@batijs/cli 0.0.254 → 0.0.257
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/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/d1/files/$README.md.js +31 -0
- package/dist/boilerplates/@batijs/d1/files/$tsconfig.json.js +10 -0
- package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +21 -0
- package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
- package/dist/boilerplates/@batijs/drizzle/files/$.env.js +9 -0
- package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +4 -4
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +33 -14
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +16 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +27 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +11 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/{schema → drizzle/schema}/todos.ts +1 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/{seed.ts → drizzle/seed.ts} +3 -3
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -3
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -0
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +12 -0
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +43 -0
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +1 -1
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +2 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +1 -1
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +1 -1
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +1 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +1 -18
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +5 -5
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +39 -26
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +7 -0
- package/dist/boilerplates/@batijs/mantine/files/$README.md.js +23 -0
- package/dist/boilerplates/@batijs/mantine/files/$package.json.js +122 -0
- package/dist/boilerplates/@batijs/mantine/files/components/Link.tsx +10 -0
- package/dist/boilerplates/@batijs/mantine/files/layouts/LayoutDefault.tsx +37 -0
- package/dist/boilerplates/@batijs/mantine/files/layouts/style.css +0 -0
- package/dist/boilerplates/@batijs/mantine/files/layouts/theme.ts +9 -0
- package/dist/boilerplates/@batijs/mantine/files/postcss.config.cjs +14 -0
- package/dist/boilerplates/@batijs/mantine/types/components/Link.d.ts +4 -0
- package/dist/boilerplates/@batijs/mantine/types/layouts/LayoutDefault.d.ts +5 -0
- package/dist/boilerplates/@batijs/mantine/types/layouts/theme.d.ts +3 -0
- package/dist/boilerplates/@batijs/mantine/types/postcss.config.d.cts +12 -0
- package/dist/boilerplates/@batijs/react/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/react/files/layouts/HeadDefault.tsx +5 -0
- package/dist/boilerplates/@batijs/react/files/pages/todo/TodoList.tsx +1 -7
- package/dist/boilerplates/@batijs/shared/files/vite.config.ts +1 -1
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +6 -3
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +7 -3
- package/dist/boilerplates/@batijs/solid/files/pages/todo/TodoList.tsx +1 -7
- package/dist/boilerplates/@batijs/sqlite/files/$.env.js +9 -0
- package/dist/boilerplates/@batijs/sqlite/files/$README.md.js +18 -0
- package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +120 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/db.ts +15 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +25 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +9 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/all.ts +3 -0
- package/dist/boilerplates/@batijs/{lucia-auth/files/database/sqliteDb.ts → sqlite/files/database/sqlite/schema/lucia-auth.ts} +6 -5
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/todos.ts +14 -0
- package/dist/boilerplates/@batijs/{lucia-auth/types/database/sqliteDb.d.ts → sqlite/types/database/sqlite/db.d.ts} +1 -1
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +5 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/all.d.ts +2 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/lucia-auth.d.ts +1 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/todos.d.ts +1 -0
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +5 -3
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +5 -3
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +5 -3
- package/dist/boilerplates/@batijs/vue/files/pages/todo/TodoList.vue +1 -1
- package/dist/boilerplates/boilerplates.json +44 -0
- package/dist/index.js +9 -3
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzleDb.ts +0 -5
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzleDb.d.ts +0 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/database/auth-actions.ts +0 -54
- package/dist/boilerplates/@batijs/lucia-auth/types/database/auth-actions.d.ts +0 -9
- /package/dist/boilerplates/@batijs/{lucia-auth/files/database/schema/auth.ts → drizzle/files/database/drizzle/schema/lucia-auth.ts} +0 -0
- /package/dist/boilerplates/@batijs/{lucia-auth/types/database/schema/auth.d.ts → drizzle/types/database/drizzle/schema/lucia-auth.d.ts} +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{schema → drizzle/schema}/todos.d.ts +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{seed.d.ts → drizzle/seed.d.ts} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// package.json
|
|
28
|
+
var require_package = __commonJS({
|
|
29
|
+
"package.json"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
name: "@batijs/mantine",
|
|
32
|
+
private: true,
|
|
33
|
+
version: "0.0.1",
|
|
34
|
+
description: "",
|
|
35
|
+
type: "module",
|
|
36
|
+
scripts: {
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
build: "bati-compile-boilerplate"
|
|
39
|
+
},
|
|
40
|
+
keywords: [],
|
|
41
|
+
author: "",
|
|
42
|
+
license: "MIT",
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@batijs/react": "workspace:*",
|
|
46
|
+
"@mantine/core": "^7.12.1",
|
|
47
|
+
"@mantine/hooks": "^7.12.1",
|
|
48
|
+
"@types/node": "^18.19.14",
|
|
49
|
+
"@types/react": "^18.3.4",
|
|
50
|
+
"@types/react-dom": "^18.3.0",
|
|
51
|
+
postcss: "^8.4.41",
|
|
52
|
+
"postcss-preset-mantine": "^1.17.0",
|
|
53
|
+
"postcss-simple-vars": "^7.0.1",
|
|
54
|
+
react: "^18.3.1",
|
|
55
|
+
"react-dom": "^18.3.1",
|
|
56
|
+
"vike-react": "^0.5.3",
|
|
57
|
+
vite: "^5.4.2",
|
|
58
|
+
"vite-plugin-compiled-react": "^1.1.3"
|
|
59
|
+
},
|
|
60
|
+
dependencies: {
|
|
61
|
+
"@batijs/core": "workspace:*"
|
|
62
|
+
},
|
|
63
|
+
files: [
|
|
64
|
+
"dist/"
|
|
65
|
+
],
|
|
66
|
+
bati: {
|
|
67
|
+
enforce: "post",
|
|
68
|
+
if: {
|
|
69
|
+
flag: {
|
|
70
|
+
$all: [
|
|
71
|
+
"mantine",
|
|
72
|
+
"react"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
exports: {
|
|
78
|
+
"./postcss.config.": {
|
|
79
|
+
types: "./dist/types/postcss.config.d.cts"
|
|
80
|
+
},
|
|
81
|
+
"./components/Link": {
|
|
82
|
+
types: "./dist/types/components/Link.d.ts"
|
|
83
|
+
},
|
|
84
|
+
"./layouts/theme": {
|
|
85
|
+
types: "./dist/types/layouts/theme.d.ts"
|
|
86
|
+
},
|
|
87
|
+
"./layouts/LayoutDefault": {
|
|
88
|
+
types: "./dist/types/layouts/LayoutDefault.d.ts"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
typesVersions: {
|
|
92
|
+
"*": {
|
|
93
|
+
"postcss.config.": [
|
|
94
|
+
"./dist/types/postcss.config.d.cts"
|
|
95
|
+
],
|
|
96
|
+
"components/Link": [
|
|
97
|
+
"./dist/types/components/Link.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"layouts/theme": [
|
|
100
|
+
"./dist/types/layouts/theme.d.ts"
|
|
101
|
+
],
|
|
102
|
+
"layouts/LayoutDefault": [
|
|
103
|
+
"./dist/types/layouts/LayoutDefault.d.ts"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// files/$package.json.ts
|
|
112
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
113
|
+
async function getPackageJson(props) {
|
|
114
|
+
const packageJson = await loadAsJson(props);
|
|
115
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
116
|
+
devDependencies: ["postcss", "postcss-preset-mantine", "postcss-simple-vars"],
|
|
117
|
+
dependencies: ["@mantine/core", "@mantine/hooks"]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
getPackageJson as default
|
|
122
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { usePageContext } from "vike-react/usePageContext";
|
|
3
|
+
import { NavLink } from "@mantine/core";
|
|
4
|
+
|
|
5
|
+
export function Link({ href, label }: { href: string; label: string }) {
|
|
6
|
+
const pageContext = usePageContext();
|
|
7
|
+
const { urlPathname } = pageContext;
|
|
8
|
+
const isActive = href === "/" ? urlPathname === href : urlPathname.startsWith(href);
|
|
9
|
+
return <NavLink href={href} label={label} active={isActive} />;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "@mantine/core/styles.css";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { AppShell, Burger, Group, Image, MantineProvider } from "@mantine/core";
|
|
4
|
+
import { useDisclosure } from "@mantine/hooks";
|
|
5
|
+
import theme from "./theme.js";
|
|
6
|
+
|
|
7
|
+
import logoUrl from "@batijs/react/assets/logo.svg";
|
|
8
|
+
import { Link } from "../components/Link";
|
|
9
|
+
|
|
10
|
+
export default function LayoutDefault({ children }: { children: React.ReactNode }) {
|
|
11
|
+
const [opened, { toggle }] = useDisclosure();
|
|
12
|
+
return (
|
|
13
|
+
<MantineProvider theme={theme}>
|
|
14
|
+
<AppShell
|
|
15
|
+
header={{ height: 60 }}
|
|
16
|
+
navbar={{ width: 300, breakpoint: "sm", collapsed: { mobile: !opened } }}
|
|
17
|
+
padding="md"
|
|
18
|
+
>
|
|
19
|
+
<AppShell.Header>
|
|
20
|
+
<Group h="100%" px="md">
|
|
21
|
+
<Burger opened={opened} onClick={toggle} hiddenFrom="sm" size="sm" />
|
|
22
|
+
<a href="/">
|
|
23
|
+
{" "}
|
|
24
|
+
<Image h={50} fit="contain" src={logoUrl} />{" "}
|
|
25
|
+
</a>
|
|
26
|
+
</Group>
|
|
27
|
+
</AppShell.Header>
|
|
28
|
+
<AppShell.Navbar p="md">
|
|
29
|
+
<Link href="/" label="Welcome" />
|
|
30
|
+
<Link href="/todo" label="Todo" />
|
|
31
|
+
<Link href="/star-wars" label="Data Fetching" />
|
|
32
|
+
</AppShell.Navbar>
|
|
33
|
+
<AppShell.Main> {children} </AppShell.Main>
|
|
34
|
+
</AppShell>
|
|
35
|
+
</MantineProvider>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: {
|
|
3
|
+
'postcss-preset-mantine': {},
|
|
4
|
+
'postcss-simple-vars': {
|
|
5
|
+
variables: {
|
|
6
|
+
'mantine-breakpoint-xs': '36em',
|
|
7
|
+
'mantine-breakpoint-sm': '48em',
|
|
8
|
+
'mantine-breakpoint-md': '62em',
|
|
9
|
+
'mantine-breakpoint-lg': '75em',
|
|
10
|
+
'mantine-breakpoint-xl': '88em',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export let plugins: {
|
|
2
|
+
'postcss-preset-mantine': {};
|
|
3
|
+
'postcss-simple-vars': {
|
|
4
|
+
variables: {
|
|
5
|
+
'mantine-breakpoint-xs': string;
|
|
6
|
+
'mantine-breakpoint-sm': string;
|
|
7
|
+
'mantine-breakpoint-md': string;
|
|
8
|
+
'mantine-breakpoint-lg': string;
|
|
9
|
+
'mantine-breakpoint-xl': string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -50,6 +50,7 @@ var require_package = __commonJS({
|
|
|
50
50
|
"@batijs/telefunc": "workspace:^",
|
|
51
51
|
"@batijs/trpc": "workspace:^",
|
|
52
52
|
"@batijs/ts-rest": "workspace:*",
|
|
53
|
+
"@mantine/core": "^7.12.1",
|
|
53
54
|
"@types/node": "^18.19.14",
|
|
54
55
|
"@types/react": "^18.3.4",
|
|
55
56
|
"@types/react-dom": "^18.3.0",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import logoUrl from "../assets/logo.svg";
|
|
3
|
+
//# BATI.has("mantine")
|
|
4
|
+
import { ColorSchemeScript } from "@mantine/core";
|
|
3
5
|
|
|
4
6
|
// Default <head> (can be overridden by pages)
|
|
5
7
|
|
|
@@ -10,6 +12,7 @@ export default function HeadDefault() {
|
|
|
10
12
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
11
13
|
<meta name="description" content="Demo showcasing Vike" />
|
|
12
14
|
<link rel="icon" href={logoUrl} />
|
|
15
|
+
{BATI.has("mantine") ? <ColorSchemeScript /> : null}
|
|
13
16
|
{/* See https://plausible.io/docs/plausible-script */}
|
|
14
17
|
{/* TODO: update data-domain */}
|
|
15
18
|
<script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.js"></script>
|
|
@@ -21,6 +24,7 @@ export default function HeadDefault() {
|
|
|
21
24
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
22
25
|
<meta name="description" content="Demo showcasing Vike" />
|
|
23
26
|
<link rel="icon" href={logoUrl} />
|
|
27
|
+
{BATI.has("mantine") ? <ColorSchemeScript /> : null}
|
|
24
28
|
<script
|
|
25
29
|
async
|
|
26
30
|
src={`https://www.googletagmanager.com/gtag/js?id=${import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS}`}
|
|
@@ -42,6 +46,7 @@ export default function HeadDefault() {
|
|
|
42
46
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
43
47
|
<meta name="description" content="Demo showcasing Vike" />
|
|
44
48
|
<link rel="icon" href={logoUrl} />
|
|
49
|
+
{BATI.has("mantine") ? <ColorSchemeScript /> : null}
|
|
45
50
|
</>
|
|
46
51
|
);
|
|
47
52
|
}
|
|
@@ -20,13 +20,7 @@ export function TodoList({ initialTodoItems }: { initialTodoItems: { text: strin
|
|
|
20
20
|
|
|
21
21
|
// Optimistic UI update
|
|
22
22
|
setTodoItems((prev) => [...prev, { text: newTodo }]);
|
|
23
|
-
if (
|
|
24
|
-
BATI.has("express") ||
|
|
25
|
-
BATI.has("fastify") ||
|
|
26
|
-
BATI.has("h3") ||
|
|
27
|
-
BATI.has("hattip") ||
|
|
28
|
-
BATI.has("hono")
|
|
29
|
-
) {
|
|
23
|
+
if (BATI.hasServer) {
|
|
30
24
|
try {
|
|
31
25
|
if (BATI.has("telefunc")) {
|
|
32
26
|
await onNewTodo({ text: newTodo });
|
|
@@ -16,7 +16,7 @@ export default defineConfig({
|
|
|
16
16
|
//# BATI.has("hattip") && !BATI.has("vercel")
|
|
17
17
|
hattip(),
|
|
18
18
|
],
|
|
19
|
-
//# BATI.has("vercel") &&
|
|
19
|
+
//# BATI.has("vercel") && BATI.hasServer
|
|
20
20
|
vercel: {
|
|
21
21
|
additionalEndpoints: [
|
|
22
22
|
{
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/compile": "workspace:*",
|
|
46
46
|
"@batijs/core": "workspace:*",
|
|
47
47
|
"@batijs/drizzle": "workspace:*",
|
|
48
|
+
"@batijs/sqlite": "workspace:*",
|
|
48
49
|
"@batijs/features": "workspace:*",
|
|
49
50
|
"@batijs/shared-no-db": "workspace:*",
|
|
50
51
|
"@types/node": "^18.19.14",
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
3
2
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
3
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
4
5
|
|
|
5
6
|
export const createTodoHandler: Get<[], UniversalHandler> = () => async (request) => {
|
|
6
7
|
// In a real case, user-provided data should ALWAYS be validated with tools like zod
|
|
7
8
|
const newTodo = (await request.json()) as { text: string };
|
|
8
9
|
|
|
9
10
|
if (BATI.has("drizzle")) {
|
|
10
|
-
await
|
|
11
|
+
await drizzleQueries.insertTodo(newTodo.text);
|
|
12
|
+
} else if (BATI.has("sqlite")) {
|
|
13
|
+
sqliteQueries.insertTodo(newTodo.text);
|
|
11
14
|
} else {
|
|
12
15
|
// This is where you'd persist the data
|
|
13
16
|
console.log("Received new todo", newTodo);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// https://vike.dev/data
|
|
2
|
-
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
3
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
4
2
|
import { todos } from "@batijs/shared-no-db/database/todoItems";
|
|
3
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
5
5
|
|
|
6
6
|
export type Data = {
|
|
7
7
|
todo: { text: string }[];
|
|
@@ -9,7 +9,11 @@ export type Data = {
|
|
|
9
9
|
|
|
10
10
|
export default async function data(): Promise<Data> {
|
|
11
11
|
if (BATI.has("drizzle")) {
|
|
12
|
-
const todo =
|
|
12
|
+
const todo = drizzleQueries.getAllTodos();
|
|
13
|
+
|
|
14
|
+
return { todo };
|
|
15
|
+
} else if (BATI.has("sqlite")) {
|
|
16
|
+
const todo = sqliteQueries.getAllTodos();
|
|
13
17
|
|
|
14
18
|
return { todo };
|
|
15
19
|
} else {
|
|
@@ -18,13 +18,7 @@ export function TodoList(props: { initialTodoItems: { text: string }[] }) {
|
|
|
18
18
|
|
|
19
19
|
// Optimistic UI update
|
|
20
20
|
setTodoItems((prev) => [...prev, { text: untrack(newTodo) }]);
|
|
21
|
-
if (
|
|
22
|
-
BATI.has("express") ||
|
|
23
|
-
BATI.has("fastify") ||
|
|
24
|
-
BATI.has("h3") ||
|
|
25
|
-
BATI.has("hattip") ||
|
|
26
|
-
BATI.has("hono")
|
|
27
|
-
) {
|
|
21
|
+
if (BATI.hasServer) {
|
|
28
22
|
try {
|
|
29
23
|
if (BATI.has("telefunc")) {
|
|
30
24
|
await onNewTodo({ text: untrack(newTodo) });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// files/$.env.ts
|
|
2
|
+
import { appendToEnv } from "@batijs/core";
|
|
3
|
+
async function getEnv(props) {
|
|
4
|
+
const envContent = await props.readfile?.();
|
|
5
|
+
return appendToEnv(envContent, "DATABASE_URL", "sqlite.db", "Path to the sqlite database");
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
getEnv as default
|
|
9
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// files/$README.md.ts
|
|
2
|
+
import { loadReadme } from "@batijs/core";
|
|
3
|
+
async function getReadme(props) {
|
|
4
|
+
const content = await loadReadme(props);
|
|
5
|
+
const todo = `
|
|
6
|
+
## *Sqlite*
|
|
7
|
+
|
|
8
|
+
First, ensure that \`DATABASE_URL\` is configured in \`.env\` file, then create the database:
|
|
9
|
+
\`\`\`bash
|
|
10
|
+
pnpm sqlite:migrate # creates sqlite tables
|
|
11
|
+
\`\`\`
|
|
12
|
+
`;
|
|
13
|
+
content.addTodo(todo);
|
|
14
|
+
return content.finalize();
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
getReadme as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// package.json
|
|
28
|
+
var require_package = __commonJS({
|
|
29
|
+
"package.json"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
name: "@batijs/sqlite",
|
|
32
|
+
private: true,
|
|
33
|
+
version: "0.0.1",
|
|
34
|
+
description: "",
|
|
35
|
+
type: "module",
|
|
36
|
+
scripts: {
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
build: "bati-compile-boilerplate"
|
|
39
|
+
},
|
|
40
|
+
keywords: [],
|
|
41
|
+
author: "",
|
|
42
|
+
license: "MIT",
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@types/node": "^18.19.14",
|
|
46
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
47
|
+
"better-sqlite3": "^11.2.1",
|
|
48
|
+
dotenv: "^16.4.5",
|
|
49
|
+
tsx: "^4.19.0"
|
|
50
|
+
},
|
|
51
|
+
dependencies: {
|
|
52
|
+
"@batijs/core": "workspace:*"
|
|
53
|
+
},
|
|
54
|
+
files: [
|
|
55
|
+
"dist/"
|
|
56
|
+
],
|
|
57
|
+
bati: {
|
|
58
|
+
if: {
|
|
59
|
+
flag: "sqlite"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
exports: {
|
|
63
|
+
"./database/sqlite/db": {
|
|
64
|
+
types: "./dist/types/database/sqlite/db.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./database/sqlite/queries/lucia-auth": {
|
|
67
|
+
types: "./dist/types/database/sqlite/queries/lucia-auth.d.ts"
|
|
68
|
+
},
|
|
69
|
+
"./database/sqlite/queries/todos": {
|
|
70
|
+
types: "./dist/types/database/sqlite/queries/todos.d.ts"
|
|
71
|
+
},
|
|
72
|
+
"./database/sqlite/schema/lucia-auth": {
|
|
73
|
+
types: "./dist/types/database/sqlite/schema/lucia-auth.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./database/sqlite/schema/todos": {
|
|
76
|
+
types: "./dist/types/database/sqlite/schema/todos.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./database/sqlite/schema/all": {
|
|
79
|
+
types: "./dist/types/database/sqlite/schema/all.d.ts"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
typesVersions: {
|
|
83
|
+
"*": {
|
|
84
|
+
"database/sqlite/db": [
|
|
85
|
+
"./dist/types/database/sqlite/db.d.ts"
|
|
86
|
+
],
|
|
87
|
+
"database/sqlite/queries/lucia-auth": [
|
|
88
|
+
"./dist/types/database/sqlite/queries/lucia-auth.d.ts"
|
|
89
|
+
],
|
|
90
|
+
"database/sqlite/queries/todos": [
|
|
91
|
+
"./dist/types/database/sqlite/queries/todos.d.ts"
|
|
92
|
+
],
|
|
93
|
+
"database/sqlite/schema/lucia-auth": [
|
|
94
|
+
"./dist/types/database/sqlite/schema/lucia-auth.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"database/sqlite/schema/todos": [
|
|
97
|
+
"./dist/types/database/sqlite/schema/todos.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"database/sqlite/schema/all": [
|
|
100
|
+
"./dist/types/database/sqlite/schema/all.d.ts"
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// files/$package.json.ts
|
|
109
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
110
|
+
async function getPackageJson(props) {
|
|
111
|
+
const packageJson = await loadAsJson(props);
|
|
112
|
+
packageJson.scripts["sqlite:migrate"] = "tsx ./database/sqlite/schema/all.ts";
|
|
113
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
114
|
+
devDependencies: ["dotenv", "@types/better-sqlite3", "tsx"],
|
|
115
|
+
dependencies: ["better-sqlite3"]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
getPackageJson as default
|
|
120
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import sqlite, { type Database } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
let singleton: Database | undefined = undefined;
|
|
5
|
+
|
|
6
|
+
export function db(): Database {
|
|
7
|
+
if (!singleton) {
|
|
8
|
+
if (!process.env.DATABASE_URL) {
|
|
9
|
+
throw new Error("Missing DATABASE_URL in .env file");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
singleton = sqlite(process.env.DATABASE_URL);
|
|
13
|
+
}
|
|
14
|
+
return singleton;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { db } from "../db";
|
|
2
|
+
import type { Transaction } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
export function getExistingUser(username: string) {
|
|
5
|
+
return db().prepare("SELECT * FROM users WHERE username = ?").get(username);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
9
|
+
return db()
|
|
10
|
+
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
11
|
+
.get(providerId, providerUserId);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function signupWithGithub(userId: string, username: string, githubUserId: number): Transaction {
|
|
15
|
+
return db().transaction(() => {
|
|
16
|
+
db().prepare("INSERT INTO users (id, username) VALUES (?, ?)").run(userId, username);
|
|
17
|
+
db()
|
|
18
|
+
.prepare("INSERT INTO oauth_accounts (provider_id, provider_user_id, user_id) VALUES (?, ?, ?)")
|
|
19
|
+
.run("github", githubUserId, userId);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function signupWithCredentials(userId: string, username: string, passwordHash: string) {
|
|
24
|
+
return db().prepare("INSERT INTO users (id, username, password) VALUES(?, ?, ?)").run(userId, username, passwordHash);
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { db } from "../db";
|
|
2
|
+
|
|
3
|
+
export function insertTodo(text: string) {
|
|
4
|
+
return db().prepare("INSERT INTO todos (text) VALUES (?)").run(text);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getAllTodos() {
|
|
8
|
+
return db().prepare<[], { id: number; text: string }>("SELECT * FROM todos").all();
|
|
9
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/*# BATI include-if-imported #*/
|
|
2
|
-
import
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { db } from "../db";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const client = db();
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* SQLite Schema
|
|
8
9
|
*
|
|
9
10
|
* @link {@see https://lucia-auth.com/database/sqlite#schema}
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
client.exec(`CREATE TABLE IF NOT EXISTS users (
|
|
12
13
|
id TEXT NOT NULL PRIMARY KEY,
|
|
13
14
|
username TEXT NOT NULL UNIQUE,
|
|
14
15
|
password TEXT
|
|
15
16
|
)`);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
client.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
18
19
|
provider_id TEXT NOT NULL,
|
|
19
20
|
provider_user_id INTEGER NOT NULL,
|
|
20
21
|
user_id TEXT NOT NULL,
|
|
@@ -22,7 +23,7 @@ sqliteDb.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
|
22
23
|
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
23
24
|
)`);
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
client.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
26
27
|
id TEXT NOT NULL PRIMARY KEY,
|
|
27
28
|
expires_at INTEGER NOT NULL,
|
|
28
29
|
user_id TEXT NOT NULL,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { db } from "../db";
|
|
4
|
+
|
|
5
|
+
const client = db();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SQLite Schema
|
|
9
|
+
* `todos` example
|
|
10
|
+
*/
|
|
11
|
+
client.exec(`CREATE TABLE IF NOT EXISTS todos (
|
|
12
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
13
|
+
text TEXT
|
|
14
|
+
)`);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Database } from "better-sqlite3";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function db(): Database;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Transaction } from "better-sqlite3";
|
|
2
|
+
export declare function getExistingUser(username: string): unknown;
|
|
3
|
+
export declare function getExistingAccount(providerId: string, providerUserId: number): unknown;
|
|
4
|
+
export declare function signupWithGithub(userId: string, username: string, githubUserId: number): Transaction;
|
|
5
|
+
export declare function signupWithCredentials(userId: string, username: string, passwordHash: string): import("better-sqlite3").RunResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "dotenv/config";
|