vasp-cli 0.4.0 → 0.9.0

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.
Files changed (136) hide show
  1. package/dist/vasp +82 -34
  2. package/package.json +2 -2
  3. package/starters/minimal.vasp +1 -1
  4. package/starters/recipe.vasp +11 -20
  5. package/starters/todo-auth-ssr.vasp +33 -20
  6. package/starters/todo.vasp +15 -8
  7. package/templates/shared/.gitignore.hbs +1 -0
  8. package/templates/shared/auth/server/index.hbs +4 -8
  9. package/templates/shared/auth/server/middleware.hbs +33 -15
  10. package/templates/{templates/shared → shared}/auth/server/plugin.hbs +0 -2
  11. package/templates/shared/auth/server/providers/github.hbs +1 -1
  12. package/templates/shared/auth/server/providers/google.hbs +1 -1
  13. package/templates/shared/auth/server/providers/usernameAndPassword.hbs +3 -6
  14. package/templates/shared/bunfig.toml.hbs +3 -0
  15. package/templates/shared/drizzle/schema.hbs +38 -19
  16. package/templates/shared/package.json.hbs +11 -4
  17. package/templates/shared/server/db/client.hbs +19 -1
  18. package/templates/shared/server/db/seed.hbs +16 -0
  19. package/templates/shared/server/index.hbs +40 -0
  20. package/templates/shared/server/middleware/errorHandler.hbs +75 -0
  21. package/templates/shared/server/middleware/logger.hbs +74 -0
  22. package/templates/shared/server/middleware/rateLimit.hbs +2 -2
  23. package/templates/shared/server/routes/_vasp.hbs +37 -0
  24. package/templates/shared/server/routes/actions/_action.hbs +5 -1
  25. package/templates/shared/server/routes/api/_api.hbs +24 -0
  26. package/templates/shared/server/routes/crud/_crud.hbs +58 -10
  27. package/templates/shared/server/routes/queries/_query.hbs +5 -1
  28. package/templates/shared/shared/types.hbs +58 -0
  29. package/templates/shared/shared/validation.hbs +20 -0
  30. package/templates/shared/tests/actions/_action.test.js.hbs +7 -0
  31. package/templates/shared/tests/actions/_action.test.ts.hbs +7 -0
  32. package/templates/shared/tests/auth/login.test.js.hbs +7 -0
  33. package/templates/shared/tests/auth/login.test.ts.hbs +7 -0
  34. package/templates/shared/tests/crud/_entity.test.js.hbs +7 -0
  35. package/templates/shared/tests/crud/_entity.test.ts.hbs +7 -0
  36. package/templates/shared/tests/queries/_query.test.js.hbs +7 -0
  37. package/templates/shared/tests/queries/_query.test.ts.hbs +7 -0
  38. package/templates/shared/tests/setup.js.hbs +5 -0
  39. package/templates/shared/tests/setup.ts.hbs +5 -0
  40. package/templates/shared/tests/vitest.config.js.hbs +8 -0
  41. package/templates/shared/tests/vitest.config.ts.hbs +8 -0
  42. package/templates/shared/tsconfig.json.hbs +2 -1
  43. package/templates/spa/js/src/App.vue.hbs +9 -1
  44. package/templates/spa/js/src/components/VaspErrorBoundary.vue.hbs +33 -0
  45. package/templates/spa/js/src/components/VaspNotifications.vue.hbs +60 -0
  46. package/templates/spa/js/src/vasp/auth.js.hbs +31 -15
  47. package/templates/spa/js/src/vasp/client/actions.js.hbs +7 -1
  48. package/templates/spa/js/src/vasp/client/crud.js.hbs +94 -5
  49. package/templates/spa/js/src/vasp/useVaspNotifications.js.hbs +35 -0
  50. package/templates/spa/js/vite.config.js.hbs +1 -0
  51. package/templates/spa/ts/src/App.vue.hbs +9 -1
  52. package/templates/spa/ts/src/components/VaspErrorBoundary.vue.hbs +33 -0
  53. package/templates/spa/ts/src/components/VaspNotifications.vue.hbs +60 -0
  54. package/templates/spa/ts/src/vasp/auth.ts.hbs +31 -15
  55. package/templates/spa/ts/src/vasp/client/actions.ts.hbs +7 -1
  56. package/templates/spa/ts/src/vasp/client/crud.ts.hbs +96 -10
  57. package/templates/spa/ts/src/vasp/client/types.ts.hbs +14 -28
  58. package/templates/spa/ts/src/vasp/useVaspNotifications.ts.hbs +41 -0
  59. package/templates/spa/ts/vite.config.ts.hbs +1 -0
  60. package/templates/ssr/js/error.vue.hbs +23 -0
  61. package/templates/ssr/js/nuxt.config.js.hbs +1 -0
  62. package/templates/ssr/ts/error.vue.hbs +26 -0
  63. package/templates/ssr/ts/nuxt.config.ts.hbs +1 -0
  64. package/templates/starters/minimal.vasp +15 -0
  65. package/templates/starters/recipe.vasp +70 -0
  66. package/templates/starters/todo-auth-ssr.vasp +65 -0
  67. package/templates/starters/todo.vasp +42 -0
  68. package/templates/templates/shared/.env.example.hbs +0 -14
  69. package/templates/templates/shared/.gitignore.hbs +0 -8
  70. package/templates/templates/shared/auth/client/Login.vue.hbs +0 -46
  71. package/templates/templates/shared/auth/client/Register.vue.hbs +0 -42
  72. package/templates/templates/shared/auth/server/index.hbs +0 -46
  73. package/templates/templates/shared/auth/server/middleware.hbs +0 -33
  74. package/templates/templates/shared/auth/server/providers/github.hbs +0 -48
  75. package/templates/templates/shared/auth/server/providers/google.hbs +0 -53
  76. package/templates/templates/shared/auth/server/providers/usernameAndPassword.hbs +0 -66
  77. package/templates/templates/shared/bunfig.toml.hbs +0 -5
  78. package/templates/templates/shared/drizzle/drizzle.config.hbs +0 -10
  79. package/templates/templates/shared/drizzle/schema.hbs +0 -48
  80. package/templates/templates/shared/jobs/_job.hbs +0 -34
  81. package/templates/templates/shared/jobs/boss.hbs +0 -15
  82. package/templates/templates/shared/package.json.hbs +0 -38
  83. package/templates/templates/shared/server/db/client.hbs +0 -12
  84. package/templates/templates/shared/server/index.hbs +0 -73
  85. package/templates/templates/shared/server/middleware/csrf.hbs +0 -34
  86. package/templates/templates/shared/server/middleware/rateLimit.hbs +0 -44
  87. package/templates/templates/shared/server/routes/actions/_action.hbs +0 -20
  88. package/templates/templates/shared/server/routes/crud/_crud.hbs +0 -86
  89. package/templates/templates/shared/server/routes/jobs/_schedule.hbs +0 -12
  90. package/templates/templates/shared/server/routes/queries/_query.hbs +0 -20
  91. package/templates/templates/shared/server/routes/realtime/_channel.hbs +0 -78
  92. package/templates/templates/shared/server/routes/realtime/index.hbs +0 -9
  93. package/templates/templates/shared/tsconfig.json.hbs +0 -21
  94. package/templates/templates/spa/js/index.html.hbs +0 -12
  95. package/templates/templates/spa/js/src/App.vue.hbs +0 -3
  96. package/templates/templates/spa/js/src/main.js.hbs +0 -9
  97. package/templates/templates/spa/js/src/router/index.js.hbs +0 -41
  98. package/templates/templates/spa/js/src/vasp/auth.js.hbs +0 -45
  99. package/templates/templates/spa/js/src/vasp/client/actions.js.hbs +0 -15
  100. package/templates/templates/spa/js/src/vasp/client/crud.js.hbs +0 -30
  101. package/templates/templates/spa/js/src/vasp/client/index.js.hbs +0 -16
  102. package/templates/templates/spa/js/src/vasp/client/queries.js.hbs +0 -15
  103. package/templates/templates/spa/js/src/vasp/client/realtime.js.hbs +0 -51
  104. package/templates/templates/spa/js/src/vasp/plugin.js.hbs +0 -11
  105. package/templates/templates/spa/js/vite.config.js.hbs +0 -26
  106. package/templates/templates/spa/ts/index.html.hbs +0 -12
  107. package/templates/templates/spa/ts/src/App.vue.hbs +0 -3
  108. package/templates/templates/spa/ts/src/main.ts.hbs +0 -9
  109. package/templates/templates/spa/ts/src/router/index.ts.hbs +0 -41
  110. package/templates/templates/spa/ts/src/vasp/auth.ts.hbs +0 -53
  111. package/templates/templates/spa/ts/src/vasp/client/actions.ts.hbs +0 -19
  112. package/templates/templates/spa/ts/src/vasp/client/crud.ts.hbs +0 -37
  113. package/templates/templates/spa/ts/src/vasp/client/index.ts.hbs +0 -17
  114. package/templates/templates/spa/ts/src/vasp/client/queries.ts.hbs +0 -19
  115. package/templates/templates/spa/ts/src/vasp/client/realtime.ts.hbs +0 -56
  116. package/templates/templates/spa/ts/src/vasp/client/types.ts.hbs +0 -33
  117. package/templates/templates/spa/ts/src/vasp/plugin.ts.hbs +0 -12
  118. package/templates/templates/spa/ts/vite.config.ts.hbs +0 -26
  119. package/templates/templates/ssr/js/_page.vue.hbs +0 -10
  120. package/templates/templates/ssr/js/app.vue.hbs +0 -3
  121. package/templates/templates/ssr/js/composables/useAuth.js.hbs +0 -52
  122. package/templates/templates/ssr/js/composables/useVasp.js.hbs +0 -6
  123. package/templates/templates/ssr/js/middleware/auth.js.hbs +0 -8
  124. package/templates/templates/ssr/js/nuxt.config.js.hbs +0 -15
  125. package/templates/templates/ssr/js/plugins/vasp.client.js.hbs +0 -27
  126. package/templates/templates/ssr/js/plugins/vasp.server.js.hbs +0 -33
  127. package/templates/templates/ssr/ts/_page.vue.hbs +0 -10
  128. package/templates/templates/ssr/ts/app.vue.hbs +0 -3
  129. package/templates/templates/ssr/ts/composables/useAuth.ts.hbs +0 -56
  130. package/templates/templates/ssr/ts/composables/useVasp.ts.hbs +0 -10
  131. package/templates/templates/ssr/ts/middleware/auth.ts.hbs +0 -8
  132. package/templates/templates/ssr/ts/nuxt.config.ts.hbs +0 -19
  133. package/templates/templates/ssr/ts/plugins/vasp.client.ts.hbs +0 -27
  134. package/templates/templates/ssr/ts/plugins/vasp.server.ts.hbs +0 -33
  135. /package/templates/{templates/shared → shared}/.env.hbs +0 -0
  136. /package/templates/{templates/shared → shared}/README.md.hbs +0 -0
@@ -1,27 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // Runs only on the client after hydration — routes calls to the Elysia backend via ofetch
3
- import { $fetch } from 'ofetch'
4
-
5
- function getCsrfToken() {
6
- const match = document.cookie.match(/(?:^|;\s*)vasp-csrf=([^;]*)/)
7
- return match ? decodeURIComponent(match[1]) : undefined
8
- }
9
-
10
- export default defineNuxtPlugin((nuxtApp) => {
11
- const config = useRuntimeConfig()
12
- const baseURL = config.public.apiBase
13
-
14
- nuxtApp.provide('vasp', {
15
- async query(name, args) {
16
- return $fetch(`/queries/${name}`, { baseURL, method: 'GET', query: args })
17
- },
18
- async action(name, args) {
19
- return $fetch(`/actions/${name}`, {
20
- baseURL,
21
- method: 'POST',
22
- body: args,
23
- headers: { 'x-csrf-token': getCsrfToken() ?? '' },
24
- })
25
- },
26
- })
27
- })
@@ -1,33 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // Runs only on the server during SSR render — calls query/action functions directly (zero HTTP overhead)
3
- {{#each queries}}
4
- import { {{importName fn}} } from '{{fn.source}}'
5
- {{/each}}
6
- {{#each actions}}
7
- import { {{importName fn}} } from '{{fn.source}}'
8
- {{/each}}
9
-
10
- export default defineNuxtPlugin((nuxtApp) => {
11
- const queryFns = {
12
- {{#each queries}}
13
- {{camelCase name}}: {{importName fn}},
14
- {{/each}}
15
- }
16
-
17
- const actionFns = {
18
- {{#each actions}}
19
- {{camelCase name}}: {{importName fn}},
20
- {{/each}}
21
- }
22
-
23
- nuxtApp.provide('vasp', {
24
- async query(name, args) {
25
- if (!queryFns[name]) throw new Error(`[Vasp] Unknown query: ${name}`)
26
- return queryFns[name](args)
27
- },
28
- async action(name, args) {
29
- if (!actionFns[name]) throw new Error(`[Vasp] Unknown action: ${name}`)
30
- return actionFns[name](args)
31
- },
32
- })
33
- })
@@ -1,10 +0,0 @@
1
- <template>
2
- <{{componentName}} />
3
- </template>
4
-
5
- <script setup lang="ts">
6
- import {{componentName}} from '{{componentSource}}'
7
- {{#if hasAuth}}
8
- definePageMeta({ middleware: 'auth' })
9
- {{/if}}
10
- </script>
@@ -1,3 +0,0 @@
1
- <template>
2
- <NuxtPage />
3
- </template>
@@ -1,56 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // SSR-aware auth composable — uses cookies (httpOnly) and Nuxt's useRequestHeaders for server-side access
3
- import { $fetch } from 'ofetch'
4
-
5
- interface AuthUser {
6
- id: number
7
- username: string
8
- email?: string
9
- }
10
-
11
- const _user = ref<AuthUser | null>(null)
12
- let _checked = false
13
-
14
- export function useAuth() {
15
- const config = useRuntimeConfig()
16
- const baseURL = config.public.apiBase as string
17
- const headers = import.meta.server ? useRequestHeaders(['cookie']) : {}
18
-
19
- async function checkAuth(): Promise<void> {
20
- if (_checked) return
21
- _checked = true
22
- try {
23
- _user.value = await $fetch<AuthUser>(`${baseURL}/auth/me`, { headers, credentials: 'include' })
24
- } catch {
25
- _user.value = null
26
- }
27
- }
28
-
29
- async function login(username: string, password: string): Promise<AuthUser> {
30
- _user.value = await $fetch<AuthUser>(`${baseURL}/auth/login`, {
31
- method: 'POST',
32
- body: { username, password },
33
- credentials: 'include',
34
- })
35
- _checked = true
36
- return _user.value!
37
- }
38
-
39
- async function register(username: string, password: string, email?: string): Promise<AuthUser> {
40
- _user.value = await $fetch<AuthUser>(`${baseURL}/auth/register`, {
41
- method: 'POST',
42
- body: { username, password, email },
43
- credentials: 'include',
44
- })
45
- _checked = true
46
- return _user.value!
47
- }
48
-
49
- async function logout(): Promise<void> {
50
- await $fetch(`${baseURL}/auth/logout`, { method: 'POST', credentials: 'include' })
51
- _user.value = null
52
- _checked = false
53
- }
54
-
55
- return { user: _user, checkAuth, login, register, logout }
56
- }
@@ -1,10 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- interface VaspClient {
3
- query<T = unknown>(name: string, args?: unknown): Promise<T>
4
- action<T = unknown>(name: string, args?: unknown): Promise<T>
5
- }
6
-
7
- export const useVasp = (): { $vasp: VaspClient } => {
8
- const { $vasp } = useNuxtApp()
9
- return { $vasp: $vasp as VaspClient }
10
- }
@@ -1,8 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- export default defineNuxtRouteMiddleware((to) => {
3
- const { user } = useAuth()
4
- const publicPaths = ['/login', '/register']
5
- if (!user.value && !publicPaths.includes(to.path)) {
6
- return navigateTo('/login')
7
- }
8
- })
@@ -1,19 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // https://nuxt.com/docs/api/configuration/nuxt-config
3
- export default defineNuxtConfig({
4
- compatibilityDate: '2024-11-01',
5
- devtools: { enabled: true },
6
- typescript: {
7
- strict: true,
8
- typeCheck: true,
9
- },
10
- alias: {
11
- '@src': '~/src',
12
- },
13
- runtimeConfig: {
14
- backendUrl: process.env.BACKEND_URL || 'http://localhost:{{backendPort}}',
15
- public: {
16
- apiBase: process.env.API_BASE || 'http://localhost:{{backendPort}}/api',
17
- },
18
- },
19
- })
@@ -1,27 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // Runs only on the client after hydration — routes calls to the Elysia backend via ofetch
3
- import { $fetch } from 'ofetch'
4
-
5
- function getCsrfToken(): string | undefined {
6
- const match = document.cookie.match(/(?:^|;\s*)vasp-csrf=([^;]*)/)
7
- return match ? decodeURIComponent(match[1]) : undefined
8
- }
9
-
10
- export default defineNuxtPlugin((nuxtApp) => {
11
- const config = useRuntimeConfig()
12
- const baseURL = config.public.apiBase as string
13
-
14
- nuxtApp.provide('vasp', {
15
- async query<T = unknown>(name: string, args?: unknown): Promise<T> {
16
- return $fetch<T>(`/queries/${name}`, { baseURL, method: 'GET', query: args as Record<string, unknown> })
17
- },
18
- async action<T = unknown>(name: string, args?: unknown): Promise<T> {
19
- return $fetch<T>(`/actions/${name}`, {
20
- baseURL,
21
- method: 'POST',
22
- body: args,
23
- headers: { 'x-csrf-token': getCsrfToken() ?? '' },
24
- })
25
- },
26
- })
27
- })
@@ -1,33 +0,0 @@
1
- // Auto-generated by Vasp — do not edit directly
2
- // Runs only on the server during SSR render — calls query/action functions directly (zero HTTP overhead)
3
- {{#each queries}}
4
- import { {{importName fn}} } from '{{fn.source}}'
5
- {{/each}}
6
- {{#each actions}}
7
- import { {{importName fn}} } from '{{fn.source}}'
8
- {{/each}}
9
-
10
- export default defineNuxtPlugin((nuxtApp) => {
11
- const queryFns: Record<string, (args?: unknown) => Promise<unknown>> = {
12
- {{#each queries}}
13
- {{camelCase name}}: {{importName fn}} as (args?: unknown) => Promise<unknown>,
14
- {{/each}}
15
- }
16
-
17
- const actionFns: Record<string, (args?: unknown) => Promise<unknown>> = {
18
- {{#each actions}}
19
- {{camelCase name}}: {{importName fn}} as (args?: unknown) => Promise<unknown>,
20
- {{/each}}
21
- }
22
-
23
- nuxtApp.provide('vasp', {
24
- async query<T = unknown>(name: string, args?: unknown): Promise<T> {
25
- if (!queryFns[name]) throw new Error(`[Vasp] Unknown query: ${name}`)
26
- return queryFns[name](args) as Promise<T>
27
- },
28
- async action<T = unknown>(name: string, args?: unknown): Promise<T> {
29
- if (!actionFns[name]) throw new Error(`[Vasp] Unknown action: ${name}`)
30
- return actionFns[name](args) as Promise<T>
31
- },
32
- })
33
- })
File without changes