@gzl10/baserow 1.2.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 (58) hide show
  1. package/CHANGELOG.md +435 -0
  2. package/README.md +847 -0
  3. package/dist/index.d.ts +8749 -0
  4. package/dist/index.js +11167 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +91 -0
  7. package/src/BaserowClient.ts +501 -0
  8. package/src/ClientWithCreds.ts +545 -0
  9. package/src/ClientWithCredsWs.ts +852 -0
  10. package/src/ClientWithToken.ts +171 -0
  11. package/src/contexts/DatabaseClientContext.ts +114 -0
  12. package/src/contexts/DatabaseContext.ts +870 -0
  13. package/src/contexts/DatabaseTokenContext.ts +331 -0
  14. package/src/contexts/FieldContext.ts +399 -0
  15. package/src/contexts/RowContext.ts +99 -0
  16. package/src/contexts/TableClientContext.ts +291 -0
  17. package/src/contexts/TableContext.ts +1247 -0
  18. package/src/contexts/TableOnlyContext.ts +74 -0
  19. package/src/contexts/WorkspaceContext.ts +490 -0
  20. package/src/express/errors.ts +260 -0
  21. package/src/express/index.ts +69 -0
  22. package/src/express/middleware.ts +225 -0
  23. package/src/express/serializers.ts +314 -0
  24. package/src/index.ts +247 -0
  25. package/src/presets/performance.ts +262 -0
  26. package/src/services/AuthService.ts +472 -0
  27. package/src/services/DatabaseService.ts +246 -0
  28. package/src/services/DatabaseTokenService.ts +186 -0
  29. package/src/services/FieldService.ts +1543 -0
  30. package/src/services/RowService.ts +982 -0
  31. package/src/services/SchemaControlService.ts +420 -0
  32. package/src/services/TableService.ts +781 -0
  33. package/src/services/WorkspaceService.ts +113 -0
  34. package/src/services/core/BaseAuthClient.ts +111 -0
  35. package/src/services/core/BaseClient.ts +107 -0
  36. package/src/services/core/BaseService.ts +71 -0
  37. package/src/services/core/HttpService.ts +115 -0
  38. package/src/services/core/ValidationService.ts +149 -0
  39. package/src/types/auth.ts +177 -0
  40. package/src/types/core.ts +91 -0
  41. package/src/types/errors.ts +105 -0
  42. package/src/types/fields.ts +456 -0
  43. package/src/types/index.ts +222 -0
  44. package/src/types/requests.ts +333 -0
  45. package/src/types/responses.ts +50 -0
  46. package/src/types/schema.ts +446 -0
  47. package/src/types/tokens.ts +36 -0
  48. package/src/types.ts +11 -0
  49. package/src/utils/auth.ts +174 -0
  50. package/src/utils/axios.ts +647 -0
  51. package/src/utils/field-cache.ts +164 -0
  52. package/src/utils/httpFactory.ts +66 -0
  53. package/src/utils/jwt-decoder.ts +188 -0
  54. package/src/utils/jwtTokens.ts +50 -0
  55. package/src/utils/performance.ts +105 -0
  56. package/src/utils/prisma-mapper.ts +961 -0
  57. package/src/utils/validation.ts +463 -0
  58. package/src/validators/schema.ts +419 -0
@@ -0,0 +1,262 @@
1
+ import type { BaserowPerformanceOptions } from '../types'
2
+
3
+ /**
4
+ * Colección de configuraciones de performance predefinidas para diferentes entornos y casos de uso
5
+ *
6
+ * Facilita la selección de configuraciones apropiadas sin tener que conocer los valores específicos.
7
+ * Cada preset está optimizado para escenarios específicos de uso.
8
+ *
9
+ * @example Uso básico con presets
10
+ * ```typescript
11
+ * import { BaserowClient, PERFORMANCE_PRESETS } from '@gzl10/baserow'
12
+ *
13
+ * // Para producción (balanceado)
14
+ * const prodClient = await BaserowClient.create({
15
+ * url: 'https://baserow.example.com',
16
+ * token: process.env.TOKEN,
17
+ * performance: PERFORMANCE_PRESETS.production
18
+ * })
19
+ *
20
+ * // Para desarrollo local (más relajado)
21
+ * const devClient = await BaserowClient.create({
22
+ * url: 'http://localhost:3000',
23
+ * credentials: { email: 'dev@example.com', password: 'password' },
24
+ * performance: PERFORMANCE_PRESETS.development
25
+ * })
26
+ *
27
+ * // Para tests (conservador)
28
+ * const testClient = await BaserowClient.create({
29
+ * url: 'https://test.baserow.com',
30
+ * token: process.env.TEST_TOKEN,
31
+ * performance: PERFORMANCE_PRESETS.testing
32
+ * })
33
+ * ```
34
+ *
35
+ * @example Selección dinámica de presets
36
+ * ```typescript
37
+ * import { getPerformancePreset } from '@gzl10/baserow'
38
+ *
39
+ * const envToPreset = {
40
+ * production: 'production',
41
+ * staging: 'testing',
42
+ * development: 'development'
43
+ * } as const
44
+ *
45
+ * const preset = getPerformancePreset(envToPreset[process.env.NODE_ENV as keyof typeof envToPreset])
46
+ * ```
47
+ *
48
+ * @since 1.1.0
49
+ * @public
50
+ */
51
+ export const PERFORMANCE_PRESETS = {
52
+ /**
53
+ * Configuración balanceada para entornos de producción
54
+ *
55
+ * Optimizada para un equilibrio entre performance y estabilidad en producción.
56
+ * Valores probados para cargas de trabajo estándar.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const client = await BaserowClient.create({
61
+ * url: 'https://api.baserow.com',
62
+ * token: process.env.BASEROW_TOKEN,
63
+ * performance: PERFORMANCE_PRESETS.production
64
+ * })
65
+ * ```
66
+ *
67
+ * - **Timeout**: 30 segundos (estándar para APIs REST)
68
+ * - **Reintentos**: 3 (recuperación robusta de errores temporales)
69
+ * - **Rate limiting**: 10 req/s (equilibrio entre throughput y respeto al servidor)
70
+ * - **Casos de uso**: APIs en producción, integraciones estables, servicios críticos
71
+ *
72
+ * @since 1.1.0
73
+ */
74
+ production: {
75
+ timeout: 30000,
76
+ retries: 3,
77
+ maxRequestsPerSecond: 10,
78
+ enableRateLimiting: true
79
+ } as BaserowPerformanceOptions,
80
+
81
+ /**
82
+ * Configuración relajada para desarrollo local
83
+ *
84
+ * Diseñada para desarrollo cómodo con tiempos más generosos para debugging.
85
+ * Menos agresiva para facilitar el desarrollo y troubleshooting.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const devClient = await BaserowClient.create({
90
+ * url: 'http://localhost:3000',
91
+ * credentials: { email: 'dev@example.com', password: 'dev123' },
92
+ * performance: PERFORMANCE_PRESETS.development
93
+ * })
94
+ * ```
95
+ *
96
+ * - **Timeout**: 60 segundos (tiempo adicional para debugging y breakpoints)
97
+ * - **Reintentos**: 2 (menos agresivo durante desarrollo)
98
+ * - **Rate limiting**: 5 req/s (conservador para instancias locales)
99
+ * - **Casos de uso**: Desarrollo local, debugging, instancias de desarrollo
100
+ *
101
+ * @since 1.1.0
102
+ */
103
+ development: {
104
+ timeout: 60000,
105
+ retries: 2,
106
+ maxRequestsPerSecond: 5,
107
+ enableRateLimiting: true
108
+ } as BaserowPerformanceOptions,
109
+
110
+ /**
111
+ * Configuración conservadora para tests automatizados
112
+ *
113
+ * Optimizada para estabilidad en entornos de testing, especialmente CI/CD.
114
+ * Balanceada para ser respetuosa con recursos compartidos.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const testClient = await BaserowClient.create({
119
+ * url: 'https://test.baserow.com',
120
+ * token: process.env.BASEROW_TEST_TOKEN,
121
+ * performance: PERFORMANCE_PRESETS.testing
122
+ * })
123
+ * ```
124
+ *
125
+ * - **Timeout**: 45 segundos (tiempo adicional para CI/CD lentos)
126
+ * - **Reintentos**: 2 (equilibrio entre estabilidad y velocidad de tests)
127
+ * - **Rate limiting**: 5 req/s (respetuoso con servidores de testing compartidos)
128
+ * - **Casos de uso**: Tests automatizados, CI/CD, entornos de QA
129
+ *
130
+ * @since 1.1.0
131
+ */
132
+ testing: {
133
+ timeout: 45000,
134
+ retries: 2,
135
+ maxRequestsPerSecond: 5,
136
+ enableRateLimiting: true
137
+ } as BaserowPerformanceOptions,
138
+
139
+ /**
140
+ * Configuración de alta performance para servicios robustos
141
+ *
142
+ * Configuración agresiva diseñada para máximo throughput en infraestructura robusta.
143
+ * Requiere servidores Baserow dedicados con recursos suficientes.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const fastClient = await BaserowClient.create({
148
+ * url: 'https://dedicated.baserow.com',
149
+ * token: process.env.BASEROW_FAST_TOKEN,
150
+ * performance: PERFORMANCE_PRESETS.aggressive
151
+ * })
152
+ * ```
153
+ *
154
+ * - **Timeout**: 15 segundos (respuesta rápida esperada)
155
+ * - **Reintentos**: 5 (agresivo en recuperación de errores)
156
+ * - **Rate limiting**: 20 req/s (alta throughput)
157
+ * - **Casos de uso**: Servicios de alta demanda, servidores dedicados, APIs críticas
158
+ *
159
+ * @warning Solo usar con servidores Baserow dedicados y robustos
160
+ * @since 1.1.0
161
+ */
162
+ aggressive: {
163
+ timeout: 15000,
164
+ retries: 5,
165
+ maxRequestsPerSecond: 20,
166
+ enableRateLimiting: true
167
+ } as BaserowPerformanceOptions,
168
+
169
+ /**
170
+ * Configuración muy conservadora para recursos limitados
171
+ *
172
+ * Configuración minimalista diseñada para minimizar la carga en servidores con recursos limitados.
173
+ * Maximiza la compatibilidad y estabilidad en entornos restrictivos.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * const conservativeClient = await BaserowClient.create({
178
+ * url: 'https://shared.baserow.com',
179
+ * token: process.env.BASEROW_LIMITED_TOKEN,
180
+ * performance: PERFORMANCE_PRESETS.conservative
181
+ * })
182
+ * ```
183
+ *
184
+ * - **Timeout**: 60 segundos (paciencia con servidores lentos)
185
+ * - **Reintentos**: 1 (mínimo impacto en servidor sobrecargado)
186
+ * - **Rate limiting**: 2 req/s (muy respetuoso con recursos)
187
+ * - **Casos de uso**: Servidores compartidos, recursos limitados, procesos batch
188
+ *
189
+ * @example Casos de uso ideales
190
+ * ```typescript
191
+ * // Para servidores Baserow compartidos con muchos usuarios
192
+ * // Para instancias con recursos limitados (RAM/CPU)
193
+ * // Para procesos batch que pueden esperar
194
+ * // Para entornos con restricciones de red
195
+ * ```
196
+ *
197
+ * @since 1.1.0
198
+ */
199
+ conservative: {
200
+ timeout: 60000,
201
+ retries: 1,
202
+ maxRequestsPerSecond: 2,
203
+ enableRateLimiting: true
204
+ } as BaserowPerformanceOptions
205
+ } as const
206
+
207
+ /**
208
+ * Tipo que representa las claves disponibles en PERFORMANCE_PRESETS
209
+ *
210
+ * Útil para crear funciones que acepten solo presets válidos con autocompletado TypeScript.
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * function createClientWithPreset(preset: PerformancePresetKey) {
215
+ * return BaserowClient.create({
216
+ * url: 'https://baserow.example.com',
217
+ * token: process.env.TOKEN,
218
+ * performance: PERFORMANCE_PRESETS[preset]
219
+ * })
220
+ * }
221
+ * ```
222
+ *
223
+ * @since 1.1.0
224
+ * @public
225
+ */
226
+ export type PerformancePresetKey = keyof typeof PERFORMANCE_PRESETS
227
+
228
+ /**
229
+ * Función helper para obtener un preset por clave con validación TypeScript
230
+ *
231
+ * Proporciona una forma programática de acceder a presets con validación de tipos.
232
+ * Especialmente útil cuando la selección de preset es dinámica.
233
+ *
234
+ * @param preset - Clave del preset deseado (con autocompletado)
235
+ * @returns Configuración de performance del preset seleccionado
236
+ *
237
+ * @example Uso básico
238
+ * ```typescript
239
+ * const config = getPerformancePreset('testing')
240
+ * // Equivalente a: PERFORMANCE_PRESETS.testing
241
+ * ```
242
+ *
243
+ * @example Selección dinámica basada en entorno
244
+ * ```typescript
245
+ * const envToPreset: Record<string, PerformancePresetKey> = {
246
+ * production: 'production',
247
+ * staging: 'testing',
248
+ * development: 'development',
249
+ * test: 'testing'
250
+ * }
251
+ *
252
+ * const currentPreset = getPerformancePreset(
253
+ * envToPreset[process.env.NODE_ENV || 'development']
254
+ * )
255
+ * ```
256
+ *
257
+ * @since 1.1.0
258
+ * @public
259
+ */
260
+ export function getPerformancePreset(preset: PerformancePresetKey): BaserowPerformanceOptions {
261
+ return PERFORMANCE_PRESETS[preset]
262
+ }