create-guren-app 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/api-only/.env.example +0 -3
- package/templates/api-only/.oxlintrc.json +3 -1
- package/templates/api-only/bin/serve.ts +1 -1
- package/templates/api-only/package.json +3 -3
- package/templates/api-only/src/app.ts +7 -7
- package/templates/blog/app/Http/Controllers/PostController.ts +4 -4
- package/templates/blog/app/Providers/AuthProvider.ts +3 -4
- package/templates/blog/app/Providers/AuthorizationProvider.ts +2 -3
- package/templates/blog/resources/js/pages/posts/Index.tsx +3 -2
- package/templates/blog/routes/web.ts +4 -4
- package/templates/blog/src/app.ts +7 -7
- package/templates/blog/tests/PostController.test.ts +8 -7
- package/templates/database/mysql/config/database.ts +1 -1
- package/templates/database/mysql/drizzle.config.ts +1 -1
- package/templates/database/postgres/config/database.ts +1 -1
- package/templates/database/postgres/drizzle.config.ts +1 -1
- package/templates/database/sqlite/config/database.ts +2 -2
- package/templates/database/sqlite/drizzle.config.ts +8 -12
- package/templates/default/.env.example +0 -6
- package/templates/default/.oxlintrc.json +3 -1
- package/templates/default/bin/serve.ts +1 -1
- package/templates/default/package.json +3 -3
- package/templates/default/resources/css/guren.css +4 -0
- package/templates/default/src/app.ts +7 -7
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
3
|
// The guren rules ship with @guren/cli: await-async-assertion (a bare
|
|
4
|
-
// `expect(...).rejects` statement can never fail its test)
|
|
4
|
+
// `expect(...).rejects` statement can never fail its test), no-nullish-env-default
|
|
5
|
+
// (`process.env.FOO ?? 'x'` keeps a blank `FOO=` as ''), and the comment rules.
|
|
5
6
|
"jsPlugins": ["@guren/cli/oxlint"],
|
|
6
7
|
"ignorePatterns": ["node_modules/**", ".guren/**", "dist/**", "public/build/**"],
|
|
7
8
|
"rules": {
|
|
8
9
|
"guren/await-async-assertion": "error",
|
|
10
|
+
"guren/no-nullish-env-default": "error",
|
|
9
11
|
// Comment hygiene is advisory: the agent harness feeds these back after every
|
|
10
12
|
// edit, while `bun run lint` stays green on them.
|
|
11
13
|
"guren/comment-length": "warn",
|
|
@@ -10,7 +10,7 @@ try {
|
|
|
10
10
|
// `PORT=0` means "any free port", so this tests for a number, not truthiness.
|
|
11
11
|
const parsedPort = Number.parseInt(process.env.PORT ?? '', 10)
|
|
12
12
|
const port = Number.isInteger(parsedPort) ? parsedPort : 3333
|
|
13
|
-
const hostname = process.env.HOST
|
|
13
|
+
const hostname = process.env.HOST || '0.0.0.0'
|
|
14
14
|
|
|
15
15
|
// The walk past a busy port lives in listen() now, which is also the only
|
|
16
16
|
// place that can report which port it ended up on. Set GUREN_STRICT_PORT=1 to
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"test": "bun test"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@guren/cli": "^2.
|
|
24
|
-
"@guren/core": "^1.
|
|
25
|
-
"@guren/orm": "^2.
|
|
23
|
+
"@guren/cli": "^2.19.0",
|
|
24
|
+
"@guren/core": "^1.15.0",
|
|
25
|
+
"@guren/orm": "^2.7.0",
|
|
26
26
|
"drizzle-orm": "1.0.0-rc.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -3,13 +3,9 @@ import DatabaseProvider from '../app/Providers/DatabaseProvider.js'
|
|
|
3
3
|
import { registerApiRoutes } from '../routes/api.js'
|
|
4
4
|
|
|
5
5
|
// The Host header is client-controlled, so production should answer only to the
|
|
6
|
-
// host this app is deployed as, which APP_URL carries.
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// (the Cloudflare worker imports this module before wrangler `vars` land). A
|
|
10
|
-
// missing value therefore warns and leaves the check off, rather than throwing
|
|
11
|
-
// and stopping the app from booting at all. Emailed links do not depend on this
|
|
12
|
-
// — app/Auth/AppUrl.ts resolves those per request and fails closed there.
|
|
6
|
+
// host this app is deployed as, which APP_URL carries. Emailed links do not
|
|
7
|
+
// depend on this — app/Auth/AppUrl.ts resolves those per request and fails
|
|
8
|
+
// closed there.
|
|
13
9
|
function hostAuthorization() {
|
|
14
10
|
const exclude = ['/health']
|
|
15
11
|
|
|
@@ -18,6 +14,10 @@ function hostAuthorization() {
|
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
const appUrl = process.env.APP_URL?.trim()
|
|
17
|
+
// Read at module scope, where not every platform has populated process.env yet
|
|
18
|
+
// (the Cloudflare worker imports this module before wrangler `vars` land), so a
|
|
19
|
+
// missing value warns and leaves the check off rather than throwing and
|
|
20
|
+
// stopping the app from booting at all.
|
|
21
21
|
if (!appUrl) {
|
|
22
22
|
console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
|
|
23
23
|
return false
|
|
@@ -28,15 +28,15 @@ export default class PostController extends Controller {
|
|
|
28
28
|
// Serves the HTTP QUERY route `posts.search` — a safe read that carries its
|
|
29
29
|
// criteria in a JSON body. Matches posts with any keyword in title or
|
|
30
30
|
// excerpt; `%` and `_` in a keyword act as SQL LIKE wildcards, which this
|
|
31
|
-
// starter treats as a feature.
|
|
32
|
-
// `where(callback)`, keeping this an any-keyword match while AND filters
|
|
33
|
-
// added later (a published flag, tenancy) apply to every hit instead of
|
|
34
|
-
// being OR'd away.
|
|
31
|
+
// starter treats as a feature.
|
|
35
32
|
async search(): Promise<Response> {
|
|
36
33
|
const { keywords, limit } = await this.validateBody(PostSearchSchema)
|
|
37
34
|
|
|
38
35
|
const posts = await Post.newQuery()
|
|
39
36
|
.with('author')
|
|
37
|
+
// All keyword OR pairs sit inside one callback, keeping this an
|
|
38
|
+
// any-keyword match while AND filters added later (a published flag,
|
|
39
|
+
// tenancy) apply to every hit instead of being OR'd away.
|
|
40
40
|
.where((q) => {
|
|
41
41
|
for (const keyword of keywords) {
|
|
42
42
|
const pattern = `%${keyword}%`
|
|
@@ -13,11 +13,10 @@ export default class AuthProvider extends ServiceProvider {
|
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// Nothing shares the signed-in user with the frontend by default, so every
|
|
17
|
+
// page would render as a guest. Layout.tsx reads this to choose between
|
|
18
|
+
// "Sign in" and the Write/Dashboard/Log out controls.
|
|
16
19
|
boot(): void {
|
|
17
|
-
// Nothing shares the signed-in user with the frontend by default, so every
|
|
18
|
-
// page would render as a guest. Layout.tsx reads this to choose between
|
|
19
|
-
// "Sign in" and the Write/Dashboard/Log out controls.
|
|
20
|
-
//
|
|
21
20
|
// shareInertiaProps merges over resolvers registered earlier instead of
|
|
22
21
|
// replacing them, so the framework's flashed `errors` still come through.
|
|
23
22
|
// Passing this.container scopes the props to this app.
|
|
@@ -6,13 +6,12 @@ import { PostPolicy } from '../Policies/PostPolicy.js'
|
|
|
6
6
|
* Maps models to their policies. `PostController` calls `this.authorize()` in
|
|
7
7
|
* every mutating action, and without a registered policy the gate has nothing
|
|
8
8
|
* to consult and denies them all.
|
|
9
|
-
*
|
|
10
|
-
* The framework's own provider creates the gate during registration, so this
|
|
11
|
-
* runs in boot() — getGate() throws before that.
|
|
12
9
|
*/
|
|
13
10
|
export default class AuthorizationProvider extends ServiceProvider {
|
|
14
11
|
register(): void {}
|
|
15
12
|
|
|
13
|
+
// The framework's own provider creates the gate during registration, so this
|
|
14
|
+
// runs in boot() — getGate() throws before that.
|
|
16
15
|
boot(): void {
|
|
17
16
|
getGate().policy(Post, PostPolicy)
|
|
18
17
|
}
|
|
@@ -10,8 +10,9 @@ interface Props extends PaginatedPageProps<PostResourceData> {}
|
|
|
10
10
|
|
|
11
11
|
// posts.search is an HTTP QUERY route (RFC 10008): safe like GET, but the
|
|
12
12
|
// criteria travel in a JSON body — HTML forms and Inertia navigation cannot
|
|
13
|
-
// send it, so the page calls it through the generated typed client.
|
|
14
|
-
|
|
13
|
+
// send it, so the page calls it through the generated typed client.
|
|
14
|
+
|
|
15
|
+
// The client types the request body from the schema bound to the route, and
|
|
15
16
|
// json() from the `resource` hint the route declares — both come from the
|
|
16
17
|
// route definition, so this file never restates the wire shape.
|
|
17
18
|
const api = createApiClient<ApiRoutes>({ baseUrl: '' })
|
|
@@ -34,13 +34,13 @@ export function registerWebRoutes(baseRouter: Router): void {
|
|
|
34
34
|
|
|
35
35
|
// HTTP QUERY (RFC 10008): safe and idempotent like GET, but carries its
|
|
36
36
|
// search criteria in a JSON body. Only fetch-based clients can send it —
|
|
37
|
-
// the posts page calls it through the generated API client.
|
|
38
|
-
// `resource` hint declares the response shape the controller builds with
|
|
39
|
-
// PostResource, so the client's json() comes back typed — no runtime
|
|
40
|
-
// validation, just the type codegen already extracts from the Resource.
|
|
37
|
+
// the posts page calls it through the generated API client.
|
|
41
38
|
posts.query('/search', {
|
|
42
39
|
name: 'posts.search',
|
|
43
40
|
body: PostSearchSchema,
|
|
41
|
+
// Declares the response shape the controller builds with PostResource, so
|
|
42
|
+
// the client's json() comes back typed — no runtime validation, just the
|
|
43
|
+
// type codegen already extracts from the Resource.
|
|
44
44
|
resource: { data: [PostResource] },
|
|
45
45
|
}, [PostController, 'search'])
|
|
46
46
|
})
|
|
@@ -18,13 +18,9 @@ setInertiaDocument({
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
// The Host header is client-controlled, so production should answer only to the
|
|
21
|
-
// host this app is deployed as, which APP_URL carries.
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
// (the Cloudflare worker imports this module before wrangler `vars` land). A
|
|
25
|
-
// missing value therefore warns and leaves the check off, rather than throwing
|
|
26
|
-
// and stopping the app from booting at all. Emailed links do not depend on this
|
|
27
|
-
// — app/Auth/AppUrl.ts resolves those per request and fails closed there.
|
|
21
|
+
// host this app is deployed as, which APP_URL carries. Emailed links do not
|
|
22
|
+
// depend on this — app/Auth/AppUrl.ts resolves those per request and fails
|
|
23
|
+
// closed there.
|
|
28
24
|
function hostAuthorization() {
|
|
29
25
|
const exclude = ['/health']
|
|
30
26
|
|
|
@@ -33,6 +29,10 @@ function hostAuthorization() {
|
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
const appUrl = process.env.APP_URL?.trim()
|
|
32
|
+
// Read at module scope, where not every platform has populated process.env yet
|
|
33
|
+
// (the Cloudflare worker imports this module before wrangler `vars` land), so a
|
|
34
|
+
// missing value warns and leaves the check off rather than throwing and
|
|
35
|
+
// stopping the app from booting at all.
|
|
36
36
|
if (!appUrl) {
|
|
37
37
|
console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
|
|
38
38
|
return false
|
|
@@ -2,13 +2,14 @@ import { beforeAll, describe, it } from 'bun:test'
|
|
|
2
2
|
import { TestApp } from '@guren/testing'
|
|
3
3
|
import app from '../src/app.js'
|
|
4
4
|
|
|
5
|
-
// posts.search is an HTTP QUERY route (RFC 10008). Its controller validates
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
//
|
|
5
|
+
// posts.search is an HTTP QUERY route (RFC 10008). Its controller validates the
|
|
6
|
+
// body with validateBody() before building any query — the schema bound to the
|
|
7
|
+
// route feeds codegen and `guren audit`, while body parsing stays in the
|
|
8
|
+
// controller so the request stream is read once.
|
|
9
|
+
|
|
10
|
+
// So an invalid payload gets a 422 without the database ever being touched,
|
|
11
|
+
// which keeps this starter test green without migrations or fixtures. Cover the
|
|
12
|
+
// happy path with real feature tests once your test database is set up.
|
|
12
13
|
describe('posts.search', () => {
|
|
13
14
|
let http: TestApp
|
|
14
15
|
|
|
@@ -3,7 +3,7 @@ import { createMySqlDatabase, type MySqlSeederContext } from '@guren/orm'
|
|
|
3
3
|
const database = createMySqlDatabase({
|
|
4
4
|
migrationsFolder: new URL('../db/migrations', import.meta.url),
|
|
5
5
|
seedersFolder: new URL('../db/seeders', import.meta.url),
|
|
6
|
-
connectionString: () => process.env.DATABASE_URL
|
|
6
|
+
connectionString: () => process.env.DATABASE_URL || 'mysql://guren:guren@localhost:33306/guren',
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
export const { getDatabase, migrateDatabase, closeDatabase, configureOrm, seedDatabase, resetDatabase, migrationStatus } = database
|
|
@@ -10,6 +10,6 @@ export default defineConfig({
|
|
|
10
10
|
out: './db/migrations',
|
|
11
11
|
dialect: 'mysql',
|
|
12
12
|
dbCredentials: {
|
|
13
|
-
url: process.env.DATABASE_URL
|
|
13
|
+
url: process.env.DATABASE_URL || 'mysql://guren:guren@localhost:33306/guren',
|
|
14
14
|
},
|
|
15
15
|
})
|
|
@@ -3,7 +3,7 @@ import { createPostgresDatabase, type PostgresSeederContext } from '@guren/orm'
|
|
|
3
3
|
const database = createPostgresDatabase({
|
|
4
4
|
migrationsFolder: new URL('../db/migrations', import.meta.url),
|
|
5
5
|
seedersFolder: new URL('../db/seeders', import.meta.url),
|
|
6
|
-
connectionString: () => process.env.DATABASE_URL
|
|
6
|
+
connectionString: () => process.env.DATABASE_URL || 'postgres://guren:guren@localhost:54322/guren',
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
export const { getDatabase, migrateDatabase, closeDatabase, configureOrm, seedDatabase, resetDatabase, migrationStatus } = database
|
|
@@ -10,6 +10,6 @@ export default defineConfig({
|
|
|
10
10
|
out: './db/migrations',
|
|
11
11
|
dialect: 'postgresql',
|
|
12
12
|
dbCredentials: {
|
|
13
|
-
url: process.env.DATABASE_URL
|
|
13
|
+
url: process.env.DATABASE_URL || 'postgres://guren:guren@localhost:54322/guren',
|
|
14
14
|
},
|
|
15
15
|
})
|
|
@@ -7,9 +7,9 @@ import { createSqliteDatabase, type SqliteSeederContext } from '@guren/orm'
|
|
|
7
7
|
// shard parallel CI runs); DATABASE_URL is still authoritative outside tests.
|
|
8
8
|
function resolveDatabaseFilename(): string {
|
|
9
9
|
if (process.env.NODE_ENV === 'test') {
|
|
10
|
-
return process.env.TEST_DATABASE_URL
|
|
10
|
+
return process.env.TEST_DATABASE_URL || './data/guren.test.db'
|
|
11
11
|
}
|
|
12
|
-
return process.env.DATABASE_URL
|
|
12
|
+
return process.env.DATABASE_URL || './data/guren.db'
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const database = createSqliteDatabase({
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { defineConfig } from 'drizzle-kit'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Read by two different SQLite implementations that disagree about URI
|
|
4
|
+
// filenames: the app opens it with `bun:sqlite`, which honours them, while
|
|
5
|
+
// drizzle-kit opens it with `node:sqlite`, which does not. So `file:` is not a
|
|
6
|
+
// shared spelling of anything — `file:local.db` migrates the app into
|
|
7
|
+
// `local.db` and drizzle-kit into a file *named* `file:local.db`.
|
|
8
|
+
const filename = process.env.DATABASE_URL || './data/guren.db'
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* about URI filenames: the app opens it with `bun:sqlite`, which honours them,
|
|
8
|
-
* while drizzle-kit opens it with `node:sqlite`, which does not. So `file:` is
|
|
9
|
-
* not a shared spelling of anything — `file:local.db` migrates the app into
|
|
10
|
-
* `local.db` and drizzle-kit into a file *named* `file:local.db`. The safe set
|
|
11
|
-
* is what both agree on: plain paths, and `:memory:`.
|
|
12
|
-
*
|
|
13
|
-
* The scheme must be two characters or more, since no registered scheme is one
|
|
14
|
-
* letter while `C:/data/app.db` is a Windows drive path.
|
|
15
|
-
*/
|
|
10
|
+
// Two characters or more: no registered scheme is one letter, while
|
|
11
|
+
// `C:/data/app.db` is a Windows drive path.
|
|
16
12
|
const uriScheme = /^([a-z][a-z0-9+.-]+):/i.exec(filename)
|
|
17
13
|
|
|
18
14
|
if (uriScheme) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
3
|
// The guren rules ship with @guren/cli: await-async-assertion (a bare
|
|
4
|
-
// `expect(...).rejects` statement can never fail its test)
|
|
4
|
+
// `expect(...).rejects` statement can never fail its test), no-nullish-env-default
|
|
5
|
+
// (`process.env.FOO ?? 'x'` keeps a blank `FOO=` as ''), and the comment rules.
|
|
5
6
|
"jsPlugins": ["@guren/cli/oxlint"],
|
|
6
7
|
"ignorePatterns": ["node_modules/**", ".guren/**", "dist/**", "public/build/**"],
|
|
7
8
|
"rules": {
|
|
8
9
|
"guren/await-async-assertion": "error",
|
|
10
|
+
"guren/no-nullish-env-default": "error",
|
|
9
11
|
// Comment hygiene is advisory: the agent harness feeds these back after every
|
|
10
12
|
// edit, while `bun run lint` stays green on them.
|
|
11
13
|
"guren/comment-length": "warn",
|
|
@@ -10,7 +10,7 @@ try {
|
|
|
10
10
|
// `PORT=0` means "any free port", so this tests for a number, not truthiness.
|
|
11
11
|
const parsedPort = Number.parseInt(process.env.PORT ?? '', 10)
|
|
12
12
|
const port = Number.isInteger(parsedPort) ? parsedPort : 3333
|
|
13
|
-
const hostname = process.env.HOST
|
|
13
|
+
const hostname = process.env.HOST || '0.0.0.0'
|
|
14
14
|
|
|
15
15
|
// The walk past a busy port lives in listen() now, which is also the only
|
|
16
16
|
// place that can report which port it ended up on. Set GUREN_STRICT_PORT=1 to
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"db:seed": "bunx guren db:seed"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@guren/cli": "^2.
|
|
25
|
-
"@guren/core": "^1.
|
|
24
|
+
"@guren/cli": "^2.19.0",
|
|
25
|
+
"@guren/core": "^1.15.0",
|
|
26
26
|
"@guren/inertia-client": "^1.1.3",
|
|
27
|
-
"@guren/orm": "^2.
|
|
27
|
+
"@guren/orm": "^2.7.0",
|
|
28
28
|
"@inertiajs/react": "^3.6.1",
|
|
29
29
|
"drizzle-orm": "1.0.0-rc.4",
|
|
30
30
|
"react": "^19.0.0",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
fill moves to them only inside a confirm step. */
|
|
10
10
|
|
|
11
11
|
:root {
|
|
12
|
+
/* The dark block below follows the system preference, so the UA chrome
|
|
13
|
+
(scrollbars, native controls, Chrome's autofill wash) must too. */
|
|
14
|
+
color-scheme: light dark;
|
|
15
|
+
|
|
12
16
|
--g-font-sans: system-ui, 'Noto Sans JP', 'Hiragino Sans', sans-serif;
|
|
13
17
|
--g-font-mono: ui-monospace, 'JetBrains Mono', 'SFMono-Regular', Menlo, monospace;
|
|
14
18
|
|
|
@@ -17,13 +17,9 @@ setInertiaDocument({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
// The Host header is client-controlled, so production should answer only to the
|
|
20
|
-
// host this app is deployed as, which APP_URL carries.
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// (the Cloudflare worker imports this module before wrangler `vars` land). A
|
|
24
|
-
// missing value therefore warns and leaves the check off, rather than throwing
|
|
25
|
-
// and stopping the app from booting at all. Emailed links do not depend on this
|
|
26
|
-
// — app/Auth/AppUrl.ts resolves those per request and fails closed there.
|
|
20
|
+
// host this app is deployed as, which APP_URL carries. Emailed links do not
|
|
21
|
+
// depend on this — app/Auth/AppUrl.ts resolves those per request and fails
|
|
22
|
+
// closed there.
|
|
27
23
|
function hostAuthorization() {
|
|
28
24
|
const exclude = ['/health']
|
|
29
25
|
|
|
@@ -32,6 +28,10 @@ function hostAuthorization() {
|
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
const appUrl = process.env.APP_URL?.trim()
|
|
31
|
+
// Read at module scope, where not every platform has populated process.env yet
|
|
32
|
+
// (the Cloudflare worker imports this module before wrangler `vars` land), so a
|
|
33
|
+
// missing value warns and leaves the check off rather than throwing and
|
|
34
|
+
// stopping the app from booting at all.
|
|
35
35
|
if (!appUrl) {
|
|
36
36
|
console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
|
|
37
37
|
return false
|