create-cedar-app 3.1.2-next.0 → 3.1.2-next.126
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/database-overlays/neon-postgres/.env +20 -0
- package/database-overlays/neon-postgres/api/db/schema.prisma +26 -0
- package/database-overlays/neon-postgres/api/package.json +12 -0
- package/database-overlays/neon-postgres/api/prisma.config.cjs +12 -0
- package/database-overlays/neon-postgres/api/src/lib/db.ts +32 -0
- package/database-overlays/pglite/.env.defaults +18 -0
- package/database-overlays/pglite/api/db/schema.prisma +26 -0
- package/database-overlays/pglite/api/package.json +14 -0
- package/database-overlays/pglite/api/prisma.config.mts +82 -0
- package/database-overlays/pglite/api/src/lib/db.ts +50 -0
- package/dist/create-cedar-app.js +411 -449
- package/package.json +6 -6
- package/templates/esm-js/{.redwood → .cedar}/README.md +4 -4
- package/templates/esm-js/.env.defaults +2 -2
- package/templates/esm-js/.env.example +1 -1
- package/templates/esm-js/.vscode/launch.json +3 -3
- package/templates/esm-js/README.md +2 -2
- package/templates/esm-js/api/jsconfig.json +4 -4
- package/templates/esm-js/api/package.json +3 -3
- package/templates/esm-js/gitignore.template +3 -2
- package/templates/esm-js/package.json +5 -5
- package/templates/esm-js/scripts/jsconfig.json +6 -6
- package/templates/esm-js/scripts/seed.js +3 -3
- package/templates/esm-js/web/jsconfig.json +6 -6
- package/templates/esm-js/web/package.json +4 -4
- package/templates/{js/.redwood → esm-ts/.cedar}/README.md +4 -4
- package/templates/esm-ts/.env.defaults +2 -2
- package/templates/esm-ts/.env.example +1 -1
- package/templates/esm-ts/.vscode/launch.json +3 -3
- package/templates/esm-ts/README.md +2 -2
- package/templates/esm-ts/api/package.json +3 -3
- package/templates/esm-ts/api/tsconfig.json +4 -4
- package/templates/esm-ts/gitignore.template +3 -2
- package/templates/esm-ts/package.json +5 -5
- package/templates/esm-ts/scripts/seed.ts +3 -3
- package/templates/esm-ts/scripts/tsconfig.json +6 -6
- package/templates/esm-ts/web/package.json +4 -4
- package/templates/esm-ts/web/tsconfig.json +6 -6
- package/templates/{esm-ts/.redwood → js/.cedar}/README.md +4 -4
- package/templates/js/.env.defaults +2 -2
- package/templates/js/.env.example +1 -1
- package/templates/js/.vscode/launch.json +3 -3
- package/templates/js/README.md +2 -2
- package/templates/js/api/jsconfig.json +4 -4
- package/templates/js/api/package.json +4 -3
- package/templates/js/gitignore.template +3 -2
- package/templates/js/package.json +5 -4
- package/templates/js/scripts/jsconfig.json +6 -6
- package/templates/js/scripts/seed.js +3 -3
- package/templates/js/web/jsconfig.json +6 -6
- package/templates/js/web/package.json +5 -4
- package/templates/overlays/cjs/npm/package.json +20 -0
- package/templates/overlays/cjs/pnpm/package.json +19 -0
- package/templates/overlays/cjs/pnpm/pnpm-workspace.yaml +3 -0
- package/templates/overlays/cjs/yarn/package.json +21 -0
- package/templates/overlays/esm/npm/package.json +20 -0
- package/templates/overlays/esm/pnpm/package.json +19 -0
- package/templates/overlays/esm/pnpm/pnpm-workspace.yaml +3 -0
- package/templates/overlays/esm/yarn/package.json +21 -0
- package/templates/ts/{.redwood → .cedar}/README.md +4 -4
- package/templates/ts/.env.defaults +2 -2
- package/templates/ts/.env.example +1 -1
- package/templates/ts/.vscode/launch.json +3 -3
- package/templates/ts/README.md +2 -2
- package/templates/ts/api/package.json +4 -3
- package/templates/ts/api/tsconfig.json +4 -4
- package/templates/ts/gitignore.template +3 -2
- package/templates/ts/package.json +5 -4
- package/templates/ts/scripts/seed.ts +3 -3
- package/templates/ts/scripts/tsconfig.json +6 -6
- package/templates/ts/web/package.json +5 -4
- package/templates/ts/web/tsconfig.json +6 -6
- package/templates/js/.yarnrc.yml +0 -15
- package/templates/ts/.yarnrc.yml +0 -15
- /package/templates/{esm-js → overlays/cjs/yarn}/.yarnrc.yml +0 -0
- /package/templates/{esm-ts → overlays/esm/yarn}/.yarnrc.yml +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# THIS FILE SHOULD NOT BE CHECKED INTO YOUR VERSION CONTROL SYSTEM
|
|
2
|
+
#
|
|
3
|
+
# Environment variables set here will override those in .env.defaults.
|
|
4
|
+
# Any environment variables you need in production you will need to setup with
|
|
5
|
+
# your hosting provider. For example in Netlify you can add environment
|
|
6
|
+
# variables in Settings > Build & Deploy > environment
|
|
7
|
+
|
|
8
|
+
DATABASE_URL={{DATABASE_URL}}
|
|
9
|
+
DIRECT_DATABASE_URL={{DIRECT_DATABASE_URL}}
|
|
10
|
+
# Claimable DB expires at: {{NEON_CLAIM_EXPIRY}}
|
|
11
|
+
# Claim it now to your account using the link below:
|
|
12
|
+
# {{NEON_CLAIM_URL}}
|
|
13
|
+
#
|
|
14
|
+
# TEST_DATABASE_URL=postgres://user:pass@postgreshost.com:5432/test_database_name
|
|
15
|
+
|
|
16
|
+
# Sets an app-specific secret used to sign and verify your own app's webhooks.
|
|
17
|
+
# For example if you schedule a cron job with a signed payload that later will
|
|
18
|
+
# then invoke your api-side webhook function you will use this secret to sign and the verify.
|
|
19
|
+
# Important: Please change this default to a strong password or other secret
|
|
20
|
+
# WEBHOOK_SECRET=THIS_IS_NOT_SECRET_PLEASE_CHANGE
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Don't forget to tell Prisma about your edits to this file using
|
|
2
|
+
// `yarn cedar prisma migrate dev` or `yarn cedar prisma db push`.
|
|
3
|
+
// `migrate` is like committing while `push` is for prototyping.
|
|
4
|
+
// Read more about both here:
|
|
5
|
+
// https://www.prisma.io/docs/orm/prisma-migrate
|
|
6
|
+
|
|
7
|
+
datasource db {
|
|
8
|
+
provider = "postgresql"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
generator client {
|
|
12
|
+
provider = "prisma-client"
|
|
13
|
+
output = "./generated/prisma"
|
|
14
|
+
moduleFormat = "cjs"
|
|
15
|
+
generatedFileExtension = "mts"
|
|
16
|
+
importFileExtension = "mts"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Define your own datamodels here and run `yarn cedar prisma migrate dev`
|
|
20
|
+
// to create migrations for them and apply to your dev DB.
|
|
21
|
+
// TODO: Please remove the following example:
|
|
22
|
+
model UserExample {
|
|
23
|
+
id Int @id @default(autoincrement())
|
|
24
|
+
email String @unique
|
|
25
|
+
name String?
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@cedarjs/api": "3.1.2-next.126",
|
|
8
|
+
"@cedarjs/graphql-server": "3.1.2-next.126",
|
|
9
|
+
"@prisma/adapter-pg": "{{PRISMA_VERSION}}",
|
|
10
|
+
"pg": "^8.13.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { defineConfig, env } = require('prisma/config')
|
|
2
|
+
|
|
3
|
+
module.exports = defineConfig({
|
|
4
|
+
schema: 'db/schema.prisma',
|
|
5
|
+
migrations: {
|
|
6
|
+
path: 'db/migrations',
|
|
7
|
+
seed: 'yarn cedar exec seed',
|
|
8
|
+
},
|
|
9
|
+
datasource: {
|
|
10
|
+
url: env('DIRECT_DATABASE_URL'),
|
|
11
|
+
},
|
|
12
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
2
|
+
import { PrismaClient } from 'api/db/generated/prisma/client.mts'
|
|
3
|
+
|
|
4
|
+
import { emitLogLevels, handlePrismaLogging } from '@cedarjs/api/logger'
|
|
5
|
+
|
|
6
|
+
import { logger } from './logger.js'
|
|
7
|
+
|
|
8
|
+
export * from 'api/db/generated/prisma/client.mts'
|
|
9
|
+
|
|
10
|
+
if (!process.env.DATABASE_URL) {
|
|
11
|
+
throw new Error('DATABASE_URL environment variable is not set')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
|
|
15
|
+
const prismaClient = new PrismaClient({
|
|
16
|
+
log: emitLogLevels(['info', 'warn', 'error']),
|
|
17
|
+
adapter,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
handlePrismaLogging({
|
|
21
|
+
db: prismaClient,
|
|
22
|
+
logger,
|
|
23
|
+
logLevels: ['info', 'warn', 'error'],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Global Prisma client extensions should be added here, as $extend
|
|
28
|
+
* returns a new instance.
|
|
29
|
+
* export const db = prismaClient.$extend(...)
|
|
30
|
+
* Add any .$on hooks before using $extend
|
|
31
|
+
*/
|
|
32
|
+
export const db = prismaClient
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# These environment variables will be used by default if you do not create any
|
|
2
|
+
# yourself in .env. This file should be safe to check into your version control
|
|
3
|
+
# system. Any custom values should go in .env and .env should *not* be checked
|
|
4
|
+
# into version control.
|
|
5
|
+
|
|
6
|
+
# schema.prisma defaults
|
|
7
|
+
# Use `PGSSLMODE=disable psql -h localhost -p 5433 -U postgres -d cedar` to
|
|
8
|
+
# connect on the command line
|
|
9
|
+
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/cedar
|
|
10
|
+
|
|
11
|
+
# disables Prisma CLI update notifier
|
|
12
|
+
PRISMA_HIDE_UPDATE_MESSAGE=true
|
|
13
|
+
|
|
14
|
+
# Option to override the current environment's default api-side log level
|
|
15
|
+
# See: https://cedarjs.com/docs/logger for level options, defaults to "trace" otherwise.
|
|
16
|
+
# Most applications want "debug" or "info" during dev, "trace" when you have issues and "warn" in production.
|
|
17
|
+
# Ordered by how verbose they are: trace | debug | info | warn | error | silent
|
|
18
|
+
# LOG_LEVEL=debug
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Don't forget to tell Prisma about your edits to this file using
|
|
2
|
+
// `yarn cedar prisma migrate dev` or `yarn cedar prisma db push`.
|
|
3
|
+
// `migrate` is like committing while `push` is for prototyping.
|
|
4
|
+
// Read more about both here:
|
|
5
|
+
// https://www.prisma.io/docs/orm/prisma-migrate
|
|
6
|
+
|
|
7
|
+
datasource db {
|
|
8
|
+
provider = "postgresql"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
generator client {
|
|
12
|
+
provider = "prisma-client"
|
|
13
|
+
output = "./generated/prisma"
|
|
14
|
+
moduleFormat = "cjs"
|
|
15
|
+
generatedFileExtension = "mts"
|
|
16
|
+
importFileExtension = "mts"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Define your own datamodels here and run `yarn cedar prisma migrate dev`
|
|
20
|
+
// to create migrations for them and apply to your dev DB.
|
|
21
|
+
// TODO: Please remove the following example:
|
|
22
|
+
model UserExample {
|
|
23
|
+
id Int @id @default(autoincrement())
|
|
24
|
+
email String @unique
|
|
25
|
+
name String?
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@cedarjs/api": "3.1.2-next.126",
|
|
8
|
+
"@cedarjs/graphql-server": "3.1.2-next.126",
|
|
9
|
+
"@electric-sql/pglite": "^0.4.2",
|
|
10
|
+
"@electric-sql/pglite-socket": "^0.1.2",
|
|
11
|
+
"@prisma/adapter-pg": "{{PRISMA_VERSION}}",
|
|
12
|
+
"pg": "^8.13.0"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { PGlite } from '@electric-sql/pglite'
|
|
5
|
+
import { PGLiteSocketServer } from '@electric-sql/pglite-socket'
|
|
6
|
+
import { defineConfig, env } from 'prisma/config'
|
|
7
|
+
|
|
8
|
+
let pglite: PGlite | null = null
|
|
9
|
+
let pgliteServer: PGLiteSocketServer | null = null
|
|
10
|
+
|
|
11
|
+
async function isPortInUse(port: number, host: string): Promise<boolean> {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const server = net.createServer()
|
|
14
|
+
|
|
15
|
+
server.once('error', (err: NodeJS.ErrnoException) => {
|
|
16
|
+
if (err.code === 'EADDRINUSE') {
|
|
17
|
+
resolve(true)
|
|
18
|
+
} else {
|
|
19
|
+
// Don't block on unexpected errors
|
|
20
|
+
resolve(false)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
server.once('listening', () => {
|
|
25
|
+
server.close(() => resolve(false))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
server.listen(port, host)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function startPglite(databaseUrl: string | undefined) {
|
|
33
|
+
if (pglite || pgliteServer) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!databaseUrl) {
|
|
38
|
+
console.error('DATABASE_URL environment variable is not set')
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const url = new URL(databaseUrl)
|
|
44
|
+
const port = parseInt(url.port, 10)
|
|
45
|
+
|
|
46
|
+
if (await isPortInUse(port, url.hostname)) {
|
|
47
|
+
// Port is in use, skip PGlite server start as it's most likely already
|
|
48
|
+
// running
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pgDataDir = path.join(import.meta.dirname, 'db', 'pglite-data')
|
|
53
|
+
|
|
54
|
+
pglite = await PGlite.create(pgDataDir)
|
|
55
|
+
pgliteServer = new PGLiteSocketServer({
|
|
56
|
+
db: pglite,
|
|
57
|
+
port,
|
|
58
|
+
host: url.hostname,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
await pgliteServer.start()
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error('Failed to start PGlite server:', error)
|
|
64
|
+
pglite = null
|
|
65
|
+
pgliteServer = null
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const config = defineConfig({
|
|
70
|
+
schema: 'db/schema.prisma',
|
|
71
|
+
migrations: {
|
|
72
|
+
path: 'db/migrations',
|
|
73
|
+
seed: 'yarn cedar exec seed',
|
|
74
|
+
},
|
|
75
|
+
datasource: {
|
|
76
|
+
url: env('DATABASE_URL'),
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
await startPglite(config.datasource?.url)
|
|
81
|
+
|
|
82
|
+
export default config
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { PGlite } from '@electric-sql/pglite'
|
|
4
|
+
import { PGLiteSocketServer } from '@electric-sql/pglite-socket'
|
|
5
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
6
|
+
import { PrismaClient } from 'api/db/generated/prisma/client.mts'
|
|
7
|
+
|
|
8
|
+
import { emitLogLevels, handlePrismaLogging } from '@cedarjs/api/logger'
|
|
9
|
+
import { getPaths } from '@cedarjs/project-config'
|
|
10
|
+
|
|
11
|
+
import { logger } from './logger.js'
|
|
12
|
+
|
|
13
|
+
export * from 'api/db/generated/prisma/client.mts'
|
|
14
|
+
|
|
15
|
+
if (!process.env.DATABASE_URL) {
|
|
16
|
+
throw new Error('DATABASE_URL environment variable is not set')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const connectionString = process.env.DATABASE_URL
|
|
20
|
+
const url = new URL(connectionString)
|
|
21
|
+
const pgDataDir = path.join(getPaths().api.base, 'db', 'pglite-data')
|
|
22
|
+
|
|
23
|
+
const pglite = await PGlite.create(pgDataDir)
|
|
24
|
+
const pgliteServer = new PGLiteSocketServer({
|
|
25
|
+
db: pglite,
|
|
26
|
+
port: parseInt(url.port, 10),
|
|
27
|
+
host: url.hostname,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
await pgliteServer.start()
|
|
31
|
+
|
|
32
|
+
const adapter = new PrismaPg({ connectionString })
|
|
33
|
+
const prismaClient = new PrismaClient({
|
|
34
|
+
log: emitLogLevels(['info', 'warn', 'error']),
|
|
35
|
+
adapter,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
handlePrismaLogging({
|
|
39
|
+
db: prismaClient,
|
|
40
|
+
logger,
|
|
41
|
+
logLevels: ['info', 'warn', 'error'],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Global Prisma client extensions should be added here, as $extend
|
|
46
|
+
* returns a new instance.
|
|
47
|
+
* export const db = prismaClient.$extend(...)
|
|
48
|
+
* Add any .$on hooks before using $extend
|
|
49
|
+
*/
|
|
50
|
+
export const db = prismaClient
|