Skip to content

Commit

Permalink
Fix delete on hono (#413)
Browse files Browse the repository at this point in the history
* adjustments

* fixed delete on hono

* fixed admin and hono

* release 0.26.3-exp.0
  • Loading branch information
noam-honig committed Apr 22, 2024
1 parent 5d25230 commit 41a8690
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 44 deletions.
3 changes: 2 additions & 1 deletion docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ import { remultHapi } from 'remult/remult-hapi'

```ts [Hono]
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
import { remultHono } from 'remult/remult-hono'

const app = new Hono()

const api = remultHono({}) // [!code highlight]
app.route('', api) // [!code highlight]

export default app
serve(app)
```

```ts [Nest]
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "remult-mono-repo",
"description": "See projects/core for the remult core package.json. This package.json is used for remult/core development, test projects and experimental work. See ",
"version": "0.26.2",
"version": "0.26.3-exp.0",
"scripts": {
"format": "prettier \"./projects/core/**\" --write",
"test": "vitest --ui --coverage",
Expand Down Expand Up @@ -39,7 +39,7 @@
"@fastify/middie": "^8.0.0",
"@fastify/swagger-ui": "^1.8.1",
"@hapi/hapi": "^21.3.2",
"@hono/node-server": "^1.8.2",
"@hono/node-server": "^1.11.0",
"@koa/router": "^12.0.0",
"@microsoft/fetch-event-source": "^2.0.1",
"@paralleldrive/cuid2": "^2.2.1",
Expand Down Expand Up @@ -79,7 +79,7 @@
"fastify-plugin": "^4.0.0",
"graphql": "^15.8.0",
"graphql-yoga": "^3.9.1",
"hono": "^4.0.9",
"hono": "^4.2.5",
"knex": "^2.4.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
Expand Down
3 changes: 1 addition & 2 deletions projects/core/remult-hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function remultHono(

let honoRouter: GenericRouter = {
route(path) {
if (path.endsWith('*')) path = path.substring(0, path.length - 1) + '.*'
let r = {
get(handler) {
app.get(path, honoHandler(handler))
Expand Down Expand Up @@ -78,7 +77,7 @@ export function remultHono(
},
end: () => {
if (sse) sse.close()
else res(c.text(''))
else res(c.body(null))
},
send: (data: string) => {
res(c.html(data))
Expand Down
9 changes: 6 additions & 3 deletions projects/core/server/expressBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ export class RemultServerImplementation<RequestType>
r,
)
if (this.options.admin !== undefined && this.options.admin !== false) {
r.route(this.options.rootPath + '/admin*').get(
this.process(async (remult, req, res, orig, origResponse) => {
const admin = this.process(
async (remult, req, res, orig, origResponse) => {
if (remult.isAllowed(this.options.admin))
origResponse.send(
remultAdminHtml({
Expand All @@ -415,8 +415,11 @@ export class RemultServerImplementation<RequestType>
}),
)
else res.notFound()
}),
},
)
r.route(this.options.rootPath + '/admin/:id').get(admin)
r.route(this.options.rootPath + '/admin/').get(admin)
r.route(this.options.rootPath + '/admin').get(admin)
}
if (this.options.subscriptionServer instanceof SseSubscriptionServer) {
const streamPath = this.options.rootPath + '/' + streamUrl
Expand Down
3 changes: 2 additions & 1 deletion projects/core/src/remult3/remult3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ export type ClassFieldDecorator<entityType, valueType> = (
//y1 - fix async hooks - was it fixed?
//p1 - consider upsert (where,set)
//p1 - consider id to also support keyof (id:['company','index'])
//p1 - wait a second to close stream

//p1 - reconsider update many, maybe the second parameter should be in a set option - break existing
//p1 - add documentation for bun sqlite
Expand All @@ -829,7 +830,7 @@ export type ClassFieldDecorator<entityType, valueType> = (
//p1 - maybe add decorator comment in the readme as well (I heard you've lost me in decorators) - and improve the describeClass function
//p1 - return error on connection error
//p1 - consider including the admin in the tutorial - and maybe even in the demo when we setup the api
//p1 -
//p2 -fix remult admin not to load the html into memory until used

//y2 - JY suggestion of having generate as part of the ensure schema - not sure
//y2 - currently for string fields we default for 255 in knex (which is their default) why not just use text (varchar max) - and only use exact length when one is provided?
Expand Down
1 change: 1 addition & 0 deletions projects/test-servers/deno-fresh/routes/api/_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Task } from '../../shared/task.ts'
export const api = remultFresh(
{
entities: [Task],
admin:true
},
Response,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { Task } from '../../shared/Task'

export default remultNext({
entities: [Task],
admin: true,
})
2 changes: 1 addition & 1 deletion projects/test-servers/node-servers/hapiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const init = async () => {
host: '127.0.0.1',
})

const api = remultHapi({ entities: [Task] })
const api = remultHapi({ entities: [Task], admin: true })
await server.register(api)
await server.register({
plugin: routesPlugin,
Expand Down
2 changes: 1 addition & 1 deletion projects/test-servers/node-servers/koaServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Task } from '../shared/Task'

const app = new koa()

const api = createRemultServer({ entities: [Task] })
const api = createRemultServer({ entities: [Task], admin: true })
app.use(bodyParser())
app.use(async (ctx, next) => {
const r = await api.handle(ctx.request)
Expand Down
2 changes: 1 addition & 1 deletion projects/test-servers/node-servers/middlewareCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const app = express()
app.use(express.json())

const api = createRemultServerCore<express.Request>(
{ entities: [Task] },
{ entities: [Task], admin: true },
{
buildGenericRequestInfo: (req) => req,
getRequestBody: (req) => req.body,
Expand Down
2 changes: 1 addition & 1 deletion projects/test-servers/node-servers/middlewareServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Task } from '../shared/Task'
const app = express()
app.use(express.json())

const api = createRemultServer({ entities: [Task] })
const api = createRemultServer({ entities: [Task], admin: true })
app.use(async (req, res, next) => {
;(await api.handle(req, res)) || next()
})
Expand Down
2 changes: 1 addition & 1 deletion projects/test-servers/nuxt-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 50 additions & 12 deletions projects/tests/backend-tests/all-server-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export function allServerTests(
'delete many',
withRemultForTest(async () => {
await create3Tasks()
expect(await repo(Task).deleteMany({ where: { title: ['a', 'c'] } })).toBe(2)
expect(
await repo(Task).deleteMany({ where: { title: ['a', 'c'] } }),
).toBe(2)
expect(await repo(Task).count()).toBe(1)
}),
)
Expand All @@ -94,7 +96,9 @@ export function allServerTests(
withRemultForTest(async () => {
await create3Tasks()
expect(
await repo(Task).deleteMany({ where: { $or: [{ title: 'a' }, { title: 'c' }] } }),
await repo(Task).deleteMany({
where: { $or: [{ title: 'a' }, { title: 'c' }] },
}),
).toBe(2)
expect(await repo(Task).count()).toBe(1)
}),
Expand All @@ -103,7 +107,9 @@ export function allServerTests(
'delete many 3',
withRemultForTest(async () => {
await create3Tasks()
expect(await repo(Task).deleteMany({ where: { title: { $ne: 'b' } } })).toBe(2)
expect(
await repo(Task).deleteMany({ where: { title: { $ne: 'b' } } }),
).toBe(2)
expect(await repo(Task).count()).toBe(1)
}),
)
Expand All @@ -112,7 +118,10 @@ export function allServerTests(
withRemultForTest(async () => {
await create3Tasks()
expect(
await repo(Task).updateMany({ where: { title: ['a', 'c'] } }, { title: 'dd' }),
await repo(Task).updateMany(
{ where: { title: ['a', 'c'] } },
{ title: 'dd' },
),
).toBe(2)
expect(await repo(Task).count({ title: 'dd' })).toBe(2)
expect(await repo(Task).count({ title: { '!=': 'dd' } })).toBe(1)
Expand All @@ -123,7 +132,10 @@ export function allServerTests(
withRemultForTest(async () => {
await create3Tasks()
expect(
await repo(Task).updateMany({ where: { title: { $ne: 'b' } } }, { title: 'dd' }),
await repo(Task).updateMany(
{ where: { title: { $ne: 'b' } } },
{ title: 'dd' },
),
).toBe(2)
expect(await repo(Task).count({ title: 'dd' })).toBe(2)
expect(await repo(Task).count({ title: { '!=': 'dd' } })).toBe(1)
Expand All @@ -148,20 +160,46 @@ export function allServerTests(
}),
)
it(
'delete with url params',
'admin',
withRemultForTest(async () => {
await create3Tasks()
expect((await axios.get(remult.apiClient.url + '/admin')).status).toBe(
200,
)
}),
)
it(
'admin/',
withRemultForTest(async () => {
await create3Tasks()
expect((await axios.get(remult.apiClient.url + '/admin/')).status).toBe(
200,
)
}),
)
it(
'admin/tasks',
withRemultForTest(async () => {
expect(
(await axios.delete(remult.apiClient.url + '/tasks' + '?title.ne=b'))
.data,
).toMatchInlineSnapshot(`
(await axios.get(remult.apiClient.url + '/admin/tasks')).status,
).toBe(200)
}),
),
it(
'delete with url params',
withRemultForTest(async () => {
await create3Tasks()
expect(
(await axios.delete(remult.apiClient.url + '/tasks' + '?title.ne=b'))
.data,
).toMatchInlineSnapshot(`
{
"deleted": 2,
}
`)
expect(await repo(Task).count()).toBe(1)
}),
)
expect(await repo(Task).count()).toBe(1)
}),
)
it(
'update many 2',
withRemultForTest(async () => {
Expand Down
3 changes: 2 additions & 1 deletion projects/tests/backend-tests/test-express-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type RemultExpressServer,
remultExpress,
} from '../../core/remult-express.js'
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it } from 'vitest'
import { Task, test_compound_id } from '../../test-servers/shared/Task.js'
import {
InMemoryDataProvider,
Expand All @@ -28,6 +28,7 @@ describe('test express server', async () => {
let api = remultExpress({
entities: [Task, test_compound_id],
dataProvider: new InMemoryDataProvider(),
admin: true,
error: (e) => errorHandler?.(e),
getUser: async () => {
if (throwExceptionOnGetUser)
Expand Down
1 change: 1 addition & 0 deletions projects/tests/backend-tests/test-fastify-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('test fastify server', async () => {
const app = fastify()
const api = remultFastify({
entities: [Task],
admin: true,
})
await app.register(api)
app.get('/api/test', async (req, res) => {
Expand Down
2 changes: 2 additions & 0 deletions projects/tests/backend-tests/test-hapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('test hapi server', async () => {
const app = server({ port })
const api = remultHapi({
entities: [Task],

admin: true,
})
await app.register(api)
app.route({
Expand Down
1 change: 1 addition & 0 deletions projects/tests/backend-tests/test-hono-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('test holo server', async () => {
const app = new Hono()
const api = remultHono({
entities: [Task],
admin: true,
})
app.route('', api)
app.get('/api/test', api.withRemult, async (c) =>
Expand Down

0 comments on commit 41a8690

Please sign in to comment.