@starbemtech/star-db-query-builder 1.0.38 → 1.2.1

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 (85) hide show
  1. package/.github/workflows/publish.yml +118 -0
  2. package/ARCHITECTURE.md +313 -0
  3. package/CHANGELOG.md +65 -0
  4. package/README.md +1309 -129
  5. package/coverage/base.css +224 -0
  6. package/coverage/block-navigation.js +87 -0
  7. package/coverage/favicon.png +0 -0
  8. package/coverage/index.html +131 -0
  9. package/coverage/lcov-report/block-navigation.js +1 -1
  10. package/coverage/lcov-report/index.html +41 -11
  11. package/coverage/lcov-report/mysqlClient.ts.html +685 -0
  12. package/coverage/lcov-report/pgClient.ts.html +823 -0
  13. package/coverage/lcov-report/sorter.js +21 -7
  14. package/coverage/lcov.info +533 -0
  15. package/coverage/mysqlClient.ts.html +685 -0
  16. package/coverage/pgClient.ts.html +823 -0
  17. package/coverage/prettify.css +1 -0
  18. package/coverage/prettify.js +2 -0
  19. package/coverage/sort-arrow-sprite.png +0 -0
  20. package/coverage/sorter.js +210 -0
  21. package/dist/index.d.ts +5 -4
  22. package/dist/index.js +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/src/core/repository.d.ts +374 -0
  25. package/dist/src/core/repository.js +677 -0
  26. package/dist/src/core/repository.js.map +1 -0
  27. package/dist/src/{default → core}/types.d.ts +9 -1
  28. package/dist/src/{default → core}/types.js.map +1 -1
  29. package/dist/src/core/utils.d.ts +133 -0
  30. package/dist/src/{default → core}/utils.js +167 -0
  31. package/dist/src/core/utils.js.map +1 -0
  32. package/dist/src/db/IDatabaseClient.d.ts +10 -1
  33. package/dist/src/db/initDb.d.ts +120 -1
  34. package/dist/src/db/initDb.js +119 -0
  35. package/dist/src/db/initDb.js.map +1 -1
  36. package/dist/src/db/mysqlClient.d.ts +23 -1
  37. package/dist/src/db/mysqlClient.js +115 -0
  38. package/dist/src/db/mysqlClient.js.map +1 -1
  39. package/dist/src/db/pgClient.d.ts +22 -1
  40. package/dist/src/db/pgClient.js +127 -0
  41. package/dist/src/db/pgClient.js.map +1 -1
  42. package/dist/src/monitor/monitor.d.ts +6 -1
  43. package/dist/src/monitor/monitor.js +5 -0
  44. package/dist/src/monitor/monitor.js.map +1 -1
  45. package/dist/src/setupTests.d.ts +26 -0
  46. package/dist/src/setupTests.js +43 -0
  47. package/dist/src/setupTests.js.map +1 -0
  48. package/docs/INDEX.md +145 -0
  49. package/docs/methods/findFirst.md +394 -0
  50. package/docs/methods/findMany.md +587 -0
  51. package/docs/methods/insert.md +536 -0
  52. package/docs/methods/insertMany.md +627 -0
  53. package/docs/methods/joins.md +781 -0
  54. package/docs/methods/rawQuery.md +284 -0
  55. package/docs/methods/transactions.md +737 -0
  56. package/eslint.config.mjs +77 -0
  57. package/index.ts +5 -4
  58. package/jest.config.ts +23 -28
  59. package/package.json +52 -29
  60. package/scripts/release.sh +123 -0
  61. package/src/core/repository.ts +865 -0
  62. package/src/{default → core}/types.ts +11 -2
  63. package/src/{default → core}/utils.ts +168 -0
  64. package/src/db/IDatabaseClient.ts +11 -1
  65. package/src/db/__tests__/mysqlClient.test.ts +262 -0
  66. package/src/db/__tests__/pgClient.test.ts +260 -0
  67. package/src/db/initDb.ts +120 -1
  68. package/src/db/mysqlClient.ts +119 -3
  69. package/src/db/pgClient.ts +131 -3
  70. package/src/monitor/monitor.ts +5 -0
  71. package/src/setupTests.ts +45 -0
  72. package/tsconfig.test.json +21 -0
  73. package/.eslintignore +0 -4
  74. package/.eslintrc.json +0 -32
  75. package/coverage/clover.xml +0 -6
  76. package/coverage/coverage-final.json +0 -1
  77. package/dist/.eslintrc.json +0 -32
  78. package/dist/src/default/genericRepository.d.ts +0 -20
  79. package/dist/src/default/genericRepository.js +0 -192
  80. package/dist/src/default/genericRepository.js.map +0 -1
  81. package/dist/src/default/utils.d.ts +0 -9
  82. package/dist/src/default/utils.js.map +0 -1
  83. package/index.d.ts +0 -60
  84. package/src/default/genericRepository.ts +0 -320
  85. /package/dist/src/{default → core}/types.js +0 -0
@@ -0,0 +1,77 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+ import tseslint from "typescript-eslint";
4
+ import prettier from "eslint-plugin-prettier";
5
+ import { defineConfig } from "eslint/config";
6
+
7
+ export default defineConfig([
8
+ // Ignore patterns (replaces .eslintignore)
9
+ {
10
+ ignores: [
11
+ "dist/**",
12
+ "build/**",
13
+ "coverage/**",
14
+ "node_modules/**",
15
+ "*.js",
16
+ "*.d.ts",
17
+ "examples/**",
18
+ ],
19
+ },
20
+
21
+ // Base configuration for all files
22
+ {
23
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
24
+ languageOptions: {
25
+ ecmaVersion: "latest",
26
+ sourceType: "module",
27
+ globals: {
28
+ ...globals.node,
29
+ ...globals.es2021,
30
+ },
31
+ parser: tseslint.parser,
32
+ parserOptions: {
33
+ ecmaVersion: "latest",
34
+ sourceType: "module",
35
+ },
36
+ },
37
+ plugins: {
38
+ "@typescript-eslint": tseslint.plugin,
39
+ prettier: prettier,
40
+ },
41
+ rules: {
42
+ // Prettier
43
+ "prettier/prettier": "error",
44
+
45
+ // TypeScript rules
46
+ "@typescript-eslint/explicit-function-return-type": "off",
47
+ "@typescript-eslint/no-explicit-any": "off",
48
+ "@typescript-eslint/explicit-module-boundary-types": "off",
49
+ "@typescript-eslint/no-require-imports": "off",
50
+ "@typescript-eslint/no-unused-vars": "warn",
51
+
52
+ // General rules
53
+ "import/prefer-default-export": "off",
54
+ "no-param-reassign": "off",
55
+ "no-console": "off",
56
+ "no-return-assign": "off",
57
+ "array-callback-return": "off",
58
+ },
59
+ },
60
+
61
+ // TypeScript specific configuration
62
+ ...tseslint.configs.recommended.map(config => ({
63
+ ...config,
64
+ rules: {
65
+ ...config.rules,
66
+ "@typescript-eslint/no-explicit-any": "off",
67
+ },
68
+ })),
69
+
70
+ // Prettier configuration
71
+ {
72
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
73
+ rules: {
74
+ "prettier/prettier": "error",
75
+ },
76
+ },
77
+ ]);
package/index.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { PoolConfig as PgPoolConfig } from 'pg'
1
+ import { PoolConfig as PgPoolConfig, PoolOptions as PgPoolOptions } from 'pg'
2
2
  import { PoolOptions as MySqlPoolOptions } from 'mysql2'
3
- import { Conditions as TypeConditions } from './src/default/types'
3
+ import { Conditions as TypeConditions } from './src/core/types'
4
4
 
5
5
  // Configs
6
6
  export * from './src/db/initDb'
7
7
 
8
8
  // Generic Repository
9
- export * from './src/default/genericRepository'
9
+ export * from './src/core/repository'
10
10
 
11
11
  // Monitor
12
12
  export * from './src/monitor/monitor'
13
13
 
14
14
  // Types Definition
15
- export type { PgPoolConfig, MySqlPoolOptions, TypeConditions }
15
+ export type { PgPoolConfig, PgPoolOptions, MySqlPoolOptions, TypeConditions }
16
+ export type * from './src/core/types'
package/jest.config.ts CHANGED
@@ -36,15 +36,17 @@ const config: Config = {
36
36
  coverageProvider: 'v8',
37
37
 
38
38
  // A list of reporter names that Jest uses when writing coverage reports
39
- // coverageReporters: [
40
- // "json",
41
- // "text",
42
- // "lcov",
43
- // "clover"
44
- // ],
39
+ coverageReporters: ['text', 'lcov', 'html'],
45
40
 
46
41
  // An object that configures minimum threshold enforcement for coverage results
47
- // coverageThreshold: undefined,
42
+ coverageThreshold: {
43
+ global: {
44
+ branches: 70,
45
+ functions: 70,
46
+ lines: 70,
47
+ statements: 70,
48
+ },
49
+ },
48
50
 
49
51
  // A path to a custom dependency extractor
50
52
  // dependencyExtractor: undefined,
@@ -78,16 +80,7 @@ const config: Config = {
78
80
  // ],
79
81
 
80
82
  // An array of file extensions your modules use
81
- // moduleFileExtensions: [
82
- // "js",
83
- // "mjs",
84
- // "cjs",
85
- // "jsx",
86
- // "ts",
87
- // "tsx",
88
- // "json",
89
- // "node"
90
- // ],
83
+ moduleFileExtensions: ['ts', 'js', 'json'],
91
84
 
92
85
  // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93
86
  // moduleNameMapper: {},
@@ -137,7 +130,7 @@ const config: Config = {
137
130
  // setupFiles: [],
138
131
 
139
132
  // A list of paths to modules that run some code to configure or set up the testing framework before each test
140
- // setupFilesAfterEnv: [],
133
+ setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
141
134
 
142
135
  // The number of seconds after which a test is considered as slow and reported as such in the results.
143
136
  // slowTestThreshold: 5,
@@ -146,7 +139,7 @@ const config: Config = {
146
139
  // snapshotSerializers: [],
147
140
 
148
141
  // The test environment that will be used for testing
149
- // testEnvironment: "jest-environment-node",
142
+ testEnvironment: 'node',
150
143
 
151
144
  // Options that will be passed to the testEnvironment
152
145
  // testEnvironmentOptions: {},
@@ -155,15 +148,10 @@ const config: Config = {
155
148
  // testLocationInResults: false,
156
149
 
157
150
  // The glob patterns Jest uses to detect test files
158
- // testMatch: [
159
- // "**/__tests__/**/*.[jt]s?(x)",
160
- // "**/?(*.)+(spec|test).[tj]s?(x)"
161
- // ],
151
+ testMatch: ['**/__tests__/**/*.(ts|js)', '**/?(*.)+(spec|test).(ts|js)'],
162
152
 
163
153
  // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
164
- // testPathIgnorePatterns: [
165
- // "/node_modules/"
166
- // ],
154
+ testPathIgnorePatterns: ['/node_modules/', '/dist/'],
167
155
 
168
156
  // The regexp pattern or array of patterns that Jest uses to detect test files
169
157
  // testRegex: [],
@@ -175,7 +163,14 @@ const config: Config = {
175
163
  // testRunner: "jest-circus/runner",
176
164
 
177
165
  // A map from regular expressions to paths to transformers
178
- // transform: undefined,
166
+ transform: {
167
+ '^.+\\.(ts|tsx)$': [
168
+ 'ts-jest',
169
+ {
170
+ tsconfig: 'tsconfig.test.json',
171
+ },
172
+ ],
173
+ },
179
174
 
180
175
  // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
181
176
  // transformIgnorePatterns: [
@@ -187,7 +182,7 @@ const config: Config = {
187
182
  // unmockedModulePathPatterns: undefined,
188
183
 
189
184
  // Indicates whether each individual test should be reported during the run
190
- // verbose: undefined,
185
+ verbose: true,
191
186
 
192
187
  // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
193
188
  // watchPathIgnorePatterns: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starbemtech/star-db-query-builder",
3
- "version": "1.0.38",
3
+ "version": "1.2.1",
4
4
  "description": "A query builder to be used with mysql or postgres",
5
5
  "author": "Julio Sousa <julio.sousa@starbem.app>",
6
6
  "main": "./dist/index.js",
@@ -9,12 +9,6 @@
9
9
  "engines": {
10
10
  "node": ">=18"
11
11
  },
12
- "scripts": {
13
- "build": "tsc",
14
- "prepare": "husky",
15
- "test": "jest --passWithNoTests",
16
- "coverage": "jest --watchAll --coverage"
17
- },
18
12
  "repository": {
19
13
  "type": "git",
20
14
  "url": "git+https://github.com/starbem/star-db-query-builder.git"
@@ -27,34 +21,63 @@
27
21
  "postgres",
28
22
  "mysql",
29
23
  "sql",
30
- "database"
24
+ "database",
25
+ "query-builder",
26
+ "starbem",
27
+ "starbemtech"
31
28
  ],
32
- "devDependencies": {
33
- "@types/jest": "^29.5.12",
34
- "@types/mysql": "^2.15.26",
35
- "@types/node": "^20.11.30",
36
- "@types/pg": "^8.11.11",
37
- "@types/promise-retry": "^1.1.6",
38
- "@types/uuid": "^9.0.8",
39
- "@typescript-eslint/eslint-plugin": "^7.4.0",
40
- "@typescript-eslint/parser": "^7.4.0",
41
- "eslint": "^8.57.0",
42
- "eslint-config-prettier": "^9.1.0",
43
- "eslint-plugin-jest": "^27.9.0",
44
- "eslint-plugin-prettier": "^5.1.3",
45
- "husky": "^9.0.11",
46
- "jest": "^29.7.0",
47
- "lint-staged": "^15.2.2",
48
- "prettier": "^3.2.5",
49
- "ts-node": "^10.9.2",
50
- "typescript": "^5.8.2"
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "prepare": "husky",
32
+ "test": "jest",
33
+ "test:watch": "jest --watch",
34
+ "test:coverage": "jest --coverage",
35
+ "test:ci": "jest --ci --coverage --watchAll=false",
36
+ "lint": "eslint src/**/*.ts",
37
+ "lint:fix": "eslint src/**/*.ts --fix",
38
+ "format": "prettier --write src/**/*.ts",
39
+ "type:check": "tsc --noEmit",
40
+ "clean": "rm -rf dist coverage",
41
+ "prebuild": "npm run clean",
42
+ "version:patch": "npm version patch",
43
+ "version:minor": "npm version minor",
44
+ "version:major": "npm version major",
45
+ "release": "bash scripts/release.sh",
46
+ "release:patch": "npm version patch && git push origin --tags",
47
+ "release:minor": "npm version minor && git push origin --tags",
48
+ "release:major": "npm version major && git push origin --tags",
49
+ "prepublishOnly": "npm run clean && npm run build && npm run test:ci"
51
50
  },
52
51
  "dependencies": {
53
- "mysql2": "^3.13.0",
54
- "pg": "^8.13.3",
52
+ "mysql2": "^3.14.5",
53
+ "pg": "^8.16.3",
55
54
  "promise-retry": "^2.0.1",
56
55
  "uuid": "^11.1.0"
57
56
  },
57
+ "devDependencies": {
58
+ "@eslint/js": "^9.35.0",
59
+ "@types/jest": "^29.5.14",
60
+ "@types/mysql": "^2.15.27",
61
+ "@types/node": "^24.3.1",
62
+ "@types/pg": "^8.15.5",
63
+ "@types/promise-retry": "^1.1.6",
64
+ "@types/uuid": "^10.0.0",
65
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
66
+ "@typescript-eslint/parser": "^7.18.0",
67
+ "eslint": "^9.35.0",
68
+ "eslint-config-prettier": "^10.1.8",
69
+ "eslint-plugin-jest": "^28.14.0",
70
+ "eslint-plugin-prettier": "^5.5.4",
71
+ "globals": "^16.3.0",
72
+ "husky": "^9.1.7",
73
+ "jest": "^29.7.0",
74
+ "lint-staged": "^16.1.6",
75
+ "prettier": "^3.6.2",
76
+ "ts-jest": "^29.4.1",
77
+ "ts-node": "^10.9.2",
78
+ "typescript": "^5.9.2",
79
+ "typescript-eslint": "^8.43.0"
80
+ },
58
81
  "lint-staged": {
59
82
  "*.{ts}": [
60
83
  "eslint --fix",
@@ -0,0 +1,123 @@
1
+ #!/bin/bash
2
+
3
+ # Script para facilitar o processo de release da lib star-db-query-builder
4
+
5
+ set -e
6
+
7
+ # Cores para output
8
+ RED='\033[0;31m'
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ NC='\033[0m' # No Color
12
+
13
+ # Função para imprimir mensagens coloridas
14
+ print_message() {
15
+ echo -e "${GREEN}[INFO]${NC} $1"
16
+ }
17
+
18
+ print_warning() {
19
+ echo -e "${YELLOW}[WARNING]${NC} $1"
20
+ }
21
+
22
+ print_error() {
23
+ echo -e "${RED}[ERROR]${NC} $1"
24
+ }
25
+
26
+ # Verificar se estamos na branch main
27
+ CURRENT_BRANCH=$(git branch --show-current)
28
+ if [ "$CURRENT_BRANCH" != "main" ]; then
29
+ print_error "Você deve estar na branch main para fazer um release"
30
+ print_message "Execute: git checkout main"
31
+ exit 1
32
+ fi
33
+
34
+ # Verificar se há mudanças não commitadas
35
+ if [ -n "$(git status --porcelain)" ]; then
36
+ print_error "Há mudanças não commitadas no repositório"
37
+ print_message "Faça commit ou stash das mudanças antes de continuar"
38
+ exit 1
39
+ fi
40
+
41
+ # Atualizar branch local
42
+ print_message "Atualizando branch local..."
43
+ git pull origin main
44
+
45
+ # Executar testes
46
+ print_message "Executando testes..."
47
+ pnpm run test:ci
48
+
49
+ # Executar linting
50
+ print_message "Executando linting..."
51
+ pnpm run lint
52
+
53
+ # Build do projeto
54
+ print_message "Fazendo build do projeto..."
55
+ pnpm run build
56
+
57
+ # Atualizar CHANGELOG
58
+ print_message "Atualizando CHANGELOG..."
59
+ CURRENT_DATE=$(date +%Y-%m-%d)
60
+ sed -i.bak "s/## \[Unreleased\]/## [Unreleased]\n\n## [$NEW_VERSION] - $CURRENT_DATE/" CHANGELOG.md
61
+ rm CHANGELOG.md.bak
62
+
63
+ # Commit das mudanças do CHANGELOG
64
+ git add CHANGELOG.md
65
+ git commit -m "docs: update changelog for version $NEW_VERSION" || true
66
+
67
+ # Perguntar tipo de versão
68
+ echo ""
69
+ print_message "Escolha o tipo de versão:"
70
+ echo "1) Patch (1.1.0 → 1.1.1) - Correções de bugs"
71
+ echo "2) Minor (1.1.0 → 1.2.0) - Novas funcionalidades"
72
+ echo "3) Major (1.1.0 → 2.0.0) - Breaking changes"
73
+ echo ""
74
+ read -p "Digite o número da opção (1-3): " version_type
75
+
76
+ case $version_type in
77
+ 1)
78
+ print_message "Criando versão patch..."
79
+ pnpm run version:patch
80
+ ;;
81
+ 2)
82
+ print_message "Criando versão minor..."
83
+ pnpm run version:minor
84
+ ;;
85
+ 3)
86
+ print_warning "Você está criando uma versão major. Isso pode quebrar compatibilidade!"
87
+ read -p "Tem certeza? (y/N): " confirm
88
+ if [[ $confirm =~ ^[Yy]$ ]]; then
89
+ print_message "Criando versão major..."
90
+ pnpm run version:major
91
+ else
92
+ print_message "Release cancelado"
93
+ exit 0
94
+ fi
95
+ ;;
96
+ *)
97
+ print_error "Opção inválida"
98
+ exit 1
99
+ ;;
100
+ esac
101
+
102
+ # Obter a nova versão
103
+ NEW_VERSION=$(node -p "require('./package.json').version")
104
+ TAG_NAME="v$NEW_VERSION"
105
+
106
+ print_message "Nova versão: $NEW_VERSION"
107
+ print_message "Tag: $TAG_NAME"
108
+
109
+ # Perguntar se quer fazer push da tag
110
+ read -p "Fazer push da tag para o GitHub? (y/N): " push_tag
111
+
112
+ if [[ $push_tag =~ ^[Yy]$ ]]; then
113
+ print_message "Fazendo push da tag..."
114
+ git push origin --tags
115
+
116
+ print_message "✅ Release iniciado!"
117
+ print_message "O GitHub Actions irá publicar automaticamente no npm"
118
+ print_message "Acompanhe o progresso em: https://github.com/starbem/star-db-query-builder/actions"
119
+ else
120
+ print_message "Tag criada localmente. Execute 'git push origin --tags' quando estiver pronto"
121
+ fi
122
+
123
+ print_message "Processo concluído!"