tina4-nodejs 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.
- package/CLAUDE.md +4 -3
- package/package.json +3 -3
- package/packages/cli/dist/bin.js +1384 -639
- package/packages/cli/src/commands/generate.ts +72 -23
- package/packages/core/dist/index.js +1393 -639
- package/packages/core/public/bundled-component-provenance.json +2 -2
- package/packages/core/public/js/frond.js +26 -7
- package/packages/core/public/js/frond.min.js +1 -1
- package/packages/core/src/index.ts +18 -0
- package/packages/core/src/middleware.ts +10 -4
- package/packages/core/src/queue.ts +42 -32
- package/packages/core/src/queueBackends/kafkaBackend.ts +687 -544
- package/packages/core/src/server.ts +41 -4
- package/packages/core/src/tcp.ts +484 -0
- package/packages/frond/dist/index.js +118 -4
- package/packages/frond/src/engine.ts +87 -8
- package/packages/frond/src/index.ts +1 -1
- package/packages/orm/dist/index.js +1386 -641
- package/packages/orm/src/migration.ts +34 -0
- package/packages/orm/src/queryBuilder.ts +38 -0
- package/types/core/src/index.d.ts +2 -0
- package/types/core/src/queue.d.ts +1 -1
- package/types/core/src/queueBackends/kafkaBackend.d.ts +48 -54
- package/types/core/src/tcp.d.ts +165 -0
- package/types/frond/src/engine.d.ts +9 -0
- package/types/frond/src/index.d.ts +1 -1
- package/types/orm/src/migration.d.ts +0 -24
- package/types/orm/src/queryBuilder.d.ts +28 -0
|
@@ -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 */
|
|
@@ -24,6 +24,24 @@ export type {
|
|
|
24
24
|
|
|
25
25
|
export { startServer, resolvePortAndHost, loopbackBindHosts, handle, start, stop, httpReason, resolveTemplate, resetTemplateCache, templateAutoRoutingEnabled, isBannerSuppressed } from "./server.js";
|
|
26
26
|
export { background, stopAllBackgroundTasks, backgroundTaskCount } from "./background.js";
|
|
27
|
+
export {
|
|
28
|
+
tcpService,
|
|
29
|
+
tcp,
|
|
30
|
+
TcpService,
|
|
31
|
+
TcpConnection,
|
|
32
|
+
registeredTcpServices,
|
|
33
|
+
clearTcpRegistry,
|
|
34
|
+
startAllTcpServices,
|
|
35
|
+
stopAcceptingAllTcpServices,
|
|
36
|
+
drainAllTcpServices,
|
|
37
|
+
} from "./tcp.js";
|
|
38
|
+
export type {
|
|
39
|
+
TcpServiceOptions,
|
|
40
|
+
TcpConnectHandler,
|
|
41
|
+
TcpDataHandler,
|
|
42
|
+
TcpCloseHandler,
|
|
43
|
+
TcpLineHandler,
|
|
44
|
+
} from "./tcp.js";
|
|
27
45
|
export { Router, RouteGroup, RouteRef, WsRouteRef, defaultRouter, runRouteMiddlewares, resolveStringMiddleware, isTrailingSlashRedirectEnabled } from "./router.js";
|
|
28
46
|
export { get, post, put, patch, del, any, websocket, del as delete } from "./router.js";
|
|
29
47
|
export type { RouteInfo } from "./router.js";
|
|
@@ -913,9 +913,9 @@ export class RequestLogger {
|
|
|
913
913
|
const duration = Date.now() - ((req as any).startTime ?? Date.now());
|
|
914
914
|
const status = res.raw.statusCode;
|
|
915
915
|
const method = req.method ?? "?";
|
|
916
|
-
const
|
|
916
|
+
const path = logPath(req);
|
|
917
917
|
const color = status >= 400 ? "\x1b[31m" : status >= 300 ? "\x1b[33m" : "\x1b[32m";
|
|
918
|
-
console.log(` ${color}${status}\x1b[0m ${method} ${
|
|
918
|
+
console.log(` ${color}${status}\x1b[0m ${method} ${path} \x1b[90m${duration}ms\x1b[0m`);
|
|
919
919
|
return [req, res];
|
|
920
920
|
}
|
|
921
921
|
}
|
|
@@ -1238,6 +1238,13 @@ export function attachCsrfFromEnv(): boolean {
|
|
|
1238
1238
|
return false;
|
|
1239
1239
|
}
|
|
1240
1240
|
|
|
1241
|
+
// The path only, never req.url: createRequest sets that to the absolute URL
|
|
1242
|
+
// with its query string, and OAuth codes, reset tokens and API keys ride in
|
|
1243
|
+
// the query straight into the log. Python, PHP and Ruby log the path too.
|
|
1244
|
+
function logPath(req: Tina4Request): string {
|
|
1245
|
+
return req.path ?? (req.url ?? "/").split("?")[0];
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1241
1248
|
// Built-in request logger middleware.
|
|
1242
1249
|
//
|
|
1243
1250
|
// v3.13.14: routes through the Tina4 Log (was a bare console.log) so the
|
|
@@ -1255,8 +1262,7 @@ export function requestLogger(): Middleware {
|
|
|
1255
1262
|
const duration = Date.now() - start;
|
|
1256
1263
|
const status = res.raw.statusCode;
|
|
1257
1264
|
const method = req.method ?? "?";
|
|
1258
|
-
|
|
1259
|
-
Log.info(`${method} ${url} -> ${status} (${duration}ms)`);
|
|
1265
|
+
Log.info(`${method} ${logPath(req)} -> ${status} (${duration}ms)`);
|
|
1260
1266
|
});
|
|
1261
1267
|
|
|
1262
1268
|
next();
|
|
@@ -14,14 +14,19 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
14
14
|
* Supported backends:
|
|
15
15
|
* - 'file' — JSON files on disk (default)
|
|
16
16
|
* - 'mongodb' — MongoDB via `mongodb` npm package (also 'mongo')
|
|
17
|
+
* - 'kafka' — Apache Kafka over a PERSISTENT worker-thread connection
|
|
18
|
+
* (the worker owns the socket, the read cursor and the committed offsets),
|
|
19
|
+
* so pop() resumes from the committed offset and complete()/fail() commit
|
|
20
|
+
* durably — it drains and survives restarts. This is ADR-0022 decision 8's
|
|
21
|
+
* fix; the old child-process-per-op design (which could never commit) is
|
|
22
|
+
* gone. See queueBackends/kafkaBackend.ts.
|
|
17
23
|
*
|
|
18
24
|
* REFUSED backends (ADR-0022):
|
|
19
|
-
* - 'rabbitmq'
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* tina4-ruby still offer both. See unsupportedBrokerMessage() below.
|
|
25
|
+
* - 'rabbitmq' THROWS on construction. Node drove it through a child process
|
|
26
|
+
* per operation, so no connection survived between pop() and complete() and
|
|
27
|
+
* acknowledgement was impossible (at-most-once: a dead consumer lost the
|
|
28
|
+
* job). It lost work silently, so it now refuses. tina4-python, tina4-php
|
|
29
|
+
* and tina4-ruby still offer it. See unsupportedBrokerMessage() below.
|
|
25
30
|
*
|
|
26
31
|
* Environment variables:
|
|
27
32
|
* TINA4_QUEUE_BACKEND — 'file' or 'mongodb'
|
|
@@ -43,6 +48,7 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
43
48
|
* queue.push("emails", { to: "alice@test.com" });
|
|
44
49
|
*/
|
|
45
50
|
import { MongoBackend } from "./queueBackends/mongoBackend.js";
|
|
51
|
+
import { KafkaBackend } from "./queueBackends/kafkaBackend.js";
|
|
46
52
|
import { LiteBackend } from "./queueBackends/liteBackend.js";
|
|
47
53
|
import { type QueueJob, type JobData, createJob } from "./job.js";
|
|
48
54
|
|
|
@@ -167,44 +173,41 @@ export interface QueueBackendInterface {
|
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
/**
|
|
170
|
-
* Why `backend: "rabbitmq"`
|
|
176
|
+
* Why `backend: "rabbitmq"` is refused in Node (ADR-0022).
|
|
171
177
|
*
|
|
172
|
-
*
|
|
173
|
-
* child process for EVERY operation. The child connects, performs one
|
|
174
|
-
* destroys its socket and exits, so no connection
|
|
175
|
-
*
|
|
178
|
+
* The RabbitMQ backend drives the wire protocol through `execFileSync`, spawning
|
|
179
|
+
* a fresh child process for EVERY operation. The child connects, performs one
|
|
180
|
+
* operation, destroys its socket and exits, so no connection or channel survives
|
|
181
|
+
* between push, pop and complete.
|
|
176
182
|
*
|
|
177
|
-
* That makes acknowledgement impossible, not merely unimplemented
|
|
183
|
+
* That makes acknowledgement impossible, not merely unimplemented: an AMQP
|
|
178
184
|
* delivery tag identifies a delivery on a CHANNEL that is already closed by the
|
|
179
|
-
* time pop() returns,
|
|
180
|
-
*
|
|
181
|
-
* a consumer that dies after pop() loses the job outright) and Kafka fetched
|
|
182
|
-
* from offset 0 every time (the topic could never drain).
|
|
185
|
+
* time pop() returns, so RabbitMQ ran Basic.Get with no-ack=true (at-most-once:
|
|
186
|
+
* a consumer that dies after pop() loses the job outright).
|
|
183
187
|
*
|
|
184
188
|
* Refusing loudly follows the same call the session backend already made for
|
|
185
189
|
* `redis-npm`: a silent demotion looks like it is working while the operator
|
|
186
190
|
* believes otherwise, which is worse than an outage you can see. Anyone
|
|
187
|
-
* "successfully" running
|
|
191
|
+
* "successfully" running it today is already losing jobs and does not know it.
|
|
188
192
|
*
|
|
189
|
-
* This is a HOLDING POSITION, not the design. The fix is a persistent
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
+
* This is a HOLDING POSITION, not the design. The fix is a persistent connection
|
|
194
|
+
* held on the backend instance, the way Python, PHP and Ruby already do it — and
|
|
195
|
+
* the way the Kafka backend now does (ADR-0022 decision 8 landed for Kafka; the
|
|
196
|
+
* same approach is owed to RabbitMQ). There is deliberately no opt-in escape
|
|
197
|
+
* hatch: nobody has asked for fire-and-forget.
|
|
193
198
|
*/
|
|
194
199
|
function unsupportedBrokerMessage(backendName: string): string {
|
|
195
|
-
const broker = backendName === "kafka" ? "Kafka" : "RabbitMQ";
|
|
196
|
-
const lost = backendName === "kafka"
|
|
197
|
-
? "every pop() re-read offset 0, so the topic could never drain"
|
|
198
|
-
: "pop() destroyed the message with no acknowledgement, so a consumer that died lost the job";
|
|
199
200
|
return (
|
|
200
201
|
`Queue backend "${backendName}" is not available in tina4-nodejs.\n\n` +
|
|
201
|
-
`Reason: the
|
|
202
|
+
`Reason: the RabbitMQ backend runs each operation in a separate child ` +
|
|
202
203
|
`process, so no connection survives between pop() and complete(). ` +
|
|
203
|
-
`Acknowledgement is therefore impossible, and
|
|
204
|
-
`
|
|
205
|
-
`
|
|
204
|
+
`Acknowledgement is therefore impossible, and pop() destroyed the message ` +
|
|
205
|
+
`with no acknowledgement, so a consumer that died lost the job. It was ` +
|
|
206
|
+
`losing work silently, so it now refuses instead.\n\n` +
|
|
207
|
+
`Use backend "kafka" (now a persistent connection: at-least-once, drains, ` +
|
|
208
|
+
`survives restarts), "mongodb" (at-least-once, real reservation + ` +
|
|
206
209
|
`visibility timeout) or the default "file" backend. tina4-python, ` +
|
|
207
|
-
`tina4-php and tina4-ruby still offer
|
|
210
|
+
`tina4-php and tina4-ruby still offer RabbitMQ.\n\n` +
|
|
208
211
|
`Tracking: ADR-0022 in tina4-documentation/plan/v3/DECISIONS.md, ` +
|
|
209
212
|
`findings in plan/v3/features/048-queue-backends.md.`
|
|
210
213
|
);
|
|
@@ -230,7 +233,7 @@ export class Queue {
|
|
|
230
233
|
* - new Queue("mongodb", { path: "data/queue" }) // legacy
|
|
231
234
|
* - new Queue() // file backend, default topic
|
|
232
235
|
*
|
|
233
|
-
* Throws on backend "rabbitmq"
|
|
236
|
+
* Throws on backend "rabbitmq" (ADR-0022); "kafka" is now supported.
|
|
234
237
|
*/
|
|
235
238
|
constructor(backendOrConfig?: string | QueueConfig, config?: QueueConfig) {
|
|
236
239
|
let resolvedConfig: QueueConfig = {};
|
|
@@ -255,8 +258,15 @@ export class Queue {
|
|
|
255
258
|
this.liteBackend = new LiteBackend(this.basePath, this._visibilityTimeout);
|
|
256
259
|
|
|
257
260
|
// Initialize external backends
|
|
258
|
-
if (this.backendName === "rabbitmq"
|
|
261
|
+
if (this.backendName === "rabbitmq") {
|
|
259
262
|
throw new Error(unsupportedBrokerMessage(this.backendName));
|
|
263
|
+
} else if (this.backendName === "kafka") {
|
|
264
|
+
// Kafka now holds a PERSISTENT connection (a worker thread owning the
|
|
265
|
+
// socket, the read cursor and the committed offsets), so pop() resumes
|
|
266
|
+
// from the committed offset and complete()/fail() commit durably — the
|
|
267
|
+
// backend drains and survives restarts (ADR-0022 decision 8, the fix the
|
|
268
|
+
// refusal was a holding position for). RabbitMQ stays refused.
|
|
269
|
+
this.externalBackend = new KafkaBackend({ visibilityTimeout: this._visibilityTimeout });
|
|
260
270
|
} else if (this.backendName === "mongodb" || this.backendName === "mongo") {
|
|
261
271
|
this.externalBackend = new MongoBackend({ visibilityTimeout: this._visibilityTimeout });
|
|
262
272
|
} else if (!["file", "default", "lite"].includes(this.backendName)) {
|