tina4ruby 3.11.15 → 3.11.17
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +80 -80
- data/LICENSE.txt +21 -21
- data/README.md +137 -137
- data/exe/tina4ruby +5 -5
- data/lib/tina4/ai.rb +696 -696
- data/lib/tina4/api.rb +189 -189
- data/lib/tina4/auth.rb +305 -305
- data/lib/tina4/auto_crud.rb +244 -244
- data/lib/tina4/cache.rb +154 -154
- data/lib/tina4/cli.rb +1449 -1449
- data/lib/tina4/constants.rb +46 -46
- data/lib/tina4/container.rb +74 -74
- data/lib/tina4/cors.rb +74 -74
- data/lib/tina4/crud.rb +692 -692
- data/lib/tina4/database/sqlite3_adapter.rb +165 -165
- data/lib/tina4/database.rb +625 -625
- data/lib/tina4/database_result.rb +208 -208
- data/lib/tina4/debug.rb +8 -8
- data/lib/tina4/dev.rb +14 -14
- data/lib/tina4/dev_admin.rb +1291 -935
- data/lib/tina4/dev_mailbox.rb +191 -191
- data/lib/tina4/drivers/firebird_driver.rb +124 -124
- data/lib/tina4/drivers/mongodb_driver.rb +561 -561
- data/lib/tina4/drivers/mssql_driver.rb +112 -112
- data/lib/tina4/drivers/mysql_driver.rb +90 -90
- data/lib/tina4/drivers/odbc_driver.rb +191 -191
- data/lib/tina4/drivers/postgres_driver.rb +116 -116
- data/lib/tina4/drivers/sqlite_driver.rb +122 -122
- data/lib/tina4/env.rb +95 -95
- data/lib/tina4/error_overlay.rb +252 -252
- data/lib/tina4/events.rb +109 -109
- data/lib/tina4/field_types.rb +154 -154
- data/lib/tina4/frond.rb +2087 -2025
- data/lib/tina4/gallery/auth/meta.json +1 -1
- data/lib/tina4/gallery/auth/src/routes/api/gallery_auth.rb +114 -114
- data/lib/tina4/gallery/database/meta.json +1 -1
- data/lib/tina4/gallery/database/src/routes/api/gallery_db.rb +43 -43
- data/lib/tina4/gallery/error-overlay/meta.json +1 -1
- data/lib/tina4/gallery/error-overlay/src/routes/api/gallery_crash.rb +17 -17
- data/lib/tina4/gallery/orm/meta.json +1 -1
- data/lib/tina4/gallery/orm/src/routes/api/gallery_products.rb +16 -16
- data/lib/tina4/gallery/queue/meta.json +1 -1
- data/lib/tina4/gallery/queue/src/routes/api/gallery_queue.rb +325 -325
- data/lib/tina4/gallery/rest-api/meta.json +1 -1
- data/lib/tina4/gallery/rest-api/src/routes/api/gallery_hello.rb +14 -14
- data/lib/tina4/gallery/templates/meta.json +1 -1
- data/lib/tina4/gallery/templates/src/routes/gallery_page.rb +12 -12
- data/lib/tina4/gallery/templates/src/templates/gallery_page.twig +257 -257
- data/lib/tina4/graphql.rb +966 -966
- data/lib/tina4/health.rb +39 -39
- data/lib/tina4/html_element.rb +170 -170
- data/lib/tina4/job.rb +80 -80
- data/lib/tina4/localization.rb +168 -168
- data/lib/tina4/log.rb +203 -203
- data/lib/tina4/mcp.rb +871 -696
- data/lib/tina4/messenger.rb +587 -587
- data/lib/tina4/metrics.rb +793 -793
- data/lib/tina4/middleware.rb +445 -445
- data/lib/tina4/migration.rb +451 -451
- data/lib/tina4/orm.rb +790 -790
- data/lib/tina4/plan.rb +471 -0
- data/lib/tina4/project_index.rb +366 -0
- data/lib/tina4/public/css/tina4.css +2463 -2463
- data/lib/tina4/public/css/tina4.min.css +1 -1
- data/lib/tina4/public/images/logo.svg +5 -5
- data/lib/tina4/public/js/frond.min.js +2 -2
- data/lib/tina4/public/js/tina4-dev-admin.js +1264 -565
- data/lib/tina4/public/js/tina4-dev-admin.min.js +1264 -480
- data/lib/tina4/public/js/tina4.min.js +92 -92
- data/lib/tina4/public/js/tina4js.min.js +48 -48
- data/lib/tina4/public/swagger/index.html +90 -90
- data/lib/tina4/public/swagger/oauth2-redirect.html +63 -63
- data/lib/tina4/query_builder.rb +380 -380
- data/lib/tina4/queue.rb +366 -366
- data/lib/tina4/queue_backends/kafka_backend.rb +80 -80
- data/lib/tina4/queue_backends/lite_backend.rb +298 -298
- data/lib/tina4/queue_backends/mongo_backend.rb +126 -126
- data/lib/tina4/queue_backends/rabbitmq_backend.rb +73 -73
- data/lib/tina4/rack_app.rb +817 -817
- data/lib/tina4/rate_limiter.rb +130 -130
- data/lib/tina4/request.rb +268 -268
- data/lib/tina4/response.rb +346 -346
- data/lib/tina4/response_cache.rb +551 -551
- data/lib/tina4/router.rb +406 -406
- data/lib/tina4/scss/tina4css/_alerts.scss +34 -34
- data/lib/tina4/scss/tina4css/_badges.scss +22 -22
- data/lib/tina4/scss/tina4css/_buttons.scss +69 -69
- data/lib/tina4/scss/tina4css/_cards.scss +49 -49
- data/lib/tina4/scss/tina4css/_forms.scss +156 -156
- data/lib/tina4/scss/tina4css/_grid.scss +81 -81
- data/lib/tina4/scss/tina4css/_modals.scss +84 -84
- data/lib/tina4/scss/tina4css/_nav.scss +149 -149
- data/lib/tina4/scss/tina4css/_reset.scss +94 -94
- data/lib/tina4/scss/tina4css/_tables.scss +54 -54
- data/lib/tina4/scss/tina4css/_typography.scss +55 -55
- data/lib/tina4/scss/tina4css/_utilities.scss +197 -197
- data/lib/tina4/scss/tina4css/_variables.scss +117 -117
- data/lib/tina4/scss/tina4css/base.scss +1 -1
- data/lib/tina4/scss/tina4css/colors.scss +48 -48
- data/lib/tina4/scss/tina4css/tina4.scss +17 -17
- data/lib/tina4/scss_compiler.rb +178 -178
- data/lib/tina4/seeder.rb +567 -567
- data/lib/tina4/service_runner.rb +303 -303
- data/lib/tina4/session.rb +297 -297
- data/lib/tina4/session_handlers/database_handler.rb +72 -72
- data/lib/tina4/session_handlers/file_handler.rb +67 -67
- data/lib/tina4/session_handlers/mongo_handler.rb +49 -49
- data/lib/tina4/session_handlers/redis_handler.rb +43 -43
- data/lib/tina4/session_handlers/valkey_handler.rb +43 -43
- data/lib/tina4/shutdown.rb +84 -84
- data/lib/tina4/sql_translation.rb +158 -158
- data/lib/tina4/swagger.rb +124 -124
- data/lib/tina4/template.rb +894 -894
- data/lib/tina4/templates/base.twig +26 -26
- data/lib/tina4/templates/errors/302.twig +14 -14
- data/lib/tina4/templates/errors/401.twig +9 -9
- data/lib/tina4/templates/errors/403.twig +29 -29
- data/lib/tina4/templates/errors/404.twig +29 -29
- data/lib/tina4/templates/errors/500.twig +38 -38
- data/lib/tina4/templates/errors/502.twig +9 -9
- data/lib/tina4/templates/errors/503.twig +12 -12
- data/lib/tina4/templates/errors/base.twig +37 -37
- data/lib/tina4/test_client.rb +159 -159
- data/lib/tina4/testing.rb +340 -340
- data/lib/tina4/validator.rb +174 -174
- data/lib/tina4/version.rb +1 -1
- data/lib/tina4/webserver.rb +312 -312
- data/lib/tina4/websocket.rb +343 -343
- data/lib/tina4/websocket_backplane.rb +190 -190
- data/lib/tina4/wsdl.rb +564 -564
- data/lib/tina4.rb +460 -458
- data/lib/tina4ruby.rb +4 -4
- metadata +5 -3
data/lib/tina4.rb
CHANGED
|
@@ -1,458 +1,460 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# ── Fast JSON: use oj if available, fall back to stdlib json ──────────
|
|
4
|
-
begin
|
|
5
|
-
require "oj"
|
|
6
|
-
Oj.default_options = { mode: :compat, symbol_keys: false }
|
|
7
|
-
rescue LoadError
|
|
8
|
-
# oj not installed — stdlib json is fine
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# ── Core (always loaded) ──────────────────────────────────────────────
|
|
12
|
-
require_relative "tina4/version"
|
|
13
|
-
require_relative "tina4/constants"
|
|
14
|
-
require_relative "tina4/log"
|
|
15
|
-
require_relative "tina4/debug" # backward compat alias
|
|
16
|
-
require_relative "tina4/env"
|
|
17
|
-
require_relative "tina4/router"
|
|
18
|
-
require_relative "tina4/request"
|
|
19
|
-
require_relative "tina4/response"
|
|
20
|
-
require_relative "tina4/rack_app"
|
|
21
|
-
require_relative "tina4/database"
|
|
22
|
-
require_relative "tina4/database_result"
|
|
23
|
-
require_relative "tina4/field_types"
|
|
24
|
-
require_relative "tina4/orm"
|
|
25
|
-
require_relative "tina4/query_builder"
|
|
26
|
-
require_relative "tina4/migration"
|
|
27
|
-
require_relative "tina4/auto_crud"
|
|
28
|
-
require_relative "tina4/database/sqlite3_adapter"
|
|
29
|
-
require_relative "tina4/template"
|
|
30
|
-
require_relative "tina4/frond"
|
|
31
|
-
require_relative "tina4/auth"
|
|
32
|
-
require_relative "tina4/session"
|
|
33
|
-
require_relative "tina4/middleware"
|
|
34
|
-
require_relative "tina4/cors"
|
|
35
|
-
require_relative "tina4/rate_limiter"
|
|
36
|
-
require_relative "tina4/health"
|
|
37
|
-
require_relative "tina4/shutdown"
|
|
38
|
-
require_relative "tina4/localization"
|
|
39
|
-
require_relative "tina4/container"
|
|
40
|
-
require_relative "tina4/queue"
|
|
41
|
-
require_relative "tina4/service_runner"
|
|
42
|
-
require_relative "tina4/events"
|
|
43
|
-
require_relative "tina4/
|
|
44
|
-
require_relative "tina4/
|
|
45
|
-
require_relative "tina4/
|
|
46
|
-
require_relative "tina4/
|
|
47
|
-
require_relative "tina4/
|
|
48
|
-
require_relative "tina4/
|
|
49
|
-
require_relative "tina4/
|
|
50
|
-
require_relative "tina4/
|
|
51
|
-
require_relative "tina4/
|
|
52
|
-
require_relative "tina4/
|
|
53
|
-
require_relative "tina4/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
autoload :
|
|
61
|
-
autoload :
|
|
62
|
-
autoload :
|
|
63
|
-
autoload :
|
|
64
|
-
autoload :
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
autoload :
|
|
72
|
-
autoload :
|
|
73
|
-
autoload :
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
autoload :
|
|
81
|
-
autoload :
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
autoload :
|
|
91
|
-
autoload :
|
|
92
|
-
autoload :
|
|
93
|
-
autoload :
|
|
94
|
-
autoload :
|
|
95
|
-
autoload :
|
|
96
|
-
autoload :
|
|
97
|
-
autoload :
|
|
98
|
-
autoload :
|
|
99
|
-
autoload :
|
|
100
|
-
autoload :
|
|
101
|
-
autoload :
|
|
102
|
-
autoload :
|
|
103
|
-
autoload :
|
|
104
|
-
autoload :
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/
|
|
111
|
-
/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
server_name = "
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
puts "
|
|
143
|
-
puts ""
|
|
144
|
-
puts "
|
|
145
|
-
puts "
|
|
146
|
-
puts "
|
|
147
|
-
puts "
|
|
148
|
-
puts ""
|
|
149
|
-
|
|
150
|
-
puts "
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
#
|
|
187
|
-
#
|
|
188
|
-
#
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
ENV["
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
require "puma
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
user_config.
|
|
258
|
-
user_config.
|
|
259
|
-
user_config.
|
|
260
|
-
user_config.
|
|
261
|
-
user_config.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
#
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
#
|
|
404
|
-
#
|
|
405
|
-
#
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
when
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
Tina4::Template.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
Tina4::Log.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
Dir.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
Tina4::Log.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ── Fast JSON: use oj if available, fall back to stdlib json ──────────
|
|
4
|
+
begin
|
|
5
|
+
require "oj"
|
|
6
|
+
Oj.default_options = { mode: :compat, symbol_keys: false }
|
|
7
|
+
rescue LoadError
|
|
8
|
+
# oj not installed — stdlib json is fine
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# ── Core (always loaded) ──────────────────────────────────────────────
|
|
12
|
+
require_relative "tina4/version"
|
|
13
|
+
require_relative "tina4/constants"
|
|
14
|
+
require_relative "tina4/log"
|
|
15
|
+
require_relative "tina4/debug" # backward compat alias
|
|
16
|
+
require_relative "tina4/env"
|
|
17
|
+
require_relative "tina4/router"
|
|
18
|
+
require_relative "tina4/request"
|
|
19
|
+
require_relative "tina4/response"
|
|
20
|
+
require_relative "tina4/rack_app"
|
|
21
|
+
require_relative "tina4/database"
|
|
22
|
+
require_relative "tina4/database_result"
|
|
23
|
+
require_relative "tina4/field_types"
|
|
24
|
+
require_relative "tina4/orm"
|
|
25
|
+
require_relative "tina4/query_builder"
|
|
26
|
+
require_relative "tina4/migration"
|
|
27
|
+
require_relative "tina4/auto_crud"
|
|
28
|
+
require_relative "tina4/database/sqlite3_adapter"
|
|
29
|
+
require_relative "tina4/template"
|
|
30
|
+
require_relative "tina4/frond"
|
|
31
|
+
require_relative "tina4/auth"
|
|
32
|
+
require_relative "tina4/session"
|
|
33
|
+
require_relative "tina4/middleware"
|
|
34
|
+
require_relative "tina4/cors"
|
|
35
|
+
require_relative "tina4/rate_limiter"
|
|
36
|
+
require_relative "tina4/health"
|
|
37
|
+
require_relative "tina4/shutdown"
|
|
38
|
+
require_relative "tina4/localization"
|
|
39
|
+
require_relative "tina4/container"
|
|
40
|
+
require_relative "tina4/queue"
|
|
41
|
+
require_relative "tina4/service_runner"
|
|
42
|
+
require_relative "tina4/events"
|
|
43
|
+
require_relative "tina4/plan"
|
|
44
|
+
require_relative "tina4/project_index"
|
|
45
|
+
require_relative "tina4/dev_admin"
|
|
46
|
+
require_relative "tina4/messenger"
|
|
47
|
+
require_relative "tina4/dev_mailbox"
|
|
48
|
+
require_relative "tina4/ai"
|
|
49
|
+
require_relative "tina4/cache"
|
|
50
|
+
require_relative "tina4/sql_translation"
|
|
51
|
+
require_relative "tina4/response_cache"
|
|
52
|
+
require_relative "tina4/html_element"
|
|
53
|
+
require_relative "tina4/error_overlay"
|
|
54
|
+
require_relative "tina4/test_client"
|
|
55
|
+
require_relative "tina4/mcp"
|
|
56
|
+
|
|
57
|
+
module Tina4
|
|
58
|
+
# ── Lazy-loaded: database drivers ─────────────────────────────────────
|
|
59
|
+
module Drivers
|
|
60
|
+
autoload :SqliteDriver, File.expand_path("tina4/drivers/sqlite_driver", __dir__)
|
|
61
|
+
autoload :PostgresDriver, File.expand_path("tina4/drivers/postgres_driver", __dir__)
|
|
62
|
+
autoload :MysqlDriver, File.expand_path("tina4/drivers/mysql_driver", __dir__)
|
|
63
|
+
autoload :MssqlDriver, File.expand_path("tina4/drivers/mssql_driver", __dir__)
|
|
64
|
+
autoload :FirebirdDriver, File.expand_path("tina4/drivers/firebird_driver", __dir__)
|
|
65
|
+
autoload :MongodbDriver, File.expand_path("tina4/drivers/mongodb_driver", __dir__)
|
|
66
|
+
autoload :OdbcDriver, File.expand_path("tina4/drivers/odbc_driver", __dir__)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# ── Lazy-loaded: session handlers ─────────────────────────────────────
|
|
70
|
+
module SessionHandlers
|
|
71
|
+
autoload :FileHandler, File.expand_path("tina4/session_handlers/file_handler", __dir__)
|
|
72
|
+
autoload :RedisHandler, File.expand_path("tina4/session_handlers/redis_handler", __dir__)
|
|
73
|
+
autoload :MongoHandler, File.expand_path("tina4/session_handlers/mongo_handler", __dir__)
|
|
74
|
+
autoload :ValkeyHandler, File.expand_path("tina4/session_handlers/valkey_handler", __dir__)
|
|
75
|
+
autoload :DatabaseHandler, File.expand_path("tina4/session_handlers/database_handler", __dir__)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# ── Lazy-loaded: queue backends ───────────────────────────────────────
|
|
79
|
+
module QueueBackends
|
|
80
|
+
autoload :LiteBackend, File.expand_path("tina4/queue_backends/lite_backend", __dir__)
|
|
81
|
+
autoload :RabbitmqBackend, File.expand_path("tina4/queue_backends/rabbitmq_backend", __dir__)
|
|
82
|
+
autoload :KafkaBackend, File.expand_path("tina4/queue_backends/kafka_backend", __dir__)
|
|
83
|
+
autoload :MongoBackend, File.expand_path("tina4/queue_backends/mongo_backend", __dir__)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# ── Lazy-loaded: web server ───────────────────────────────────────────
|
|
87
|
+
autoload :WebServer, File.expand_path("tina4/webserver", __dir__)
|
|
88
|
+
|
|
89
|
+
# ── Lazy-loaded: optional modules ─────────────────────────────────────
|
|
90
|
+
autoload :Swagger, File.expand_path("tina4/swagger", __dir__)
|
|
91
|
+
autoload :Crud, File.expand_path("tina4/crud", __dir__)
|
|
92
|
+
autoload :CRUD, File.expand_path("tina4/crud", __dir__)
|
|
93
|
+
autoload :API, File.expand_path("tina4/api", __dir__)
|
|
94
|
+
autoload :APIResponse, File.expand_path("tina4/api", __dir__)
|
|
95
|
+
autoload :GraphQLType, File.expand_path("tina4/graphql", __dir__)
|
|
96
|
+
autoload :GraphQLSchema, File.expand_path("tina4/graphql", __dir__)
|
|
97
|
+
autoload :GraphQLParser, File.expand_path("tina4/graphql", __dir__)
|
|
98
|
+
autoload :GraphQLExecutor, File.expand_path("tina4/graphql", __dir__)
|
|
99
|
+
autoload :GraphQLError, File.expand_path("tina4/graphql", __dir__)
|
|
100
|
+
autoload :GraphQL, File.expand_path("tina4/graphql", __dir__)
|
|
101
|
+
autoload :WebSocket, File.expand_path("tina4/websocket", __dir__)
|
|
102
|
+
autoload :WebSocketConnection, File.expand_path("tina4/websocket", __dir__)
|
|
103
|
+
autoload :Testing, File.expand_path("tina4/testing", __dir__)
|
|
104
|
+
autoload :ScssCompiler, File.expand_path("tina4/scss_compiler", __dir__)
|
|
105
|
+
autoload :FakeData, File.expand_path("tina4/seeder", __dir__)
|
|
106
|
+
autoload :WSDL, File.expand_path("tina4/wsdl", __dir__)
|
|
107
|
+
BANNER = <<~'BANNER'
|
|
108
|
+
|
|
109
|
+
______ _ __ __
|
|
110
|
+
/_ __/(_)___ ____ _/ // /
|
|
111
|
+
/ / / / __ \/ __ `/ // /_
|
|
112
|
+
/ / / / / / / /_/ /__ __/
|
|
113
|
+
/_/ /_/_/ /_/\__,_/ /_/
|
|
114
|
+
BANNER
|
|
115
|
+
|
|
116
|
+
class << self
|
|
117
|
+
attr_accessor :root_dir, :database
|
|
118
|
+
|
|
119
|
+
def print_banner(host: "0.0.0.0", port: 7147, server_name: nil)
|
|
120
|
+
is_tty = $stdout.respond_to?(:isatty) && $stdout.isatty
|
|
121
|
+
color = is_tty ? "\e[31m" : ""
|
|
122
|
+
reset = is_tty ? "\e[0m" : ""
|
|
123
|
+
|
|
124
|
+
is_debug = Tina4::Env.is_truthy(ENV["TINA4_DEBUG"])
|
|
125
|
+
log_level = (ENV["TINA4_LOG_LEVEL"] || "[TINA4_LOG_ALL]").upcase
|
|
126
|
+
display = (host == "0.0.0.0" || host == "::") ? "localhost" : host
|
|
127
|
+
|
|
128
|
+
# Auto-detect server name if not provided
|
|
129
|
+
if server_name.nil?
|
|
130
|
+
if is_debug
|
|
131
|
+
server_name = "WEBrick"
|
|
132
|
+
else
|
|
133
|
+
begin
|
|
134
|
+
require "puma"
|
|
135
|
+
server_name = "puma"
|
|
136
|
+
rescue LoadError
|
|
137
|
+
server_name = "WEBrick"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
puts "#{color}#{BANNER}#{reset}"
|
|
143
|
+
puts " TINA4 — The Intelligent Native Application 4ramework"
|
|
144
|
+
puts " Simple. Fast. Human. | Built for AI. Built for you."
|
|
145
|
+
puts ""
|
|
146
|
+
puts " Server: http://#{display}:#{port} (#{server_name})"
|
|
147
|
+
puts " Swagger: http://localhost:#{port}/swagger"
|
|
148
|
+
puts " Dashboard: http://localhost:#{port}/__dev"
|
|
149
|
+
puts " Debug: #{is_debug ? 'ON' : 'OFF'} (Log level: #{log_level})"
|
|
150
|
+
puts ""
|
|
151
|
+
rescue
|
|
152
|
+
puts "#{color}TINA4 Ruby v#{VERSION}#{reset}"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def initialize!(root_dir = Dir.pwd)
|
|
156
|
+
@root_dir = root_dir
|
|
157
|
+
|
|
158
|
+
# Print banner
|
|
159
|
+
print_banner
|
|
160
|
+
|
|
161
|
+
# Load environment
|
|
162
|
+
Tina4::Env.load_env(root_dir)
|
|
163
|
+
|
|
164
|
+
# Setup debug logging
|
|
165
|
+
Tina4::Log.configure(root_dir)
|
|
166
|
+
Tina4::Log.info("Tina4 Ruby v#{VERSION} initializing...")
|
|
167
|
+
|
|
168
|
+
# Setup auth keys
|
|
169
|
+
Tina4::Auth.setup(root_dir)
|
|
170
|
+
|
|
171
|
+
# Load translations
|
|
172
|
+
Tina4::Localization.load(root_dir)
|
|
173
|
+
|
|
174
|
+
# Auto-wire t() into template globals if locales were loaded
|
|
175
|
+
autowire_i18n_template_global
|
|
176
|
+
|
|
177
|
+
# Connect database if configured
|
|
178
|
+
setup_database
|
|
179
|
+
|
|
180
|
+
# Auto-discover routes
|
|
181
|
+
auto_discover(root_dir)
|
|
182
|
+
|
|
183
|
+
Tina4::Log.info("Tina4 initialized successfully")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Initialize and start the web server.
|
|
187
|
+
# This is the primary entry point for app.rb files:
|
|
188
|
+
# Tina4.initialize!(__dir__)
|
|
189
|
+
# Tina4.run!
|
|
190
|
+
# Or combined: Tina4.run!(__dir__)
|
|
191
|
+
def find_available_port(start, max_tries = 10)
|
|
192
|
+
require "socket"
|
|
193
|
+
max_tries.times do |offset|
|
|
194
|
+
port = start + offset
|
|
195
|
+
begin
|
|
196
|
+
server = TCPServer.new("127.0.0.1", port)
|
|
197
|
+
server.close
|
|
198
|
+
return port
|
|
199
|
+
rescue Errno::EADDRINUSE, Errno::EACCES
|
|
200
|
+
next
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
start
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def open_browser(url)
|
|
207
|
+
require "rbconfig"
|
|
208
|
+
Thread.new do
|
|
209
|
+
sleep 2
|
|
210
|
+
case RbConfig::CONFIG["host_os"]
|
|
211
|
+
when /darwin/i then system("open", url)
|
|
212
|
+
when /mswin|mingw/i then system("start", url)
|
|
213
|
+
else system("xdg-open", url)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def run!(root_dir = nil, port: nil, host: nil, debug: nil)
|
|
219
|
+
# Handle legacy call: run!(port: 7147) where root_dir receives the hash
|
|
220
|
+
if root_dir.is_a?(Hash)
|
|
221
|
+
port ||= root_dir[:port]
|
|
222
|
+
host ||= root_dir[:host]
|
|
223
|
+
debug = root_dir[:debug] if debug.nil? && root_dir.key?(:debug)
|
|
224
|
+
root_dir = nil
|
|
225
|
+
end
|
|
226
|
+
root_dir ||= Dir.pwd
|
|
227
|
+
|
|
228
|
+
ENV["PORT"] = port.to_s if port
|
|
229
|
+
ENV["HOST"] = host.to_s if host
|
|
230
|
+
ENV["TINA4_DEBUG"] = debug.to_s unless debug.nil?
|
|
231
|
+
|
|
232
|
+
initialize!(root_dir) unless @root_dir
|
|
233
|
+
|
|
234
|
+
host = ENV.fetch("HOST", ENV.fetch("TINA4_HOST", "0.0.0.0"))
|
|
235
|
+
port = ENV.fetch("PORT", ENV.fetch("TINA4_PORT", "7147")).to_i
|
|
236
|
+
|
|
237
|
+
actual_port = find_available_port(port)
|
|
238
|
+
if actual_port != port
|
|
239
|
+
Tina4::Log.info("Port #{port} in use, using #{actual_port}")
|
|
240
|
+
port = actual_port
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
display_host = (host == "0.0.0.0" || host == "::") ? "localhost" : host
|
|
244
|
+
url = "http://#{display_host}:#{port}"
|
|
245
|
+
|
|
246
|
+
app = Tina4::RackApp.new(root_dir: root_dir)
|
|
247
|
+
is_debug = Tina4::Env.is_truthy(ENV["TINA4_DEBUG"])
|
|
248
|
+
|
|
249
|
+
# Try Puma first (production-grade), fall back to WEBrick
|
|
250
|
+
if !is_debug
|
|
251
|
+
begin
|
|
252
|
+
require "puma"
|
|
253
|
+
require "puma/configuration"
|
|
254
|
+
require "puma/launcher"
|
|
255
|
+
|
|
256
|
+
config = Puma::Configuration.new do |user_config|
|
|
257
|
+
user_config.bind "tcp://#{host}:#{port}"
|
|
258
|
+
user_config.app app
|
|
259
|
+
user_config.threads 0, 16
|
|
260
|
+
user_config.workers 0
|
|
261
|
+
user_config.environment "production"
|
|
262
|
+
user_config.log_requests false
|
|
263
|
+
user_config.quiet
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
Tina4::Log.info("Production server: puma")
|
|
267
|
+
Tina4::Shutdown.setup
|
|
268
|
+
|
|
269
|
+
open_browser(url)
|
|
270
|
+
launcher = Puma::Launcher.new(config)
|
|
271
|
+
launcher.run
|
|
272
|
+
return
|
|
273
|
+
rescue LoadError
|
|
274
|
+
# Puma not installed, fall through to WEBrick
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
Tina4::Log.info("Development server: WEBrick")
|
|
279
|
+
open_browser(url)
|
|
280
|
+
server = Tina4::WebServer.new(app, host: host, port: port)
|
|
281
|
+
server.start
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# DSL methods for route registration
|
|
285
|
+
# GET is public by default (matching tina4_python behavior)
|
|
286
|
+
# POST/PUT/PATCH/DELETE are secured by default — use auth: false to make public
|
|
287
|
+
def get(path, auth: nil, swagger_meta: {}, &block)
|
|
288
|
+
auth_handler = auth == false ? nil : auth
|
|
289
|
+
Tina4::Router.add("GET", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def post(path, auth: :default, swagger_meta: {}, &block)
|
|
293
|
+
auth_handler = resolve_auth(auth)
|
|
294
|
+
Tina4::Router.add("POST", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def put(path, auth: :default, swagger_meta: {}, &block)
|
|
298
|
+
auth_handler = resolve_auth(auth)
|
|
299
|
+
Tina4::Router.add("PUT", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def patch(path, auth: :default, swagger_meta: {}, &block)
|
|
303
|
+
auth_handler = resolve_auth(auth)
|
|
304
|
+
Tina4::Router.add("PATCH", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def delete(path, auth: :default, swagger_meta: {}, &block)
|
|
308
|
+
auth_handler = resolve_auth(auth)
|
|
309
|
+
Tina4::Router.add("DELETE", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def any(path, auth: false, swagger_meta: {}, &block)
|
|
313
|
+
auth_handler = resolve_auth(auth)
|
|
314
|
+
%w[GET POST PUT PATCH DELETE].each do |method|
|
|
315
|
+
Tina4::Router.add(method, path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def options(path, &block)
|
|
320
|
+
Tina4::Router.add("OPTIONS", path, block)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Explicit secure variants (always secured, regardless of HTTP method)
|
|
324
|
+
def secure_get(path, auth: nil, swagger_meta: {}, &block)
|
|
325
|
+
auth_handler = auth || Tina4::Auth.default_secure_auth
|
|
326
|
+
Tina4::Router.add("GET", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def secure_post(path, auth: nil, swagger_meta: {}, &block)
|
|
330
|
+
auth_handler = auth || Tina4::Auth.default_secure_auth
|
|
331
|
+
Tina4::Router.add("POST", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def secure_put(path, auth: nil, swagger_meta: {}, &block)
|
|
335
|
+
auth_handler = auth || Tina4::Auth.default_secure_auth
|
|
336
|
+
Tina4::Router.add("PUT", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def secure_patch(path, auth: nil, swagger_meta: {}, &block)
|
|
340
|
+
auth_handler = auth || Tina4::Auth.default_secure_auth
|
|
341
|
+
Tina4::Router.add("PATCH", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def secure_delete(path, auth: nil, swagger_meta: {}, &block)
|
|
345
|
+
auth_handler = auth || Tina4::Auth.default_secure_auth
|
|
346
|
+
Tina4::Router.add("DELETE", path, block, auth_handler: auth_handler, swagger_meta: swagger_meta)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Route groups
|
|
350
|
+
def group(prefix, auth: nil, &block)
|
|
351
|
+
Tina4::Router.group(prefix, auth_handler: auth, &block)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# WebSocket route registration
|
|
355
|
+
def websocket(path, &block)
|
|
356
|
+
Tina4::Router.websocket(path, &block)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Middleware hooks
|
|
360
|
+
def before(pattern = nil, &block)
|
|
361
|
+
Tina4::Middleware.before(pattern, &block)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def after(pattern = nil, &block)
|
|
365
|
+
Tina4::Middleware.after(pattern, &block)
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Template globals
|
|
369
|
+
def template_global(key, value)
|
|
370
|
+
Tina4::Template.add_global(key, value)
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# Inline test DSL
|
|
374
|
+
def describe(name, &block)
|
|
375
|
+
Tina4::Testing.describe(name, &block)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# Translation shortcut
|
|
379
|
+
def t(key, **options)
|
|
380
|
+
Tina4::Localization.t(key, **options)
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
# Service runner DSL
|
|
384
|
+
def service(name, options = {}, &block)
|
|
385
|
+
Tina4::ServiceRunner.register(name, nil, options, &block)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# DI container shortcuts
|
|
389
|
+
def register(name, instance = nil, &block)
|
|
390
|
+
Tina4::Container.register(name, instance, &block)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
def singleton(name, &block)
|
|
394
|
+
Tina4::Container.singleton(name, &block)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
def resolve(name)
|
|
398
|
+
Tina4::Container.get(name)
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
private
|
|
402
|
+
|
|
403
|
+
# Resolve auth option for route registration
|
|
404
|
+
# :default => use bearer auth (default for POST/PUT/PATCH/DELETE)
|
|
405
|
+
# false => no auth (public route)
|
|
406
|
+
# nil => no auth
|
|
407
|
+
# Proc/Lambda => custom auth handler
|
|
408
|
+
def resolve_auth(auth)
|
|
409
|
+
case auth
|
|
410
|
+
when :default
|
|
411
|
+
Tina4::Auth.default_secure_auth
|
|
412
|
+
when false, nil
|
|
413
|
+
nil
|
|
414
|
+
else
|
|
415
|
+
auth # Custom auth handler (proc/lambda)
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def autowire_i18n_template_global
|
|
420
|
+
# Only register if translations were actually loaded
|
|
421
|
+
return if Tina4::Localization.translations.empty?
|
|
422
|
+
|
|
423
|
+
# Don't overwrite a user-registered t() global
|
|
424
|
+
return if Tina4::Template.globals.key?("t")
|
|
425
|
+
|
|
426
|
+
Tina4::Template.add_global("t", ->(key, **opts) { Tina4::Localization.t(key, **opts) })
|
|
427
|
+
Tina4::Log.debug("Auto-wired i18n t() as template global")
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def setup_database
|
|
431
|
+
db_url = ENV["DATABASE_URL"] || ENV["DB_URL"]
|
|
432
|
+
if db_url && !db_url.empty?
|
|
433
|
+
begin
|
|
434
|
+
@database = Tina4::Database.new(db_url)
|
|
435
|
+
Tina4::Log.info("Database connected: #{db_url.sub(/:[^:@]+@/, ':***@')}")
|
|
436
|
+
rescue => e
|
|
437
|
+
Tina4::Log.error("Database connection failed: #{e.message}")
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def auto_discover(root_dir)
|
|
443
|
+
# src/ prefixed directories take priority over root-level ones
|
|
444
|
+
discover_dirs = %w[src/routes routes src/api api src/orm orm]
|
|
445
|
+
discover_dirs.each do |dir|
|
|
446
|
+
full_dir = File.join(root_dir, dir)
|
|
447
|
+
next unless Dir.exist?(full_dir)
|
|
448
|
+
|
|
449
|
+
Dir.glob(File.join(full_dir, "**/*.rb")).sort.each do |file|
|
|
450
|
+
begin
|
|
451
|
+
load file
|
|
452
|
+
Tina4::Log.debug("Auto-loaded: #{file}")
|
|
453
|
+
rescue => e
|
|
454
|
+
Tina4::Log.error("Failed to load #{file}: #{e.message}")
|
|
455
|
+
end
|
|
456
|
+
end
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
end
|