create-absolutejs 0.3.16 → 0.3.19

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.
@@ -37,7 +37,7 @@ export const createPackageJson = ({ projectName, authProvider, plugins, database
37
37
  devDependencies['@tailwindcss/cli'] = resolveVersion('@tailwindcss/cli', '4.1.7');
38
38
  }
39
39
  if (flags.requiresReact) {
40
- dependencies['react'] = resolveVersion('react', '19.1.0');
40
+ dependencies['react'] = resolveVersion('react', '19.1.1');
41
41
  devDependencies['@types/react'] = resolveVersion('@types/react', '19.1.8');
42
42
  }
43
43
  if (flags.requiresSvelte) {
@@ -78,14 +78,17 @@ export const createPackageJson = ({ projectName, authProvider, plugins, database
78
78
  if (databaseEngine === 'postgresql' &&
79
79
  (!databaseHost || databaseHost === 'none')) {
80
80
  scripts['db:up'] =
81
- 'sh -c "docker info >/dev/null 2>&1 || sudo service docker start; docker compose -f db/docker-compose.db.yml up -d db"';
82
- scripts['db:down'] = 'docker compose -f db/docker-compose.db.yml down';
81
+ 'sh -c "docker info >/dev/null 2>&1 || sudo service docker start; docker compose -p postgresql -f db/docker-compose.db.yml up -d db"';
82
+ scripts['db:down'] =
83
+ 'docker compose -p postgresql -f db/docker-compose.db.yml down';
83
84
  scripts['db:reset'] =
84
- 'docker compose -f db/docker-compose.db.yml down -v';
85
+ 'docker compose -p postgresql -f db/docker-compose.db.yml down -v';
85
86
  scripts['db:psql'] =
86
- 'docker compose -f db/docker-compose.db.yml exec db psql -U postgres';
87
+ "docker compose -p postgresql -f db/docker-compose.db.yml exec db bash -lc 'until pg_isready -U user -h localhost --quiet; do sleep 1; done; exec psql -h localhost -U user -d database'";
87
88
  scripts['predev'] = 'bun db:up';
89
+ scripts['predb:psql'] = 'bun db:up';
88
90
  scripts['postdev'] = 'bun db:down';
91
+ scripts['postdb:psql'] = 'bun db:down';
89
92
  }
90
93
  if (databaseEngine === 'mysql') {
91
94
  dependencies['mysql2'] = resolveVersion('mysql2', '3.14.2');
@@ -93,14 +96,17 @@ export const createPackageJson = ({ projectName, authProvider, plugins, database
93
96
  if (databaseEngine === 'mysql' &&
94
97
  (!databaseHost || databaseHost === 'none')) {
95
98
  scripts['db:up'] =
96
- 'sh -c "docker info >/dev/null 2>&1 || sudo service docker start; docker compose -f db/docker-compose.db.yml up -d db"';
97
- scripts['db:down'] = 'docker compose -f db/docker-compose.db.yml down';
99
+ 'sh -c "docker info >/dev/null 2>&1 || sudo service docker start; docker compose -p mysql -f db/docker-compose.db.yml up -d db"';
100
+ scripts['db:down'] =
101
+ 'docker compose -p mysql -f db/docker-compose.db.yml down';
98
102
  scripts['db:reset'] =
99
- 'docker compose -f db/docker-compose.db.yml down -v';
103
+ 'docker compose -p mysql -f db/docker-compose.db.yml down -v';
100
104
  scripts['db:mysql'] =
101
- 'docker compose -f db/docker-compose.db.yml exec db mysql -u user -ppassword';
105
+ "docker compose -p mysql -f db/docker-compose.db.yml exec -e MYSQL_PWD=rootpassword db bash -lc 'until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done; exec mysql -h127.0.0.1 -uroot'";
102
106
  scripts['predev'] = 'bun db:up';
107
+ scripts['predb:mysql'] = 'bun db:up';
103
108
  scripts['postdev'] = 'bun db:down';
109
+ scripts['postdb:mysql'] = 'bun db:down';
104
110
  }
105
111
  if (databaseEngine === 'sqlite' &&
106
112
  (!databaseHost || databaseHost === 'none')) {
@@ -0,0 +1,48 @@
1
+ export declare const userTables: {
2
+ readonly cockroachdb: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT NOW(),\n metadata JSONB DEFAULT '{}'::jsonb\n);";
3
+ readonly gel: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT NOW(),\n metadata JSON DEFAULT '{}'::json\n);";
4
+ readonly mariadb: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n metadata JSON DEFAULT ('{}')\n);";
5
+ readonly mssql: "IF OBJECT_ID('users','U') IS NULL\nBEGIN\n CREATE TABLE users (\n auth_sub NVARCHAR(255) PRIMARY KEY,\n created_at DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),\n metadata NVARCHAR(MAX) NULL\n );\nEND;";
6
+ readonly mysql: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n metadata JSON DEFAULT (JSON_OBJECT())\n);";
7
+ readonly postgresql: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT NOW(),\n metadata JSONB DEFAULT '{}'::jsonb\n);";
8
+ readonly singlestore: "CREATE TABLE IF NOT EXISTS users (\n auth_sub VARCHAR(255) PRIMARY KEY,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n metadata JSON DEFAULT ('{}')\n);";
9
+ };
10
+ export declare const countHistoryTables: {
11
+ readonly cockroachdb: "CREATE TABLE IF NOT EXISTS count_history (\n uid INT PRIMARY KEY DEFAULT unique_rowid(),\n count INT NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT NOW()\n);";
12
+ readonly gel: "CREATE TABLE IF NOT EXISTS count_history (\n uid INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,\n count INTEGER NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT NOW()\n);";
13
+ readonly mariadb: "CREATE TABLE IF NOT EXISTS count_history (\n uid INT AUTO_INCREMENT PRIMARY KEY,\n count INT NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);";
14
+ readonly mssql: "IF OBJECT_ID('count_history','U') IS NULL\nBEGIN\n CREATE TABLE count_history (\n uid INT IDENTITY(1,1) PRIMARY KEY,\n count INT NOT NULL,\n created_at DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()\n );\nEND;";
15
+ readonly mysql: "CREATE TABLE IF NOT EXISTS count_history (\n uid INT AUTO_INCREMENT PRIMARY KEY,\n count INT NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);";
16
+ readonly postgresql: "CREATE TABLE IF NOT EXISTS count_history (\n uid INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,\n count INTEGER NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT NOW()\n);";
17
+ readonly singlestore: "CREATE TABLE IF NOT EXISTS count_history (\n uid INT AUTO_INCREMENT PRIMARY KEY,\n count INT NOT NULL,\n created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);";
18
+ };
19
+ export declare const initTemplates: {
20
+ readonly cockroachdb: {
21
+ readonly cli: "cockroach sql --insecure --host=localhost -e";
22
+ readonly wait: "until pg_isready -U root -h localhost --quiet; do sleep 1; done";
23
+ };
24
+ readonly gel: {
25
+ readonly cli: "psql -U user -d database -c";
26
+ readonly wait: "until pg_isready -U user -h localhost --quiet; do sleep 1; done";
27
+ };
28
+ readonly mariadb: {
29
+ readonly cli: "MYSQL_PWD=userpassword mariadb -h127.0.0.1 -u user -e";
30
+ readonly wait: "until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done";
31
+ };
32
+ readonly mssql: {
33
+ readonly cli: "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P sapassword -Q";
34
+ readonly wait: "until /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P sapassword -Q \"SELECT 1\" >/dev/null 2>&1; do sleep 1; done";
35
+ };
36
+ readonly mysql: {
37
+ readonly cli: "MYSQL_PWD=userpassword mysql -h127.0.0.1 -u user database -e";
38
+ readonly wait: "until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done";
39
+ };
40
+ readonly postgresql: {
41
+ readonly cli: "psql -U user -d database -c";
42
+ readonly wait: "until pg_isready -U user -h localhost --quiet; do sleep 1; done";
43
+ };
44
+ readonly singlestore: {
45
+ readonly cli: "MYSQL_PWD=userpassword mysql -h127.0.0.1 -u user -e";
46
+ readonly wait: "until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done";
47
+ };
48
+ };
@@ -0,0 +1,124 @@
1
+ const postgresqlUsers = `CREATE TABLE IF NOT EXISTS users (
2
+ auth_sub VARCHAR(255) PRIMARY KEY,
3
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
4
+ metadata JSONB DEFAULT '{}'::jsonb
5
+ );`;
6
+ const postgresqlCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
7
+ uid INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
8
+ count INTEGER NOT NULL,
9
+ created_at TIMESTAMP NOT NULL DEFAULT NOW()
10
+ );`;
11
+ const mysqlUsers = `CREATE TABLE IF NOT EXISTS users (
12
+ auth_sub VARCHAR(255) PRIMARY KEY,
13
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
14
+ metadata JSON DEFAULT (JSON_OBJECT())
15
+ );`;
16
+ const mysqlCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
17
+ uid INT AUTO_INCREMENT PRIMARY KEY,
18
+ count INT NOT NULL,
19
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
20
+ );`;
21
+ const mariadbUsers = `CREATE TABLE IF NOT EXISTS users (
22
+ auth_sub VARCHAR(255) PRIMARY KEY,
23
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
24
+ metadata JSON DEFAULT ('{}')
25
+ );`;
26
+ const mariadbCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
27
+ uid INT AUTO_INCREMENT PRIMARY KEY,
28
+ count INT NOT NULL,
29
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
30
+ );`;
31
+ const singlestoreUsers = `CREATE TABLE IF NOT EXISTS users (
32
+ auth_sub VARCHAR(255) PRIMARY KEY,
33
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
34
+ metadata JSON DEFAULT ('{}')
35
+ );`;
36
+ const singlestoreCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
37
+ uid INT AUTO_INCREMENT PRIMARY KEY,
38
+ count INT NOT NULL,
39
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
40
+ );`;
41
+ const cockroachdbUsers = `CREATE TABLE IF NOT EXISTS users (
42
+ auth_sub VARCHAR(255) PRIMARY KEY,
43
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
44
+ metadata JSONB DEFAULT '{}'::jsonb
45
+ );`;
46
+ const cockroachdbCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
47
+ uid INT PRIMARY KEY DEFAULT unique_rowid(),
48
+ count INT NOT NULL,
49
+ created_at TIMESTAMP NOT NULL DEFAULT NOW()
50
+ );`;
51
+ const mssqlUsers = `IF OBJECT_ID('users','U') IS NULL
52
+ BEGIN
53
+ CREATE TABLE users (
54
+ auth_sub NVARCHAR(255) PRIMARY KEY,
55
+ created_at DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME(),
56
+ metadata NVARCHAR(MAX) NULL
57
+ );
58
+ END;`;
59
+ const mssqlCountHistory = `IF OBJECT_ID('count_history','U') IS NULL
60
+ BEGIN
61
+ CREATE TABLE count_history (
62
+ uid INT IDENTITY(1,1) PRIMARY KEY,
63
+ count INT NOT NULL,
64
+ created_at DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME()
65
+ );
66
+ END;`;
67
+ const gelUsers = `CREATE TABLE IF NOT EXISTS users (
68
+ auth_sub VARCHAR(255) PRIMARY KEY,
69
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
70
+ metadata JSON DEFAULT '{}'::json
71
+ );`;
72
+ const gelCountHistory = `CREATE TABLE IF NOT EXISTS count_history (
73
+ uid INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
74
+ count INTEGER NOT NULL,
75
+ created_at TIMESTAMP NOT NULL DEFAULT NOW()
76
+ );`;
77
+ export const userTables = {
78
+ cockroachdb: cockroachdbUsers,
79
+ gel: gelUsers,
80
+ mariadb: mariadbUsers,
81
+ mssql: mssqlUsers,
82
+ mysql: mysqlUsers,
83
+ postgresql: postgresqlUsers,
84
+ singlestore: singlestoreUsers
85
+ };
86
+ export const countHistoryTables = {
87
+ cockroachdb: cockroachdbCountHistory,
88
+ gel: gelCountHistory,
89
+ mariadb: mariadbCountHistory,
90
+ mssql: mssqlCountHistory,
91
+ mysql: mysqlCountHistory,
92
+ postgresql: postgresqlCountHistory,
93
+ singlestore: singlestoreCountHistory
94
+ };
95
+ export const initTemplates = {
96
+ cockroachdb: {
97
+ cli: 'cockroach sql --insecure --host=localhost -e',
98
+ wait: 'until pg_isready -U root -h localhost --quiet; do sleep 1; done'
99
+ },
100
+ gel: {
101
+ cli: 'psql -U user -d database -c',
102
+ wait: 'until pg_isready -U user -h localhost --quiet; do sleep 1; done'
103
+ },
104
+ mariadb: {
105
+ cli: 'MYSQL_PWD=userpassword mariadb -h127.0.0.1 -u user -e',
106
+ wait: 'until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done'
107
+ },
108
+ mssql: {
109
+ cli: '/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P sapassword -Q',
110
+ wait: 'until /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P sapassword -Q "SELECT 1" >/dev/null 2>&1; do sleep 1; done'
111
+ },
112
+ mysql: {
113
+ cli: 'MYSQL_PWD=userpassword mysql -h127.0.0.1 -u user database -e',
114
+ wait: 'until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done'
115
+ },
116
+ postgresql: {
117
+ cli: 'psql -U user -d database -c',
118
+ wait: 'until pg_isready -U user -h localhost --quiet; do sleep 1; done'
119
+ },
120
+ singlestore: {
121
+ cli: 'MYSQL_PWD=userpassword mysql -h127.0.0.1 -u user -e',
122
+ wait: 'until mysqladmin ping -h127.0.0.1 --silent; do sleep 1; done'
123
+ }
124
+ };
@@ -0,0 +1,2 @@
1
+ import { DatabaseEngine } from '../../types';
2
+ export declare const generateDockerContainer: (databaseEngine: DatabaseEngine) => string;
@@ -78,7 +78,7 @@ const templates = {
78
78
  volumePath: '/var/lib/memsql'
79
79
  }
80
80
  };
81
- export const generateDatabaseContainer = (databaseEngine) => {
81
+ export const generateDockerContainer = (databaseEngine) => {
82
82
  if (databaseEngine === undefined ||
83
83
  databaseEngine === 'none' ||
84
84
  databaseEngine === 'sqlite') {
@@ -3,18 +3,12 @@ import { join } from 'path';
3
3
  import { $ } from 'bun';
4
4
  import { dim, yellow } from 'picocolors';
5
5
  import { isDrizzleDialect } from '../../typeGuards';
6
- import { checkDockerInstalled } from '../../utils/checkDockerInstalled';
7
6
  import { checkSqliteInstalled } from '../../utils/checkSqliteInstalled';
8
7
  import { createDrizzleConfig } from '../configurations/generateDrizzleConfig';
9
- import { generateDatabaseContainer } from './generateDBContainer';
10
- import { generateDBHandlers } from './generateDBHandlers';
11
8
  import { generateDrizzleSchema } from './generateDrizzleSchema';
9
+ import { generateDBHandlers } from './generateHandlers';
12
10
  import { generateSqliteSchema } from './generateSqliteSchema';
13
- const scaffoldDocker = async (databaseEngine, projectDatabaseDirectory) => {
14
- await checkDockerInstalled();
15
- const dbContainer = generateDatabaseContainer(databaseEngine);
16
- writeFileSync(join(projectDatabaseDirectory, 'docker-compose.db.yml'), dbContainer, 'utf-8');
17
- };
11
+ import { scaffoldDocker } from './scaffoldDocker';
18
12
  export const scaffoldDatabase = async ({ projectName, databaseEngine, databaseHost, databaseDirectory, backendDirectory, authProvider, orm }) => {
19
13
  const projectDatabaseDirectory = join(projectName, databaseDirectory);
20
14
  const handlerDirectory = join(backendDirectory, 'handlers');
@@ -39,8 +33,14 @@ export const scaffoldDatabase = async ({ projectName, databaseEngine, databaseHo
39
33
  await $ `sqlite3 ${databaseDirectory}/database.sqlite ".read ${join(databaseDirectory, 'schema.sql')}"`.cwd(projectName);
40
34
  }
41
35
  if (databaseEngine !== 'sqlite' &&
42
- (databaseHost === undefined || databaseHost === 'none')) {
43
- await scaffoldDocker(databaseEngine, projectDatabaseDirectory);
36
+ databaseEngine !== undefined &&
37
+ databaseEngine !== 'none') {
38
+ await scaffoldDocker({
39
+ authProvider,
40
+ databaseEngine,
41
+ projectDatabaseDirectory,
42
+ projectName
43
+ });
44
44
  }
45
45
  if (orm === 'drizzle') {
46
46
  if (!isDrizzleDialect(databaseEngine)) {
@@ -0,0 +1,9 @@
1
+ import { AuthProvider, DatabaseEngine } from '../../types';
2
+ type ScaffoldDockerProps = {
3
+ databaseEngine: DatabaseEngine;
4
+ projectDatabaseDirectory: string;
5
+ authProvider: AuthProvider;
6
+ projectName: string;
7
+ };
8
+ export declare const scaffoldDocker: ({ databaseEngine, projectDatabaseDirectory, projectName, authProvider }: ScaffoldDockerProps) => Promise<void>;
9
+ export {};
@@ -0,0 +1,29 @@
1
+ import { writeFileSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { $ } from 'bun';
4
+ import { checkDockerInstalled } from '../../utils/checkDockerInstalled';
5
+ import { countHistoryTables, initTemplates, userTables } from './dockerInitTemplates';
6
+ import { generateDockerContainer } from './generateDockerContainer';
7
+ export const scaffoldDocker = async ({ databaseEngine, projectDatabaseDirectory, projectName, authProvider }) => {
8
+ if (databaseEngine === undefined ||
9
+ databaseEngine === 'none' ||
10
+ databaseEngine === 'sqlite') {
11
+ throw new Error('Internal type error: databaseEngine must be defined and not "none" or "sqlite"');
12
+ }
13
+ await checkDockerInstalled();
14
+ const dbContainer = generateDockerContainer(databaseEngine);
15
+ writeFileSync(join(projectDatabaseDirectory, 'docker-compose.db.yml'), dbContainer, 'utf-8');
16
+ if (databaseEngine === 'mongodb') {
17
+ }
18
+ else {
19
+ const { wait, cli } = initTemplates[databaseEngine];
20
+ const usesAuth = authProvider !== undefined && authProvider !== 'none';
21
+ const dbCommand = usesAuth
22
+ ? userTables[databaseEngine]
23
+ : countHistoryTables[databaseEngine];
24
+ await $ `bun db:up`.cwd(projectName);
25
+ await $ `docker compose -p ${databaseEngine} -f db/docker-compose.db.yml exec -T db \
26
+ bash -lc '${wait} && ${cli} "${dbCommand}"'`.cwd(projectName);
27
+ await $ `bun db:down`.cwd(projectName);
28
+ }
29
+ };
@@ -27,7 +27,10 @@ export const generateServerFile = ({ tailwind, authProvider, plugins, buildDirec
27
27
  frontendDirectories,
28
28
  tailwind
29
29
  });
30
- const dbBlock = generateDBBlock({ databaseEngine, databaseHost, orm });
30
+ let dbBlock = '';
31
+ if (databaseEngine && databaseEngine !== 'none') {
32
+ dbBlock = generateDBBlock({ databaseEngine, databaseHost, orm });
33
+ }
31
34
  const useBlock = generateUseBlock({
32
35
  databaseEngine,
33
36
  deps,
package/package.json CHANGED
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "scripts": {
41
41
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp -R src/templates dist/templates",
42
- "dev": "rm -rf absolutejs-project && bun run src/index.ts",
42
+ "dev": "if [ -f absolutejs-project/package.json ] && grep -q '\"db:reset\"' absolutejs-project/package.json; then cd absolutejs-project && bun run db:reset && cd ..; fi && rm -rf absolutejs-project && bun run src/index.ts",
43
43
  "format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json,mjs,md,svelte,html,vue}\"",
44
44
  "lint": "eslint ./",
45
45
  "release": "bun run format && bun run build && bun publish",
@@ -47,5 +47,5 @@
47
47
  "typecheck": "bun run tsc --noEmit"
48
48
  },
49
49
  "type": "module",
50
- "version": "0.3.16"
50
+ "version": "0.3.19"
51
51
  }
@@ -1,2 +0,0 @@
1
- import { DatabaseEngine } from '../../types';
2
- export declare const generateDatabaseContainer: (databaseEngine: DatabaseEngine) => string;