tina4ruby 3.13.157 → 3.13.159
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 +39 -0
- data/lib/tina4/cli.rb +73 -18
- data/lib/tina4/database.rb +14 -2
- data/lib/tina4/database_url.rb +7 -3
- data/lib/tina4/dev_admin.rb +15 -5
- data/lib/tina4/dispatch_pipeline.rb +5 -0
- data/lib/tina4/frond.rb +80 -10
- data/lib/tina4/migration.rb +35 -0
- data/lib/tina4/public/bundled-component-provenance.json +2 -2
- data/lib/tina4/public/js/frond.js +26 -7
- data/lib/tina4/public/js/frond.min.js +1 -1
- data/lib/tina4/query_builder.rb +32 -0
- data/lib/tina4/queue_backends/kafka_backend.rb +39 -7
- data/lib/tina4/shutdown.rb +13 -0
- data/lib/tina4/tcp.rb +573 -0
- data/lib/tina4/version.rb +1 -1
- data/lib/tina4/webserver.rb +5 -0
- data/lib/tina4.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8eaa3629bc154d2dfc5419385857a0f9c3a8ede768af9363664c80448be9e19
|
|
4
|
+
data.tar.gz: aefe567a6fb3cf128750add20e11dc7683325a14b978708c57010ac5d4062bbe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2041d862f935b2a6611323856b8cfc7ed376009f1a0d7a52583f9ada47eeb4da1298e01c8ef6b48f17bbc71bd2d2c13bf4ae712d1004ba80636c772e18ab358f
|
|
7
|
+
data.tar.gz: 1d4d7726c126abab28b2f6261b1f5961249e8a2a8ca77e579941379c7943705d91094b0e2caf7701193a1f633ce7ccdd59a5287b1e1bc111ee438c70d3301cda
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,45 @@ number means the same thing everywhere.
|
|
|
6
6
|
**The authoritative release notes for every shipped version live in the documentation:**
|
|
7
7
|
https://tina4.com/ruby/36-releases
|
|
8
8
|
|
|
9
|
+
## 3.13.159 - 2026-11-06
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- `generate route/service/queue/websocket/listener` co-emitted a spec that asserted the
|
|
13
|
+
stub still raised `NotImplementedError`, so filling the handler in correctly turned the
|
|
14
|
+
project's own suite red. The generated spec now asserts the handler is wired and stays
|
|
15
|
+
green both as the scaffold stub and once implemented (#270).
|
|
16
|
+
- `tina4ruby migrate` applied a freshly scaffolded comment-only migration and recorded it
|
|
17
|
+
passed, so the real SQL written later under the same filename never ran. The runner now
|
|
18
|
+
keeps a migration pending while it still bears a `tina4:edit` marker and has no
|
|
19
|
+
executable SQL; a scaffolded `CREATE TABLE` is real DDL and still applies (#288).
|
|
20
|
+
- `migrate:create create_*_view` scaffolded a runnable `CREATE TABLE <name>_view`, so
|
|
21
|
+
`migrate` built a table and never the view. A `*_view` name now scaffolds commented
|
|
22
|
+
`CREATE VIEW` guidance that is kept pending until written (#297).
|
|
23
|
+
|
|
24
|
+
## 3.13.158 - 2026-11-05
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Raw TCP service primitive (feature 142, ADR-0102): an in-process TCP listener with
|
|
28
|
+
on_connect/on_data/on_close callbacks and a connection registry for server->device push.
|
|
29
|
+
- ORM chainable `skip()` / `offset()` / `take()` on the query builder.
|
|
30
|
+
- CodeQL static security scanning in CI.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- Kafka queue backend commits consumer-group offsets durably, per record, and consumes
|
|
34
|
+
externally-produced records (ADR-0105).
|
|
35
|
+
- Frond `date` filter accepts both strftime and Twig/PHP `date()` letters (ADR-0103); an
|
|
36
|
+
unclosed `{% block %}` now fails loud (ADR-0104); `form.collect()` sends every selected
|
|
37
|
+
option of a `<select multiple>`.
|
|
38
|
+
|
|
39
|
+
### Security
|
|
40
|
+
- frond.js no longer sends the signed-in bearer token to another origin or accepts a
|
|
41
|
+
FreshToken from one, and no longer writes the token into a `formToken` field
|
|
42
|
+
(GHSA-q2gc-fpw5-3v3c).
|
|
43
|
+
- The dev-reload WebSocket is gated on the raw socket peer, not only the Host header (GHSA-ppcq-wpj3-px7m).
|
|
44
|
+
- Resolves additional advisories shipped in this release; full notes in the documentation.
|
|
45
|
+
- A scheme-less `TINA4_DATABASE_URL` no longer logs its password (GHSA-cxqw-5cwf-wv3r).
|
|
46
|
+
- The dev file-save endpoint follows a dangling symlink before the containment check (GHSA-3p39-mqxh-gjxf).
|
|
47
|
+
|
|
9
48
|
## 3.13.157 - 2026-11-02
|
|
10
49
|
|
|
11
50
|
### Added
|
data/lib/tina4/cli.rb
CHANGED
|
@@ -2446,10 +2446,23 @@ module Tina4
|
|
|
2446
2446
|
fields = fields_override&.any? ? fields_override : parse_fields(flags["fields"])
|
|
2447
2447
|
is_create = name.start_with?("create_") || !fields_override.nil?
|
|
2448
2448
|
|
|
2449
|
+
# A `create_*_view` name is a VIEW, not a table. Emitting a runnable
|
|
2450
|
+
# `CREATE TABLE <name>_view` made migrate build a table and never the
|
|
2451
|
+
# view, silently (#297). A view needs a SELECT, so scaffold it as
|
|
2452
|
+
# commented guidance with tina4:edit markers and no executable SQL, so
|
|
2453
|
+
# startup auto-migrate keeps it pending until it is written (#288).
|
|
2454
|
+
is_view = is_create && fields_override.nil? && table.end_with?("_view")
|
|
2455
|
+
|
|
2449
2456
|
filename = "#{timestamp}_#{name}.sql"
|
|
2450
2457
|
path = File.join(dir, filename)
|
|
2451
2458
|
|
|
2452
|
-
if
|
|
2459
|
+
if is_view
|
|
2460
|
+
up_sql = "-- tina4:edit write the CREATE VIEW statement, then remove the\n" \
|
|
2461
|
+
"-- tina4:edit lines. For example:\n" \
|
|
2462
|
+
"-- CREATE VIEW #{table} AS\n" \
|
|
2463
|
+
"-- SELECT id, /* columns */ FROM source_table WHERE /* ... */;"
|
|
2464
|
+
down_sql = "DROP VIEW IF EXISTS #{table};"
|
|
2465
|
+
elsif is_create
|
|
2453
2466
|
col_lines = [" id INTEGER PRIMARY KEY AUTOINCREMENT"]
|
|
2454
2467
|
fields.each do |fname, ftype|
|
|
2455
2468
|
info = FIELD_TYPE_MAP[ftype] || FIELD_TYPE_MAP["string"]
|
|
@@ -2500,9 +2513,10 @@ module Tina4
|
|
|
2500
2513
|
File.write(down_path, down_content)
|
|
2501
2514
|
puts " Created #{down_path}"
|
|
2502
2515
|
|
|
2503
|
-
# Co-emit a real apply-UP/DOWN spec — only for CREATE migrations,
|
|
2504
|
-
# SQL is real DDL to assert against (a placeholder ALTER
|
|
2505
|
-
|
|
2516
|
+
# Co-emit a real apply-UP/DOWN spec — only for CREATE TABLE migrations,
|
|
2517
|
+
# whose UP SQL is real DDL to assert against (a placeholder ALTER, or a
|
|
2518
|
+
# VIEW stub that still needs its SELECT, has nothing concrete yet).
|
|
2519
|
+
emit_migration_test(name, table, filename, down_filename) if emit_test && is_create && !is_view
|
|
2506
2520
|
end
|
|
2507
2521
|
|
|
2508
2522
|
# ── Generator: middleware ────────────────────────────────────────────
|
|
@@ -3492,10 +3506,11 @@ module Tina4
|
|
|
3492
3506
|
# Routing spec for #{route} — no mocks, real Router.
|
|
3493
3507
|
#
|
|
3494
3508
|
# Generated with src/routes/#{route}.rb by `tina4ruby generate route
|
|
3495
|
-
# #{route}` (no --model). The handlers
|
|
3496
|
-
# you implement them
|
|
3497
|
-
# routes register on the REAL Router, and the list handler
|
|
3498
|
-
#
|
|
3509
|
+
# #{route}` (no --model). The handlers start as AI-FILL stubs that raise
|
|
3510
|
+
# until you implement them. This tests what is live on generation: all
|
|
3511
|
+
# five routes register on the REAL Router, and the list handler is wired
|
|
3512
|
+
# and callable. It stays GREEN whether the stub still raises OR you have
|
|
3513
|
+
# filled it in — implementing the handler never turns this spec red.
|
|
3499
3514
|
require "spec_helper"
|
|
3500
3515
|
|
|
3501
3516
|
RSpec.describe "#{klass} routing (real Router)" do
|
|
@@ -3510,9 +3525,20 @@ module Tina4
|
|
|
3510
3525
|
expect(paths).to include(["DELETE", "/api/#{route}/{id:int}"])
|
|
3511
3526
|
end
|
|
3512
3527
|
|
|
3513
|
-
it "the list handler is a
|
|
3528
|
+
it "the list handler is wired (green as a stub AND when filled)" do
|
|
3529
|
+
# It starts as a loud AI-FILL stub (raises NotImplementedError); once
|
|
3530
|
+
# you implement it this spec STILL passes — it asserts wiring, never
|
|
3531
|
+
# that the stub is unfinished, so doing the work never turns red.
|
|
3514
3532
|
route, = Tina4::Router.match("GET", "/api/#{route}")
|
|
3515
|
-
expect
|
|
3533
|
+
expect(route.handler).to respond_to(:call)
|
|
3534
|
+
request = Tina4::Request.new("REQUEST_METHOD" => "GET",
|
|
3535
|
+
"PATH_INFO" => "/api/#{route}", "QUERY_STRING" => "")
|
|
3536
|
+
begin
|
|
3537
|
+
result = route.handler.call(request, Tina4::Response.new)
|
|
3538
|
+
rescue NotImplementedError
|
|
3539
|
+
next # still the scaffold stub — expected until filled in
|
|
3540
|
+
end
|
|
3541
|
+
expect(result).not_to be_nil # filled in: must hand back a response
|
|
3516
3542
|
end
|
|
3517
3543
|
end
|
|
3518
3544
|
RUBY
|
|
@@ -3581,8 +3607,15 @@ module Tina4
|
|
|
3581
3607
|
expect(Tina4::ServiceRunner.list.any? { |s| s[:name] == "#{snake}" }).to be true
|
|
3582
3608
|
end
|
|
3583
3609
|
|
|
3584
|
-
it "the task is a
|
|
3585
|
-
|
|
3610
|
+
it "the task is wired (green as a stub AND when filled)" do
|
|
3611
|
+
# Starts as a loud AI-FILL stub (raises NotImplementedError); once
|
|
3612
|
+
# implemented this spec STILL passes, so doing the work never turns red.
|
|
3613
|
+
expect(defined?(#{snake}_task)).to be_truthy
|
|
3614
|
+
begin
|
|
3615
|
+
#{snake}_task(nil)
|
|
3616
|
+
rescue NotImplementedError
|
|
3617
|
+
next # still the scaffold stub — expected until filled in
|
|
3618
|
+
end
|
|
3586
3619
|
end
|
|
3587
3620
|
end
|
|
3588
3621
|
RUBY
|
|
@@ -3619,8 +3652,15 @@ module Tina4
|
|
|
3619
3652
|
expect(svc[:options][:daemon]).to be true
|
|
3620
3653
|
end
|
|
3621
3654
|
|
|
3622
|
-
it "handle_#{slug} is a
|
|
3623
|
-
|
|
3655
|
+
it "handle_#{slug} is wired (green as a stub AND when filled)" do
|
|
3656
|
+
# Starts as a loud AI-FILL stub (raises NotImplementedError); once
|
|
3657
|
+
# implemented this spec STILL passes, so doing the work never turns red.
|
|
3658
|
+
expect(defined?(handle_#{slug})).to be_truthy
|
|
3659
|
+
begin
|
|
3660
|
+
handle_#{slug}({})
|
|
3661
|
+
rescue NotImplementedError
|
|
3662
|
+
next # still the scaffold stub — expected until filled in
|
|
3663
|
+
end
|
|
3624
3664
|
end
|
|
3625
3665
|
end
|
|
3626
3666
|
RUBY
|
|
@@ -3727,8 +3767,15 @@ module Tina4
|
|
|
3727
3767
|
expect(ws_route.handler.call(nil, :close, nil)).to be_nil
|
|
3728
3768
|
end
|
|
3729
3769
|
|
|
3730
|
-
it "the :message branch is a
|
|
3731
|
-
|
|
3770
|
+
it "the :message branch is wired (green as a stub AND when filled)" do
|
|
3771
|
+
# Starts as a loud AI-FILL stub (raises NotImplementedError); once
|
|
3772
|
+
# implemented this spec STILL passes, so doing the work never turns red.
|
|
3773
|
+
expect(ws_route.handler).to respond_to(:call)
|
|
3774
|
+
begin
|
|
3775
|
+
ws_route.handler.call(nil, :message, "hi")
|
|
3776
|
+
rescue NotImplementedError
|
|
3777
|
+
next # still the scaffold stub — expected until filled in
|
|
3778
|
+
end
|
|
3732
3779
|
end
|
|
3733
3780
|
end
|
|
3734
3781
|
RUBY
|
|
@@ -3759,8 +3806,16 @@ module Tina4
|
|
|
3759
3806
|
expect(Tina4::Events.listeners("#{event}").length).to be >= 1
|
|
3760
3807
|
end
|
|
3761
3808
|
|
|
3762
|
-
it "emitting reaches the listener (
|
|
3763
|
-
|
|
3809
|
+
it "emitting reaches the listener (green as a stub AND when filled)" do
|
|
3810
|
+
# Starts as a loud AI-FILL stub (strict emit re-raises
|
|
3811
|
+
# NotImplementedError); once implemented this spec STILL passes, so
|
|
3812
|
+
# doing the work never turns red.
|
|
3813
|
+
expect(Tina4::Events.listeners("#{event}").length).to be >= 1
|
|
3814
|
+
begin
|
|
3815
|
+
Tina4::Events.emit("#{event}", { "id" => 1 }, strict: true)
|
|
3816
|
+
rescue NotImplementedError
|
|
3817
|
+
next # still the scaffold stub — expected until filled in
|
|
3818
|
+
end
|
|
3764
3819
|
end
|
|
3765
3820
|
end
|
|
3766
3821
|
RUBY
|
data/lib/tina4/database.rb
CHANGED
|
@@ -530,7 +530,7 @@ module Tina4
|
|
|
530
530
|
Tina4::Log.info("Database connected: #{@driver_name}")
|
|
531
531
|
@connect_error = nil
|
|
532
532
|
rescue => e
|
|
533
|
-
Tina4::Log.error("Database connection failed: #{e.message}")
|
|
533
|
+
Tina4::Log.error("Database connection failed: #{scrub_connection_string(e.message)}")
|
|
534
534
|
@connected = false
|
|
535
535
|
# REMEMBER the cause. Logging alone is not enough: the driver's own
|
|
536
536
|
# connection stays nil, so the next call used to die inside the driver as
|
|
@@ -582,9 +582,21 @@ module Tina4
|
|
|
582
582
|
def connect_error_message
|
|
583
583
|
target = safe_connection_target
|
|
584
584
|
"Database not connected (#{@driver_name}#{target.empty? ? '' : " -> #{target}"}): " \
|
|
585
|
-
"#{@connect_error.class}: #{@connect_error.message}"
|
|
585
|
+
"#{@connect_error.class}: #{scrub_connection_string(@connect_error.message)}"
|
|
586
586
|
end
|
|
587
587
|
|
|
588
|
+
# The driver's message with the raw connection string taken out. libpq quotes
|
|
589
|
+
# a scheme-less value whole as the host it could not resolve -
|
|
590
|
+
# could not translate host name "postgres//u:pass@h/app" to address
|
|
591
|
+
# - password included.
|
|
592
|
+
def scrub_connection_string(text)
|
|
593
|
+
raw = @connection_string.to_s
|
|
594
|
+
return text.to_s if raw.empty?
|
|
595
|
+
|
|
596
|
+
text.to_s.gsub(raw) { Tina4::DatabaseUrl.redact(raw) }
|
|
597
|
+
end
|
|
598
|
+
private :scrub_connection_string
|
|
599
|
+
|
|
588
600
|
# The connection string with any password stripped, so a raised error can name
|
|
589
601
|
# the target without leaking a credential into a log or an HTTP 500 body.
|
|
590
602
|
#
|
data/lib/tina4/database_url.rb
CHANGED
|
@@ -180,9 +180,13 @@ module Tina4
|
|
|
180
180
|
def self.scrub(text)
|
|
181
181
|
head, separator, rest = text.to_s.partition("://")
|
|
182
182
|
|
|
183
|
-
# No "://" - a bare file path,
|
|
184
|
-
#
|
|
185
|
-
|
|
183
|
+
# No "://" - a bare file path, an ODBC/keyword string, or a URL that lost
|
|
184
|
+
# its ":" or a "/" (`postgres//u:pass@host/app`). An "@" means userinfo may
|
|
185
|
+
# be in front of it, so take the credential out the same way as below.
|
|
186
|
+
if separator.empty?
|
|
187
|
+
text = text.to_s
|
|
188
|
+
return scrub_keywords(text.include?("@") ? redact_authority(text) : text)
|
|
189
|
+
end
|
|
186
190
|
|
|
187
191
|
# A head that is not a scheme is unknown text, and unknown text may BE the
|
|
188
192
|
# secret (the measured Python case was `notaurl-with-SuperSecret123`).
|
data/lib/tina4/dev_admin.rb
CHANGED
|
@@ -1727,24 +1727,34 @@ module Tina4
|
|
|
1727
1727
|
root = real_path_of(File.expand_path(Dir.pwd))
|
|
1728
1728
|
resolved = real_path_of(File.expand_path(rel_path.to_s, root))
|
|
1729
1729
|
roots = [root] + extra_roots.compact.map { |r| real_path_of(File.expand_path(r.to_s)) }
|
|
1730
|
-
unless roots.any? { |r| resolved == r || resolved.start_with?(r.chomp("/") + "/") }
|
|
1730
|
+
unless resolved && roots.any? { |r| r && (resolved == r || resolved.start_with?(r.chomp("/") + "/")) }
|
|
1731
1731
|
raise ArgumentError, "path escapes project directory"
|
|
1732
1732
|
end
|
|
1733
1733
|
resolved
|
|
1734
1734
|
end
|
|
1735
1735
|
|
|
1736
1736
|
# Real path of +path+: the deepest existing ancestor is realpath'd and the
|
|
1737
|
-
# not-yet-existing tail (a new file being saved) is appended.
|
|
1738
|
-
|
|
1737
|
+
# not-yet-existing tail (a new file being saved) is appended. A dangling
|
|
1738
|
+
# symlink is followed to the place a write through it would land, the way
|
|
1739
|
+
# McpDevTools.real_path_of does. nil when it cannot be resolved (a link
|
|
1740
|
+
# loop, or an unreadable link), so the caller refuses it.
|
|
1741
|
+
def real_path_of(path, hops = 0)
|
|
1739
1742
|
existing = path
|
|
1740
1743
|
tail = []
|
|
1741
1744
|
until File.exist?(existing) || File.symlink?(existing) || existing == File.dirname(existing)
|
|
1742
1745
|
tail.unshift(File.basename(existing))
|
|
1743
1746
|
existing = File.dirname(existing)
|
|
1744
1747
|
end
|
|
1745
|
-
File.join(File.realpath(existing), *tail)
|
|
1748
|
+
return File.join(File.realpath(existing), *tail) if File.exist?(existing)
|
|
1749
|
+
return nil if hops >= 40
|
|
1750
|
+
|
|
1751
|
+
# A dangling symlink. Its target is joined as text, not normalised, so a
|
|
1752
|
+
# ".." after a linked component is resolved the way the OS will follow it.
|
|
1753
|
+
target = File.readlink(existing)
|
|
1754
|
+
base = target.start_with?("/") ? target : File.join(File.dirname(existing), target)
|
|
1755
|
+
real_path_of(File.join(base, *tail), hops + 1)
|
|
1746
1756
|
rescue SystemCallError
|
|
1747
|
-
|
|
1757
|
+
nil
|
|
1748
1758
|
end
|
|
1749
1759
|
|
|
1750
1760
|
# Project-relative form of a resolved path, for the secret denylist.
|
|
@@ -199,6 +199,11 @@ module Tina4
|
|
|
199
199
|
if ctx.path.start_with?("/__dev") && !Tina4::DevAdmin.dev_host_allowed?(ctx.env)
|
|
200
200
|
return [403, { "content-type" => "text/plain" }, ["Forbidden: host not allowed"]]
|
|
201
201
|
end
|
|
202
|
+
# ...and only from a raw socket peer the /__dev HTTP gate would let in, so
|
|
203
|
+
# a remote caller that claims "Host: localhost" cannot open it.
|
|
204
|
+
if ctx.path.start_with?("/__dev") && !Tina4::DevAdmin.dev_peer_allowed?((ctx.env["REMOTE_ADDR"] || "").to_s)
|
|
205
|
+
return [403, { "content-type" => "text/plain" }, ["Forbidden: peer not allowed"]]
|
|
206
|
+
end
|
|
202
207
|
|
|
203
208
|
ws_result = Tina4::Router.find_ws_route(ctx.path)
|
|
204
209
|
return nil unless ws_result
|
data/lib/tina4/frond.rb
CHANGED
|
@@ -28,6 +28,13 @@ module Tina4
|
|
|
28
28
|
class SafeString < String
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
# Raised when a Frond template is malformed and cannot be rendered safely
|
|
32
|
+
# (ADR-0104) -- an unclosed {% block %} or a cut-short {% endblock % whose
|
|
33
|
+
# closing %} is missing. Failing loud surfaces the real cause to a developer
|
|
34
|
+
# (or an AI agent) instead of a page served 200 with its body quietly dropped.
|
|
35
|
+
class FrondSyntaxError < StandardError
|
|
36
|
+
end
|
|
37
|
+
|
|
31
38
|
class Frond
|
|
32
39
|
# -- Class-level registries ------------------------------------------------
|
|
33
40
|
# Persist globals, filters, and tests across hot-reloads and across module
|
|
@@ -569,6 +576,62 @@ module Tina4
|
|
|
569
576
|
@allowed_tags.include?(tag)
|
|
570
577
|
end
|
|
571
578
|
|
|
579
|
+
PHP_MONTHS = %w[January February March April May June July August September October November December].freeze
|
|
580
|
+
# cwday indexing: Monday == 1 .. Sunday == 7, so PHP_DAYS[cwday - 1].
|
|
581
|
+
PHP_DAYS = %w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday].freeze
|
|
582
|
+
|
|
583
|
+
# Format a date/time with Twig/PHP date() letters (English names) — ADR-0103.
|
|
584
|
+
#
|
|
585
|
+
# Letters are mapped character by character; a backslash escapes the next
|
|
586
|
+
# character, and any unmapped character is emitted literally (PHP's rule).
|
|
587
|
+
# English month/day names are hardcoded so the output matches every other
|
|
588
|
+
# Tina4 framework regardless of the host locale.
|
|
589
|
+
def self.php_date(dt, fmt)
|
|
590
|
+
hour = dt.respond_to?(:hour) ? dt.hour : 0
|
|
591
|
+
minute = dt.respond_to?(:min) ? dt.min : 0
|
|
592
|
+
second = dt.respond_to?(:sec) ? dt.sec : 0
|
|
593
|
+
h12 = hour % 12
|
|
594
|
+
h12 = 12 if h12.zero?
|
|
595
|
+
cwday = dt.cwday # 1 == Monday .. 7 == Sunday
|
|
596
|
+
wday = dt.wday # 0 == Sunday .. 6 == Saturday
|
|
597
|
+
out = +""
|
|
598
|
+
i = 0
|
|
599
|
+
n = fmt.length
|
|
600
|
+
while i < n
|
|
601
|
+
c = fmt[i]
|
|
602
|
+
if c == "\\" && i + 1 < n
|
|
603
|
+
out << fmt[i + 1]
|
|
604
|
+
i += 2
|
|
605
|
+
next
|
|
606
|
+
end
|
|
607
|
+
out << case c
|
|
608
|
+
when "Y" then format("%04d", dt.year)
|
|
609
|
+
when "y" then format("%02d", dt.year % 100)
|
|
610
|
+
when "m" then format("%02d", dt.month)
|
|
611
|
+
when "n" then dt.month.to_s
|
|
612
|
+
when "d" then format("%02d", dt.day)
|
|
613
|
+
when "j" then dt.day.to_s
|
|
614
|
+
when "H" then format("%02d", hour)
|
|
615
|
+
when "G" then hour.to_s
|
|
616
|
+
when "h" then format("%02d", h12)
|
|
617
|
+
when "g" then h12.to_s
|
|
618
|
+
when "i" then format("%02d", minute)
|
|
619
|
+
when "s" then format("%02d", second)
|
|
620
|
+
when "A" then hour < 12 ? "AM" : "PM"
|
|
621
|
+
when "a" then hour < 12 ? "am" : "pm"
|
|
622
|
+
when "D" then PHP_DAYS[cwday - 1][0, 3]
|
|
623
|
+
when "l" then PHP_DAYS[cwday - 1]
|
|
624
|
+
when "M" then PHP_MONTHS[dt.month - 1][0, 3]
|
|
625
|
+
when "F" then PHP_MONTHS[dt.month - 1]
|
|
626
|
+
when "N" then cwday.to_s
|
|
627
|
+
when "w" then wday.to_s
|
|
628
|
+
else c
|
|
629
|
+
end
|
|
630
|
+
i += 1
|
|
631
|
+
end
|
|
632
|
+
out
|
|
633
|
+
end
|
|
634
|
+
|
|
572
635
|
# Utility: HTML escape
|
|
573
636
|
def self.escape_html(str)
|
|
574
637
|
str.to_s.gsub(HTML_ESCAPE_RE, HTML_ESCAPE_MAP)
|
|
@@ -989,7 +1052,14 @@ module Tina4
|
|
|
989
1052
|
end
|
|
990
1053
|
end
|
|
991
1054
|
|
|
992
|
-
|
|
1055
|
+
unless matched
|
|
1056
|
+
# Unclosed {% block %} (or a cut-short {% endblock % whose %} is
|
|
1057
|
+
# missing, so the close regex never matches) -- fail loud
|
|
1058
|
+
# (tina4#286/#290) rather than silently dropping the body. Still
|
|
1059
|
+
# bounded: we raise, we never loop (tina4#271).
|
|
1060
|
+
raise FrondSyntaxError,
|
|
1061
|
+
"{% block #{name} %} is never closed (missing or malformed {% endblock %})"
|
|
1062
|
+
end
|
|
993
1063
|
end
|
|
994
1064
|
|
|
995
1065
|
blocks
|
|
@@ -1061,12 +1131,10 @@ module Tina4
|
|
|
1061
1131
|
end
|
|
1062
1132
|
|
|
1063
1133
|
if close_match.nil?
|
|
1064
|
-
#
|
|
1065
|
-
#
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
pos = len
|
|
1069
|
-
break
|
|
1134
|
+
# Unclosed {% block %} -- fail loud (tina4#286/#290), matching
|
|
1135
|
+
# extract_blocks, rather than silently keeping the rest verbatim.
|
|
1136
|
+
raise FrondSyntaxError,
|
|
1137
|
+
"{% block #{name} %} is never closed (missing or malformed {% endblock %})"
|
|
1070
1138
|
end
|
|
1071
1139
|
|
|
1072
1140
|
parent_content = source[content_start...close_match.begin(0)]
|
|
@@ -3195,12 +3263,14 @@ module Tina4
|
|
|
3195
3263
|
begin
|
|
3196
3264
|
if v.is_a?(String)
|
|
3197
3265
|
dt = DateTime.parse(v)
|
|
3198
|
-
dt.strftime(fmt)
|
|
3199
3266
|
elsif v.respond_to?(:strftime)
|
|
3200
|
-
v
|
|
3267
|
+
dt = v
|
|
3201
3268
|
else
|
|
3202
|
-
v.to_s
|
|
3269
|
+
return v.to_s
|
|
3203
3270
|
end
|
|
3271
|
+
# A strftime-style format (any with %) stays strftime — back-compatible;
|
|
3272
|
+
# any other format is Twig/PHP date() letters (ADR-0103).
|
|
3273
|
+
fmt.include?("%") ? dt.strftime(fmt) : Frond.php_date(dt, fmt)
|
|
3204
3274
|
rescue
|
|
3205
3275
|
v.to_s
|
|
3206
3276
|
end
|
data/lib/tina4/migration.rb
CHANGED
|
@@ -199,6 +199,23 @@ module Tina4
|
|
|
199
199
|
batch = next_batch_number
|
|
200
200
|
results = []
|
|
201
201
|
pending.each do |file|
|
|
202
|
+
# An empty, unedited scaffold migration — one that still bears a
|
|
203
|
+
# tina4:edit marker AND has no executable statement (the comment-only
|
|
204
|
+
# ALTER stub from a non-create migrate:create, or the view stub) — is
|
|
205
|
+
# unfinished. Applying it (and recording it passed) runs nothing and
|
|
206
|
+
# leaves the real SQL, written later under the same filename, never
|
|
207
|
+
# applied, with migrate reporting nothing pending (#288, #297). Keep it
|
|
208
|
+
# pending until written. A scaffolded CREATE TABLE carries the same hint
|
|
209
|
+
# but IS real DDL, so it applies — generate-model -> migrate is untouched.
|
|
210
|
+
if unapplied_scaffold?(file)
|
|
211
|
+
Tina4::Log.warning(
|
|
212
|
+
"Migration #{File.basename(file)} is still an unedited scaffold " \
|
|
213
|
+
"(a 'tina4:edit' placeholder with no SQL yet) — skipped and kept " \
|
|
214
|
+
"pending. Write the migration and remove the tina4:edit line(s), " \
|
|
215
|
+
"then run migrate again."
|
|
216
|
+
)
|
|
217
|
+
next
|
|
218
|
+
end
|
|
202
219
|
result = run_migration(file, batch)
|
|
203
220
|
results << result
|
|
204
221
|
# Stop on failure
|
|
@@ -207,6 +224,24 @@ module Tina4
|
|
|
207
224
|
results
|
|
208
225
|
end
|
|
209
226
|
|
|
227
|
+
# True if a migration file is still the unedited scaffold placeholder: it
|
|
228
|
+
# bears a tina4:edit marker AND (for a .sql file) has no executable
|
|
229
|
+
# statement. A .rb scaffold qualifies on the marker alone.
|
|
230
|
+
def unapplied_scaffold?(file)
|
|
231
|
+
raw = File.read(file)
|
|
232
|
+
return false unless raw =~ %r{(?:#|//|--|/\*|\{#)\s*tina4:edit\b}i
|
|
233
|
+
return true if file.end_with?(".rb")
|
|
234
|
+
!executable_sql?(raw)
|
|
235
|
+
rescue SystemCallError
|
|
236
|
+
false
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# True if any executable statement remains once SQL comments are stripped.
|
|
240
|
+
def executable_sql?(sql)
|
|
241
|
+
body = sql.gsub(%r{/\*.*?\*/}m, "").gsub(/--[^\n]*/, "")
|
|
242
|
+
!body.gsub(/[;\s]/, "").empty?
|
|
243
|
+
end
|
|
244
|
+
|
|
210
245
|
# A stable signed-64-bit key for PostgreSQL's pg_advisory_lock, derived from
|
|
211
246
|
# the lock name so it cannot collide with an application's own advisory-lock
|
|
212
247
|
# keys. It is a constant (not user input), so inlining it in the SQL is
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
{
|
|
10
10
|
"path": "js/frond.min.js",
|
|
11
11
|
"component": "tina4-css",
|
|
12
|
-
"sha256": "
|
|
12
|
+
"sha256": "1c46dc669fe6ebed980bef6ecab197b73fc0697488aff5746ee4fe6e8a64d7cd"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"path": "js/frond.js",
|
|
16
16
|
"component": "tina4-css",
|
|
17
|
-
"sha256": "
|
|
17
|
+
"sha256": "471cdcf1eae45142dce5a9755ce4d89e4e816989f3534ae2af56308ec4dcae65"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"path": "js/tina4.min.js",
|
|
@@ -23,6 +23,13 @@ var _frondModule = (() => {
|
|
|
23
23
|
frond: () => frond
|
|
24
24
|
});
|
|
25
25
|
var _token = null;
|
|
26
|
+
function _sameOrigin(url) {
|
|
27
|
+
try {
|
|
28
|
+
return new URL(url, window.location.href).origin === window.location.origin;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
26
33
|
function request(url, options) {
|
|
27
34
|
let opts;
|
|
28
35
|
if (typeof options === "function") {
|
|
@@ -33,7 +40,8 @@ var _frondModule = (() => {
|
|
|
33
40
|
const method = (opts.method || "GET").toUpperCase();
|
|
34
41
|
const xhr = new XMLHttpRequest();
|
|
35
42
|
xhr.open(method, url, true);
|
|
36
|
-
|
|
43
|
+
const sameOrigin = _sameOrigin(url);
|
|
44
|
+
if (_token !== null && sameOrigin) {
|
|
37
45
|
xhr.setRequestHeader("Authorization", "Bearer " + _token);
|
|
38
46
|
}
|
|
39
47
|
if (opts.headers) {
|
|
@@ -57,7 +65,8 @@ var _frondModule = (() => {
|
|
|
57
65
|
}
|
|
58
66
|
xhr.onload = function() {
|
|
59
67
|
const freshToken = xhr.getResponseHeader("FreshToken");
|
|
60
|
-
|
|
68
|
+
const answeredBySameOrigin = sameOrigin && (!xhr.responseURL || _sameOrigin(xhr.responseURL));
|
|
69
|
+
if (freshToken && freshToken !== "" && answeredBySameOrigin) {
|
|
61
70
|
_token = freshToken;
|
|
62
71
|
}
|
|
63
72
|
let content = xhr.response;
|
|
@@ -169,8 +178,12 @@ var _frondModule = (() => {
|
|
|
169
178
|
* Collect all form field values into a FormData object.
|
|
170
179
|
*
|
|
171
180
|
* Handles inputs, selects, textareas, file uploads (including
|
|
172
|
-
* multi-file), checkboxes, and radio buttons.
|
|
173
|
-
*
|
|
181
|
+
* multi-file), checkboxes, and radio buttons.
|
|
182
|
+
*
|
|
183
|
+
* A `formToken` field is sent as the server rendered it. frond never
|
|
184
|
+
* writes the bearer into it: the bearer travels in the Authorization
|
|
185
|
+
* header (own origin only), and the server accepts only a form token in
|
|
186
|
+
* the formToken slot.
|
|
174
187
|
*
|
|
175
188
|
* @param formId - DOM id of the form (without '#').
|
|
176
189
|
* @returns Populated FormData instance.
|
|
@@ -180,9 +193,6 @@ var _frondModule = (() => {
|
|
|
180
193
|
const elements = document.querySelectorAll("#" + formId + " select, #" + formId + " input, #" + formId + " textarea");
|
|
181
194
|
for (let i = 0; i < elements.length; i++) {
|
|
182
195
|
const el = elements[i];
|
|
183
|
-
if (el.name === "formToken" && _token !== null) {
|
|
184
|
-
el.value = _token;
|
|
185
|
-
}
|
|
186
196
|
if (!el.name) continue;
|
|
187
197
|
if (el.type === "file") {
|
|
188
198
|
const files = el.files;
|
|
@@ -204,6 +214,15 @@ var _frondModule = (() => {
|
|
|
204
214
|
} else if (el.type !== "radio") {
|
|
205
215
|
fd.append(el.name, "0");
|
|
206
216
|
}
|
|
217
|
+
} else if (el.type === "select-multiple") {
|
|
218
|
+
const options = el.selectedOptions;
|
|
219
|
+
for (let o = 0; o < options.length; o++) {
|
|
220
|
+
const option = options[o];
|
|
221
|
+
const group = option.parentElement;
|
|
222
|
+
if (option.disabled) continue;
|
|
223
|
+
if (group instanceof HTMLOptGroupElement && group.disabled) continue;
|
|
224
|
+
fd.append(el.name, option.value);
|
|
225
|
+
}
|
|
207
226
|
} else {
|
|
208
227
|
fd.append(el.name, el.value === "" ? "" : el.value);
|
|
209
228
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _frondModule=(()=>{var E=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var A=(t,s)=>{for(var e in s)E(t,e,{get:s[e],enumerable:!0})},D=(t,s,e,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of H(s))!q.call(t,n)&&n!==e&&E(t,n,{get:()=>s[n],enumerable:!(o=O(s,n))||o.enumerable});return t};var W=t=>D(E({},"__esModule",{value:!0}),t);var z={};A(z,{frond:()=>C});var y=null;function v(t,s){let e;typeof s=="function"?e={onSuccess:s}:e=s||{};let o=(e.method||"GET").toUpperCase(),n=new XMLHttpRequest;if(n.open(o,t,!0),y!==null&&n.setRequestHeader("Authorization","Bearer "+y),e.headers)for(let u in e.headers)Object.prototype.hasOwnProperty.call(e.headers,u)&&n.setRequestHeader(u,e.headers[u]);let c=null;e.body!==void 0&&e.body!==null&&(e.body instanceof FormData?c=e.body:typeof e.body=="object"?(c=JSON.stringify(e.body),n.setRequestHeader("Content-Type","application/json; charset=UTF-8")):typeof e.body=="string"&&(c=e.body,n.setRequestHeader("Content-Type","text/plain; charset=UTF-8"))),n.onload=function(){let u=n.getResponseHeader("FreshToken");u&&u!==""&&(y=u);let r=n.response;try{r=JSON.parse(r)}catch{}if(n.responseURL){let i=new URL(t,window.location.href).href;if(n.responseURL!==i){window.location.href=n.responseURL;return}}n.status>=200&&n.status<400?e.onSuccess&&e.onSuccess(r,n.status,n):e.onError&&e.onError(n.status,n)},n.onerror=function(){e.onError&&e.onError(n.status,n)},e.timeout!==0&&(n.timeout=e.timeout||3e4,n.ontimeout=function(){e.onError&&e.onError(n.status,n)}),n.send(c)}function h(t,s){if(!t)return"";let e=new DOMParser,o=t.includes("<html>")?t:"<body>"+t+"</body></html>",c=e.parseFromString(o,"text/html").querySelector("body"),u=c.querySelectorAll("script");if(u.forEach(function(r){r.remove()}),s!==null){let r=document.getElementById(s);return r&&(c.children.length>0?r.replaceChildren.apply(r,Array.from(c.children)):r.innerHTML=c.innerHTML,u.forEach(function(i){let l=document.createElement("script");l.type="text/javascript",l.async=!0,i.src?l.src=i.src:l.textContent=i.textContent,r.appendChild(l)})),""}return u.forEach(function(r){let i=document.createElement("script");i.type="text/javascript",i.async=!0,i.textContent=r.textContent,document.body.appendChild(i)}),c.innerHTML}function _(t,s,e,o){let n=s||"content";v(t,{method:"GET",onSuccess:function(c,u){if(document.getElementById(n)){let r=h(c,n);e&&e(r,c)}else e&&e(c)},onError:o})}function k(t,s,e,o,n){let c=e||"content";v(t,{method:"POST",body:s,onSuccess:function(u){let r="";if(u&&u.message!==void 0)r=h(u.message,c);else if(document.getElementById(c))r=h(u,c);else{o&&o(u);return}o&&o(r,u)},onError:n})}var x={collect:function(t){let s=new FormData,e=document.querySelectorAll("#"+t+" select, #"+t+" input, #"+t+" textarea");for(let o=0;o<e.length;o++){let n=e[o];if(n.name==="formToken"&&y!==null&&(n.value=y),!!n.name)if(n.type==="file"){let c=n.files;if(c)for(let u=0;u<c.length;u++){let r=c[u];if(r!==void 0){let i=n.name;c.length>1&&!i.includes("[")&&(i=i+"[]"),s.append(i,r,r.name)}}}else n.type==="checkbox"||n.type==="radio"?n.checked?s.append(n.name,n.value):n.type!=="radio"&&s.append(n.name,"0"):s.append(n.name,n.value===""?"":n.value)}return s},submit:function(t,s,e,o,n){let c=x.collect(t);k(s,c,e||"message",o,n)},show:function(t,s,e,o,n){let c=t.toUpperCase();(t==="create"||t==="edit")&&(c="GET"),t==="delete"&&(c="DELETE");let u=e||"form";v(s,{method:c,onSuccess:function(r){let i="";if(r&&r.message!==void 0)i=h(r.message,u);else if(document.getElementById(u))i=h(r,u);else{o&&o(r);return}o&&o(i)},onError:n})}};function M(t,s){let e={reconnect:!0,reconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:1/0,protocols:[],onOpen:function(){},onClose:function(){},onError:function(){},...s||{}},o=null,n=!1,c=e.reconnectDelay,u=0,r=null,i={message:[],open:[],close:[],error:[]},l={status:"connecting",send:function(f){if(!o||o.readyState!==WebSocket.OPEN)throw new Error("[frond] WebSocket is not connected");o.send(typeof f=="string"?f:JSON.stringify(f))},on:function(f,a){return i[f]||(i[f]=[]),i[f].push(a),function(){let d=i[f],g=d.indexOf(a);g>=0&&d.splice(g,1)}},close:function(f,a){n=!0,r&&(clearTimeout(r),r=null),o&&o.close(f||1e3,a||""),l.status="closed"}};function m(f){if(typeof f!="string")return f;try{return JSON.parse(f)}catch{return f}}function p(){!e.reconnect||u>=e.maxReconnectAttempts||(u++,l.status="reconnecting",r=setTimeout(function(){r=null,w()},c),c=Math.min(c*2,e.maxReconnectDelay))}function w(){l.status=u>0?"reconnecting":"connecting";try{o=new WebSocket(t,e.protocols)}catch{l.status="closed";return}o.onopen=function(){l.status="open",u=0,c=e.reconnectDelay,e.onOpen();for(let f of i.open)f()},o.onmessage=function(f){let a=m(f.data);for(let d of i.message)d(a)},o.onclose=function(f){l.status="closed",e.onClose(f.code,f.reason);for(let a of i.close)a(f.code,f.reason);n||p()},o.onerror=function(f){e.onError(f);for(let a of i.error)a(f)}}return w(),l}function I(t,s){let e={reconnect:!0,reconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:1/0,events:[],json:!0,onOpen:function(){},onClose:function(){},onError:function(){},...s||{}},o=null,n=!1,c=e.reconnectDelay,u=0,r=null,i={message:[],open:[],close:[],error:[]},l={status:"connecting",on:function(a,d){return i[a]||(i[a]=[]),i[a].push(d),function(){let g=i[a],T=g.indexOf(d);T>=0&&g.splice(T,1)}},close:function(){n=!0,r&&(clearTimeout(r),r=null),o&&(o.close(),o=null),l.status="closed"}};function m(a){if(!e.json)return a;try{return JSON.parse(a)}catch{return a}}function p(a,d){for(let g of i.message)g(a,d||void 0)}function w(){!e.reconnect||u>=e.maxReconnectAttempts||(u++,l.status="reconnecting",r=setTimeout(function(){r=null,f()},c),c=Math.min(c*2,e.maxReconnectDelay))}function f(){l.status=u>0?"reconnecting":"connecting";try{o=new EventSource(t)}catch{l.status="closed";return}o.onopen=function(){l.status="open",u=0,c=e.reconnectDelay,e.onOpen();for(let a of i.open)a(null)},o.onmessage=function(a){p(m(a.data),null)};for(let a of e.events)o.addEventListener(a,function(d){p(m(d.data),a)});o.onerror=function(a){e.onError(a);for(let d of i.error)d(a);if(o&&o.readyState===2){o=null,l.status="closed",e.onClose();for(let d of i.close)d(null);n||w()}}}return f(),l}var U={set:function(t,s,e){let o="";if(e){let n=new Date;n.setTime(n.getTime()+e*24*60*60*1e3),o="; expires="+n.toUTCString()}document.cookie=t+"="+(s||"")+o+"; path=/"},get:function(t){let s=t+"=",e=document.cookie.split(";");for(let o=0;o<e.length;o++){let n=e[o];for(;n.charAt(0)===" ";)n=n.substring(1);if(n.indexOf(s)===0)return n.substring(s.length)}return null},remove:function(t){document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"}};function j(t,s){let e=document.getElementById("message");if(!e)return;let o=s||"info";e.innerHTML='<div class="alert alert-'+o+' alert-dismissible">'+t+'<button type="button" class="btn-close" data-t4-dismiss="alert">×</button></div>'}function X(t,s,e,o){let n=window.screenLeft!==void 0?window.screenLeft:window.screenX,c=window.screenTop!==void 0?window.screenTop:window.screenY,u=window.innerWidth||document.documentElement.clientWidth||screen.width,r=window.innerHeight||document.documentElement.clientHeight||screen.height,i=u/window.screen.availWidth,l=(u-e)/2/i+n,m=(r-o)/2/i+c,p=window.open(t,s,"directories=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+e/i+",height="+o/i+",top="+m+",left="+l);return window.focus&&p&&p.focus(),p}function B(t){if(t.indexOf("No data available")>=0){window.alert("No data available for this report.");return}window.open(t,"_blank","toolbar=no,scrollbars=yes,resizable=yes,width=800,height=600,top=0,left=0")}function P(t,s,e,o){v(t,{method:"POST",body:{query:s,variables:e||{}},onSuccess:function(n){o&&o(n.data||null,n.errors||void 0)},onError:function(n){o&&o(null,[{message:"GraphQL request failed with status "+n}])}})}function b(t){let s=t.dataset;return s&&s.key?s.key:null}function F(t,s){let e=s.attributes;for(let n=0;n<e.length;n++){let c=e[n];t.getAttribute(c.name)!==c.value&&t.setAttribute(c.name,c.value)}Array.prototype.slice.call(t.attributes).forEach(function(n){s.hasAttribute(n.name)||t.removeAttribute(n.name)})}function G(t,s){let e=s.tagName;e==="INPUT"||e==="TEXTAREA"||e==="SELECT"||(F(t,s),t.children.length||s.children.length?L(t,s):t.innerHTML!==s.innerHTML&&(t.innerHTML=s.innerHTML))}function L(t,s){let e=Array.prototype.slice.call(t.children),o=Array.prototype.slice.call(s.children),n={};e.forEach(function(r){let i=b(r);i&&(n[i]=r)});let c=[];for(let r=0;r<o.length;r++){let i=o[r],l=b(i),m=null;l&&n[l]?m=n[l]:!l&&e[r]&&!b(e[r])&&e[r].tagName===i.tagName&&(m=e[r]),m&&m.tagName===i.tagName?(G(m,i),reused.push(m),c.push(m)):c.push(i)}let u=t.firstElementChild;for(let r=0;r<c.length;r++){let i=c[r];i===u?u=u.nextElementSibling:t.insertBefore(i,u)}e.forEach(function(r){c.indexOf(r)===-1&&r.parentNode===t&&t.removeChild(r)}),reused}function R(t,s){let e=document.createElement("div");if(e.innerHTML=s,!e.children.length||!t.children.length){t.innerHTML=s;return}L(t,e)}function J(t){return/^wss?:\/\//.test(t)?t:(typeof location<"u"&&location.protocol==="https:"?"wss":"ws")+"://"+location.host+t}function N(t,s){return t&&typeof t=="object"?t.type==="live"?s&&t.name&&t.name!==s?null:t.html!=null?String(t.html):null:null:typeof t=="string"?t:null}function S(t){if(typeof document>"u")return;let e=(t||document).querySelectorAll("[data-frond-live]");Array.prototype.slice.call(e).forEach(function(o){if(o.__frondLive)return;o.__frondLive=!0;let n=o.getAttribute("data-mode"),c=o.getAttribute("data-frond-live");if(n==="poll"){let u=o.getAttribute("data-src"),r=(parseInt(o.getAttribute("data-interval"),10)||5)*1e3,i=setInterval(function(){typeof document<"u"&&document.hidden||v(u,{method:"GET",onSuccess:function(l){R(o,typeof l=="string"?l:String(l))}})},r);o.__frondLiveStop=function(){clearInterval(i)}}else if(n==="ws"){let u=M(J(o.getAttribute("data-ws")));u.on("message",function(r){let i=N(r,c);i!==null&&R(o,i)}),o.__frondLiveStop=function(){u.close()}}else n==="sse"&&typeof console<"u"&&console.warn&&console.warn("[frond.live] sse transport is not wired yet (v1 supports poll and ws); block '"+c+"' shows first paint only. Use poll or ws.")})}var C={request:v,load:_,post:k,inject:h,form:x,ws:M,sse:I,live:S,cookie:U,message:j,popup:X,report:B,graphql:P,get token(){return y},set token(t){y=t}};typeof window<"u"&&(window.frond=C,typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){S()}):S()));return W(z);})();
|
|
1
|
+
var _frondModule=(()=>{var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var D=(t,r)=>{for(var e in r)E(t,e,{get:r[e],enumerable:!0})},_=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of q(r))!A.call(t,n)&&n!==e&&E(t,n,{get:()=>r[n],enumerable:!(o=H(r,n))||o.enumerable});return t};var W=t=>_(E({},"__esModule",{value:!0}),t);var K={};D(K,{frond:()=>C});var v=null;function R(t){try{return new URL(t,window.location.href).origin===window.location.origin}catch{return!1}}function h(t,r){let e;typeof r=="function"?e={onSuccess:r}:e=r||{};let o=(e.method||"GET").toUpperCase(),n=new XMLHttpRequest;n.open(o,t,!0);let c=R(t);if(v!==null&&c&&n.setRequestHeader("Authorization","Bearer "+v),e.headers)for(let s in e.headers)Object.prototype.hasOwnProperty.call(e.headers,s)&&n.setRequestHeader(s,e.headers[s]);let u=null;e.body!==void 0&&e.body!==null&&(e.body instanceof FormData?u=e.body:typeof e.body=="object"?(u=JSON.stringify(e.body),n.setRequestHeader("Content-Type","application/json; charset=UTF-8")):typeof e.body=="string"&&(u=e.body,n.setRequestHeader("Content-Type","text/plain; charset=UTF-8"))),n.onload=function(){let s=n.getResponseHeader("FreshToken"),i=c&&(!n.responseURL||R(n.responseURL));s&&s!==""&&i&&(v=s);let l=n.response;try{l=JSON.parse(l)}catch{}if(n.responseURL){let f=new URL(t,window.location.href).href;if(n.responseURL!==f){window.location.href=n.responseURL;return}}n.status>=200&&n.status<400?e.onSuccess&&e.onSuccess(l,n.status,n):e.onError&&e.onError(n.status,n)},n.onerror=function(){e.onError&&e.onError(n.status,n)},e.timeout!==0&&(n.timeout=e.timeout||3e4,n.ontimeout=function(){e.onError&&e.onError(n.status,n)}),n.send(u)}function y(t,r){if(!t)return"";let e=new DOMParser,o=t.includes("<html>")?t:"<body>"+t+"</body></html>",c=e.parseFromString(o,"text/html").querySelector("body"),u=c.querySelectorAll("script");if(u.forEach(function(s){s.remove()}),r!==null){let s=document.getElementById(r);return s&&(c.children.length>0?s.replaceChildren.apply(s,Array.from(c.children)):s.innerHTML=c.innerHTML,u.forEach(function(i){let l=document.createElement("script");l.type="text/javascript",l.async=!0,i.src?l.src=i.src:l.textContent=i.textContent,s.appendChild(l)})),""}return u.forEach(function(s){let i=document.createElement("script");i.type="text/javascript",i.async=!0,i.textContent=s.textContent,document.body.appendChild(i)}),c.innerHTML}function U(t,r,e,o){let n=r||"content";h(t,{method:"GET",onSuccess:function(c,u){if(document.getElementById(n)){let s=y(c,n);e&&e(s,c)}else e&&e(c)},onError:o})}function L(t,r,e,o,n){let c=e||"content";h(t,{method:"POST",body:r,onSuccess:function(u){let s="";if(u&&u.message!==void 0)s=y(u.message,c);else if(document.getElementById(c))s=y(u,c);else{o&&o(u);return}o&&o(s,u)},onError:n})}var M={collect:function(t){let r=new FormData,e=document.querySelectorAll("#"+t+" select, #"+t+" input, #"+t+" textarea");for(let o=0;o<e.length;o++){let n=e[o];if(n.name)if(n.type==="file"){let c=n.files;if(c)for(let u=0;u<c.length;u++){let s=c[u];if(s!==void 0){let i=n.name;c.length>1&&!i.includes("[")&&(i=i+"[]"),r.append(i,s,s.name)}}}else if(n.type==="checkbox"||n.type==="radio")n.checked?r.append(n.name,n.value):n.type!=="radio"&&r.append(n.name,"0");else if(n.type==="select-multiple"){let c=n.selectedOptions;for(let u=0;u<c.length;u++){let s=c[u],i=s.parentElement;s.disabled||i instanceof HTMLOptGroupElement&&i.disabled||r.append(n.name,s.value)}}else r.append(n.name,n.value===""?"":n.value)}return r},submit:function(t,r,e,o,n){let c=M.collect(t);L(r,c,e||"message",o,n)},show:function(t,r,e,o,n){let c=t.toUpperCase();(t==="create"||t==="edit")&&(c="GET"),t==="delete"&&(c="DELETE");let u=e||"form";h(r,{method:c,onSuccess:function(s){let i="";if(s&&s.message!==void 0)i=y(s.message,u);else if(document.getElementById(u))i=y(s,u);else{o&&o(s);return}o&&o(i)},onError:n})}};function x(t,r){let e={reconnect:!0,reconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:1/0,protocols:[],onOpen:function(){},onClose:function(){},onError:function(){},...r||{}},o=null,n=!1,c=e.reconnectDelay,u=0,s=null,i={message:[],open:[],close:[],error:[]},l={status:"connecting",send:function(d){if(!o||o.readyState!==WebSocket.OPEN)throw new Error("[frond] WebSocket is not connected");o.send(typeof d=="string"?d:JSON.stringify(d))},on:function(d,a){return i[d]||(i[d]=[]),i[d].push(a),function(){let p=i[d],g=p.indexOf(a);g>=0&&p.splice(g,1)}},close:function(d,a){n=!0,s&&(clearTimeout(s),s=null),o&&o.close(d||1e3,a||""),l.status="closed"}};function f(d){if(typeof d!="string")return d;try{return JSON.parse(d)}catch{return d}}function m(){!e.reconnect||u>=e.maxReconnectAttempts||(u++,l.status="reconnecting",s=setTimeout(function(){s=null,w()},c),c=Math.min(c*2,e.maxReconnectDelay))}function w(){l.status=u>0?"reconnecting":"connecting";try{o=new WebSocket(t,e.protocols)}catch{l.status="closed";return}o.onopen=function(){l.status="open",u=0,c=e.reconnectDelay,e.onOpen();for(let d of i.open)d()},o.onmessage=function(d){let a=f(d.data);for(let p of i.message)p(a)},o.onclose=function(d){l.status="closed",e.onClose(d.code,d.reason);for(let a of i.close)a(d.code,d.reason);n||m()},o.onerror=function(d){e.onError(d);for(let a of i.error)a(d)}}return w(),l}function I(t,r){let e={reconnect:!0,reconnectDelay:1e3,maxReconnectDelay:3e4,maxReconnectAttempts:1/0,events:[],json:!0,onOpen:function(){},onClose:function(){},onError:function(){},...r||{}},o=null,n=!1,c=e.reconnectDelay,u=0,s=null,i={message:[],open:[],close:[],error:[]},l={status:"connecting",on:function(a,p){return i[a]||(i[a]=[]),i[a].push(p),function(){let g=i[a],T=g.indexOf(p);T>=0&&g.splice(T,1)}},close:function(){n=!0,s&&(clearTimeout(s),s=null),o&&(o.close(),o=null),l.status="closed"}};function f(a){if(!e.json)return a;try{return JSON.parse(a)}catch{return a}}function m(a,p){for(let g of i.message)g(a,p||void 0)}function w(){!e.reconnect||u>=e.maxReconnectAttempts||(u++,l.status="reconnecting",s=setTimeout(function(){s=null,d()},c),c=Math.min(c*2,e.maxReconnectDelay))}function d(){l.status=u>0?"reconnecting":"connecting";try{o=new EventSource(t)}catch{l.status="closed";return}o.onopen=function(){l.status="open",u=0,c=e.reconnectDelay,e.onOpen();for(let a of i.open)a(null)},o.onmessage=function(a){m(f(a.data),null)};for(let a of e.events)o.addEventListener(a,function(p){m(f(p.data),a)});o.onerror=function(a){e.onError(a);for(let p of i.error)p(a);if(o&&o.readyState===2){o=null,l.status="closed",e.onClose();for(let p of i.close)p(null);n||w()}}}return d(),l}var j={set:function(t,r,e){let o="";if(e){let n=new Date;n.setTime(n.getTime()+e*24*60*60*1e3),o="; expires="+n.toUTCString()}document.cookie=t+"="+(r||"")+o+"; path=/"},get:function(t){let r=t+"=",e=document.cookie.split(";");for(let o=0;o<e.length;o++){let n=e[o];for(;n.charAt(0)===" ";)n=n.substring(1);if(n.indexOf(r)===0)return n.substring(r.length)}return null},remove:function(t){document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"}};function X(t,r){let e=document.getElementById("message");if(!e)return;let o=r||"info";e.innerHTML='<div class="alert alert-'+o+' alert-dismissible">'+t+'<button type="button" class="btn-close" data-t4-dismiss="alert">×</button></div>'}function B(t,r,e,o){let n=window.screenLeft!==void 0?window.screenLeft:window.screenX,c=window.screenTop!==void 0?window.screenTop:window.screenY,u=window.innerWidth||document.documentElement.clientWidth||screen.width,s=window.innerHeight||document.documentElement.clientHeight||screen.height,i=u/window.screen.availWidth,l=(u-e)/2/i+n,f=(s-o)/2/i+c,m=window.open(t,r,"directories=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+e/i+",height="+o/i+",top="+f+",left="+l);return window.focus&&m&&m.focus(),m}function P(t){if(t.indexOf("No data available")>=0){window.alert("No data available for this report.");return}window.open(t,"_blank","toolbar=no,scrollbars=yes,resizable=yes,width=800,height=600,top=0,left=0")}function F(t,r,e,o){h(t,{method:"POST",body:{query:r,variables:e||{}},onSuccess:function(n){o&&o(n.data||null,n.errors||void 0)},onError:function(n){o&&o(null,[{message:"GraphQL request failed with status "+n}])}})}function b(t){let r=t.dataset;return r&&r.key?r.key:null}function G(t,r){let e=r.attributes;for(let n=0;n<e.length;n++){let c=e[n];t.getAttribute(c.name)!==c.value&&t.setAttribute(c.name,c.value)}Array.prototype.slice.call(t.attributes).forEach(function(n){r.hasAttribute(n.name)||t.removeAttribute(n.name)})}function J(t,r){let e=r.tagName;e==="INPUT"||e==="TEXTAREA"||e==="SELECT"||(G(t,r),t.children.length||r.children.length?O(t,r):t.innerHTML!==r.innerHTML&&(t.innerHTML=r.innerHTML))}function O(t,r){let e=Array.prototype.slice.call(t.children),o=Array.prototype.slice.call(r.children),n={};e.forEach(function(s){let i=b(s);i&&(n[i]=s)});let c=[];for(let s=0;s<o.length;s++){let i=o[s],l=b(i),f=null;l&&n[l]?f=n[l]:!l&&e[s]&&!b(e[s])&&e[s].tagName===i.tagName&&(f=e[s]),f&&f.tagName===i.tagName?(J(f,i),reused.push(f),c.push(f)):c.push(i)}let u=t.firstElementChild;for(let s=0;s<c.length;s++){let i=c[s];i===u?u=u.nextElementSibling:t.insertBefore(i,u)}e.forEach(function(s){c.indexOf(s)===-1&&s.parentNode===t&&t.removeChild(s)}),reused}function k(t,r){let e=document.createElement("div");if(e.innerHTML=r,!e.children.length||!t.children.length){t.innerHTML=r;return}O(t,e)}function N(t){return/^wss?:\/\//.test(t)?t:(typeof location<"u"&&location.protocol==="https:"?"wss":"ws")+"://"+location.host+t}function z(t,r){return t&&typeof t=="object"?t.type==="live"?r&&t.name&&t.name!==r?null:t.html!=null?String(t.html):null:null:typeof t=="string"?t:null}function S(t){if(typeof document>"u")return;let e=(t||document).querySelectorAll("[data-frond-live]");Array.prototype.slice.call(e).forEach(function(o){if(o.__frondLive)return;o.__frondLive=!0;let n=o.getAttribute("data-mode"),c=o.getAttribute("data-frond-live");if(n==="poll"){let u=o.getAttribute("data-src"),s=(parseInt(o.getAttribute("data-interval"),10)||5)*1e3,i=setInterval(function(){typeof document<"u"&&document.hidden||h(u,{method:"GET",onSuccess:function(l){k(o,typeof l=="string"?l:String(l))}})},s);o.__frondLiveStop=function(){clearInterval(i)}}else if(n==="ws"){let u=x(N(o.getAttribute("data-ws")));u.on("message",function(s){let i=z(s,c);i!==null&&k(o,i)}),o.__frondLiveStop=function(){u.close()}}else n==="sse"&&typeof console<"u"&&console.warn&&console.warn("[frond.live] sse transport is not wired yet (v1 supports poll and ws); block '"+c+"' shows first paint only. Use poll or ws.")})}var C={request:h,load:U,post:L,inject:y,form:M,ws:x,sse:I,live:S,cookie:j,message:X,popup:B,report:P,graphql:F,get token(){return v},set token(t){v=t}};typeof window<"u"&&(window.frond=C,typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){S()}):S()));return W(K);})();
|
|
2
2
|
/* Frond v2.2.0 - tina4.com */
|