@tylix/compiler 0.5.0 → 0.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tylix/compiler",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "tylix",
@@ -33,6 +33,10 @@ const USE_CHANNEL_SOURCE = fs
33
33
  .readFileSync(path.join(__dirname, 'runtime', 'useChannel.js'), 'utf-8')
34
34
  .replace(/export\s+/g, '')
35
35
 
36
+ const NOT_FOUND_SOURCE = fs
37
+ .readFileSync(path.join(__dirname, 'runtime', 'notFound.js'), 'utf-8')
38
+ .replace(/export\s+/g, '')
39
+
36
40
  const capabilityCache = new Map() // capabilitiesDir -> { signature, code }
37
41
 
38
42
  async function loadCapabilityDefinitions(capabilitiesDir) {
@@ -84,6 +88,29 @@ async function loadCapabilityDefinitions(capabilitiesDir) {
84
88
  return definitions
85
89
  }
86
90
 
91
+ const headCache = new Map() // headFile -> { mtimeMs, html }
92
+
93
+ // Optional project file (app/head.html) whose contents are dropped into
94
+ // <head> on every page: extra <script>, <meta> or <link> tags. A missing
95
+ // file means no extra tags. Cached by modified time so production does not
96
+ // re-read it on every request, while dev edits show up on the next reload.
97
+ async function loadHeadTags(headFile) {
98
+ let stat
99
+ try {
100
+ stat = await fs.promises.stat(headFile)
101
+ } catch {
102
+ return ''
103
+ }
104
+ if (!stat.isFile()) return ''
105
+
106
+ const cached = headCache.get(headFile)
107
+ if (cached && cached.mtimeMs === stat.mtimeMs) return cached.html
108
+
109
+ const html = await fs.promises.readFile(headFile, 'utf-8')
110
+ headCache.set(headFile, { mtimeMs: stat.mtimeMs, html })
111
+ return html
112
+ }
113
+
87
114
  function compileComponentSource(source, fallbackClassName) {
88
115
  const isNativeComponent = /^\s*component\s+\w+/.test(source)
89
116
 
@@ -160,6 +187,8 @@ export async function renderPageDocument(
160
187
  // working exactly as before.
161
188
  stylesheets = ['/tailwind.css'],
162
189
  capabilitiesDir = path.join(process.cwd(), 'app', 'capabilities'),
190
+ // Optional file of extra <head> tags (scripts, meta, links).
191
+ headFile = path.join(process.cwd(), 'app', 'head.html'),
163
192
  } = {},
164
193
  ) {
165
194
  const {
@@ -183,6 +212,7 @@ export async function renderPageDocument(
183
212
  const { code, rootVar } = generateTemplate(templateNodes)
184
213
 
185
214
  const capabilityDefinitions = await loadCapabilityDefinitions(capabilitiesDir)
215
+ const headTags = await loadHeadTags(headFile)
186
216
 
187
217
  const childNames = Object.keys(childComponents)
188
218
  const childClassSources = childNames
@@ -245,6 +275,8 @@ ${LOADING_INDICATOR_SOURCE}
245
275
 
246
276
  ${USE_API_SOURCE}
247
277
 
278
+ ${NOT_FOUND_SOURCE}
279
+
248
280
  ${USE_CHANNEL_SOURCE}
249
281
 
250
282
  ${apiHelpers}
@@ -292,6 +324,7 @@ ${layoutMountCode}
292
324
  { name: 'capability definitions', code: capabilityDefinitions },
293
325
  { name: 'loading indicator', code: LOADING_INDICATOR_SOURCE },
294
326
  { name: 'useApi', code: USE_API_SOURCE },
327
+ { name: 'notFound', code: NOT_FOUND_SOURCE },
295
328
  { name: 'useChannel', code: USE_CHANNEL_SOURCE },
296
329
  { name: 'app/useApi helpers', code: apiHelpers },
297
330
  { name: 'page class', code: classSource },
@@ -326,6 +359,7 @@ ${layoutMountCode}
326
359
  <html>
327
360
  <head>
328
361
  <meta charset="UTF-8">
362
+ <meta name="viewport" content="width=device-width, initial-scale=1">
329
363
  ${channelsPortScript}
330
364
  <script>
331
365
  (function () {
@@ -337,7 +371,9 @@ ${layoutMountCode}
337
371
  })();
338
372
  </script>
339
373
  <title>${pageNode.title ?? pageName}</title>
374
+ <link rel="icon" type="image/png" href="/favicon.png">
340
375
  ${styleLinks}
376
+ ${headTags}
341
377
  ${styleTag}
342
378
  </head>
343
379
  <body>
@@ -0,0 +1,6 @@
1
+ // Swaps the current page for the closest _not-found.tyx. The server renders
2
+ // it with a 404 status and puts the original URL back in the address bar.
3
+ export function notFound() {
4
+ const here = window.location.pathname + window.location.search
5
+ window.location.replace('/_tylix/not-found?path=' + encodeURIComponent(here))
6
+ }
@@ -14,7 +14,11 @@ export async function useApi(url, options = {}) {
14
14
  finalBody = JSON.stringify(body)
15
15
  }
16
16
 
17
- __tylixRequestStart()
17
+ // __tylixRequestStart/End are injected by the runtime. Guarding them
18
+ // lets this exact file work whether or not they exist.
19
+ const track = typeof __tylixRequestStart === 'function'
20
+ if (track) __tylixRequestStart()
21
+
18
22
  try {
19
23
  const response = await fetch(url, {
20
24
  method,
@@ -29,17 +33,373 @@ export async function useApi(url, options = {}) {
29
33
  /* empty body */
30
34
  }
31
35
  if (!response.ok) {
36
+ // Only present when the server runs with APP_DEBUG=true.
37
+ const debug =
38
+ data && typeof data === 'object' && data.debug ? data.debug : null
39
+ if (debug) showDebug(debug, method, url)
32
40
  return {
33
41
  ok: false,
34
42
  status: response.status,
35
43
  data,
36
44
  error: (data && (data.error || data.message)) || 'Request failed',
45
+ debug,
37
46
  }
38
47
  }
39
- return { ok: true, status: response.status, data, error: null }
48
+ return { ok: true, status: response.status, data, error: null, debug: null }
40
49
  } catch (err) {
41
- return { ok: false, status: 0, data: null, error: err.message }
50
+ console.warn(
51
+ `[tylix] ${method} ${url} could not reach the server: ${err.message}. ` +
52
+ 'Is "tylix dev" running, and is the URL correct?',
53
+ )
54
+ return { ok: false, status: 0, data: null, error: err.message, debug: null }
42
55
  } finally {
43
- __tylixRequestEnd()
56
+ if (track) __tylixRequestEnd()
57
+ }
58
+
59
+ // ---------------------------------------------------------------
60
+ // Dev debug UI. Everything lives inside useApi on purpose, so the
61
+ // file still works if the compiler injects only this one function.
62
+ // ---------------------------------------------------------------
63
+ function showDebug(debug, method, url) {
64
+ logToConsole(debug, method, url)
65
+ try {
66
+ showOverlay(debug, method, url)
67
+ } catch (err) {
68
+ console.warn('[tylix] debug overlay failed:', err)
69
+ }
70
+ }
71
+
72
+ function logToConsole(d, method, url) {
73
+ console.groupCollapsed(
74
+ `%c${d.status} %c${method} ${url} %c${d.title || d.message}`,
75
+ 'color:#fb7185;font-weight:bold',
76
+ 'color:inherit',
77
+ 'color:#fb7185',
78
+ )
79
+ if (d.hint) console.log('How to fix:', d.hint)
80
+ console.log('Message:', d.message)
81
+ if (d.sql) console.log('SQL:', d.sql, d.params?.length ? d.params : '')
82
+ if (d.source) console.log('Source:', `${d.source.file}:${d.source.line}`)
83
+ const mine = (d.frames || []).filter((f) => f.kind === 'app')
84
+ if (mine.length) {
85
+ console.log(
86
+ 'Your frames:\n' +
87
+ mine.map((f) => ` ${f.fn || '<anonymous>'} (${f.short}:${f.line})`).join('\n'),
88
+ )
89
+ }
90
+ console.log('Full payload:', d)
91
+ console.groupEnd()
92
+ }
93
+
94
+ function showOverlay(debug, method, url) {
95
+ if (typeof document === 'undefined') return
96
+
97
+ const store = (window.__tylixDebug = window.__tylixDebug || {
98
+ errors: [],
99
+ index: 0,
100
+ open: false,
101
+ })
102
+ store.errors.unshift({ debug, method, url })
103
+ store.errors = store.errors.slice(0, 20)
104
+ store.index = 0
105
+ render()
106
+
107
+ function h(tag, props, ...children) {
108
+ const node = document.createElement(tag)
109
+ for (const [key, value] of Object.entries(props || {})) {
110
+ if (key === 'class') node.className = value
111
+ else if (key.startsWith('on')) node.addEventListener(key.slice(2), value)
112
+ else if (value != null) node.setAttribute(key, value)
113
+ }
114
+ for (const child of children.flat()) {
115
+ if (child == null || child === false) continue
116
+ node.append(child.nodeType ? child : document.createTextNode(String(child)))
117
+ }
118
+ return node
119
+ }
120
+
121
+ function getRoot() {
122
+ let host = document.getElementById('__tylix-debug-host')
123
+ if (!host) {
124
+ host = document.createElement('div')
125
+ host.id = '__tylix-debug-host'
126
+ document.body.appendChild(host)
127
+ host.attachShadow({ mode: 'open' })
128
+ document.addEventListener('keydown', (e) => {
129
+ if (e.key === 'Escape' && store.open) {
130
+ store.open = false
131
+ render()
132
+ }
133
+ })
134
+ }
135
+ return host.shadowRoot
136
+ }
137
+
138
+ const KEYWORDS = new Set(
139
+ (
140
+ 'SELECT FROM WHERE INSERT INTO VALUES UPDATE SET DELETE CREATE TABLE ALTER ADD DROP COLUMN ' +
141
+ 'INDEX UNIQUE PRIMARY KEY JOIN LEFT RIGHT INNER ON AS AND OR NOT NULL IN IS LIKE ORDER BY ' +
142
+ 'GROUP HAVING LIMIT OFFSET ASC DESC COUNT RETURNING IF EXISTS DEFAULT'
143
+ ).split(' '),
144
+ )
145
+
146
+ function highlightSql(sql, culprits) {
147
+ const re =
148
+ /('(?:[^'\\]|\\.)*')|(`[^`]*`|"[^"]*")|(\?|\$\d+)|(\d+(?:\.\d+)?)|([A-Za-z_]\w*)/g
149
+ const out = []
150
+ let last = 0
151
+ let m
152
+ while ((m = re.exec(sql))) {
153
+ if (m.index > last) out.push(sql.slice(last, m.index))
154
+ const token = m[0]
155
+ let cls = null
156
+ if (m[1]) cls = 'str'
157
+ else if (m[2]) cls = culprits.has(token.slice(1, -1)) ? 'culprit' : 'id'
158
+ else if (m[3]) cls = 'ph'
159
+ else if (m[4]) cls = 'num'
160
+ else if (KEYWORDS.has(token.toUpperCase())) cls = 'kw'
161
+ else if (culprits.has(token)) cls = 'culprit'
162
+ out.push(cls ? h('span', { class: 't-' + cls }, token) : token)
163
+ last = re.lastIndex
164
+ }
165
+ if (last < sql.length) out.push(sql.slice(last))
166
+ return out
167
+ }
168
+
169
+ function copy(button, text) {
170
+ const done = () => {
171
+ const old = button.textContent
172
+ button.textContent = 'Copied'
173
+ setTimeout(() => (button.textContent = old), 1400)
174
+ }
175
+ if (navigator.clipboard && window.isSecureContext) {
176
+ navigator.clipboard.writeText(text).then(done, done)
177
+ } else {
178
+ const ta = document.createElement('textarea')
179
+ ta.value = text
180
+ document.body.appendChild(ta)
181
+ ta.select()
182
+ try {
183
+ document.execCommand('copy')
184
+ } catch {
185
+ /* ignore */
186
+ }
187
+ ta.remove()
188
+ done()
189
+ }
190
+ }
191
+
192
+ function toMarkdown(d, method, url) {
193
+ const fence = String.fromCharCode(96).repeat(3)
194
+ const lines = [`## ${d.title || d.name}`, '', `**${d.name}${d.driver ? ` (${d.driver})` : ''}:** ${d.message}`]
195
+ if (d.hint) lines.push('', `**Hint:** ${d.hint}`)
196
+ if (d.sql) {
197
+ lines.push('', fence + 'sql', d.sql, fence)
198
+ if (d.params?.length) lines.push('Params: ' + JSON.stringify(d.params))
199
+ }
200
+ lines.push('', `**Request:** ${method} ${url}`)
201
+ const mine = (d.frames || []).filter((f) => f.kind === 'app').slice(0, 8)
202
+ if (mine.length) {
203
+ lines.push('', fence)
204
+ for (const f of mine) lines.push(`at ${f.fn || '<anonymous>'} (${f.short}:${f.line}:${f.column})`)
205
+ lines.push(fence)
206
+ }
207
+ return lines.join('\n')
208
+ }
209
+
210
+ function panel(entry) {
211
+ const { debug: d, method, url } = entry
212
+ const culprits = new Set([d.table, d.column].filter(Boolean))
213
+ const mine = (d.frames || []).filter((f) => f.kind === 'app').slice(0, 6)
214
+
215
+ return h(
216
+ 'div',
217
+ { class: 'panel' },
218
+ h(
219
+ 'div',
220
+ { class: 'chips' },
221
+ h('span', { class: 'chip danger' }, d.status),
222
+ d.driver && h('span', { class: 'chip accent' }, d.driver),
223
+ d.kind && h('span', { class: 'chip' }, d.kind.replace(/_/g, ' ')),
224
+ d.code && h('span', { class: 'chip mono' }, d.code),
225
+ ),
226
+ h('h1', {}, d.title || String(d.message).split('\n')[0]),
227
+ h('p', { class: 'req mono' }, `${method} ${url}`),
228
+ d.title && h('pre', { class: 'message mono' }, d.message),
229
+ d.hint &&
230
+ h('div', { class: 'hint' }, h('b', {}, 'How to fix'), h('span', {}, d.hint)),
231
+ d.source &&
232
+ h(
233
+ 'section',
234
+ {},
235
+ h('h2', {}, `Where it happened ${d.source.file}:${d.source.line}`),
236
+ h(
237
+ 'div',
238
+ { class: 'code' },
239
+ d.source.lines.map((text, i) => {
240
+ const n = d.source.start + i
241
+ return h(
242
+ 'div',
243
+ { class: 'line' + (n === d.source.line ? ' hit' : '') },
244
+ h('span', { class: 'gutter' }, n),
245
+ h('span', { class: 'mono' }, text || ' '),
246
+ )
247
+ }),
248
+ ),
249
+ ),
250
+ d.sql &&
251
+ h(
252
+ 'section',
253
+ {},
254
+ h('h2', {}, d.driver === 'mongodb' ? 'Operation' : 'Query'),
255
+ h('pre', { class: 'sql mono' }, highlightSql(d.sql, culprits)),
256
+ d.params?.length > 0 &&
257
+ h(
258
+ 'div',
259
+ { class: 'params mono' },
260
+ d.params.map((v, i) => h('div', {}, `${i + 1} ${JSON.stringify(v)}`)),
261
+ ),
262
+ ),
263
+ mine.length > 0 &&
264
+ h(
265
+ 'section',
266
+ {},
267
+ h('h2', {}, 'Your code in the stack'),
268
+ mine.map((f) =>
269
+ h(
270
+ 'div',
271
+ { class: 'frame' },
272
+ h('b', {}, f.fn || '<anonymous>'),
273
+ h('span', { class: 'mono' }, `${f.short}:${f.line}:${f.column}`),
274
+ ),
275
+ ),
276
+ ),
277
+ h(
278
+ 'div',
279
+ { class: 'actions' },
280
+ h('button', { onclick: (e) => copy(e.target, toMarkdown(d, method, url)) }, 'Copy as Markdown'),
281
+ h('button', { onclick: (e) => copy(e.target, JSON.stringify(d, null, 2)) }, 'Copy JSON'),
282
+ ),
283
+ )
284
+ }
285
+
286
+ function render() {
287
+ const root = getRoot()
288
+ const dark =
289
+ document.documentElement.classList.contains('dark') ||
290
+ window.matchMedia('(prefers-color-scheme: dark)').matches
291
+ const entry = store.errors[store.index]
292
+ const total = store.errors.length
293
+
294
+ const nodes = [h('style', {}, CSS)]
295
+
296
+ if (total === 0) {
297
+ root.replaceChildren(...nodes)
298
+ return
299
+ }
300
+
301
+ if (!store.open) {
302
+ nodes.push(
303
+ h(
304
+ 'button',
305
+ {
306
+ class: 'badge' + (dark ? ' dark' : ''),
307
+ onclick: () => {
308
+ store.open = true
309
+ render()
310
+ },
311
+ },
312
+ h('span', { class: 'dot' }),
313
+ `${entry.debug.status} ${entry.debug.title || entry.debug.message}`.slice(0, 70),
314
+ total > 1 && h('span', { class: 'count' }, `+${total - 1}`),
315
+ ),
316
+ )
317
+ } else {
318
+ const close = () => {
319
+ store.open = false
320
+ render()
321
+ }
322
+ nodes.push(
323
+ h(
324
+ 'div',
325
+ { class: 'backdrop' + (dark ? ' dark' : ''), onclick: (e) => e.target === e.currentTarget && close() },
326
+ h(
327
+ 'div',
328
+ { class: 'modal' },
329
+ h(
330
+ 'div',
331
+ { class: 'bar' },
332
+ h('span', {}, 'Tylix debug'),
333
+ total > 1 &&
334
+ h(
335
+ 'span',
336
+ { class: 'pager' },
337
+ h('button', { onclick: () => { store.index = Math.min(total - 1, store.index + 1); render() } }, '‹'),
338
+ `${store.index + 1} / ${total}`,
339
+ h('button', { onclick: () => { store.index = Math.max(0, store.index - 1); render() } }, '›'),
340
+ ),
341
+ h(
342
+ 'span',
343
+ { class: 'bar-actions' },
344
+ h('button', { onclick: () => { store.errors = []; store.open = false; render() } }, 'Dismiss all'),
345
+ h('button', { onclick: close }, 'Close (Esc)'),
346
+ ),
347
+ ),
348
+ panel(entry),
349
+ ),
350
+ ),
351
+ )
352
+ }
353
+ root.replaceChildren(...nodes)
354
+ }
355
+
356
+ const CSS = `
357
+ * { box-sizing: border-box; }
358
+ .mono, pre { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
359
+ .dark, .backdrop, .badge { --bg:#fff; --bg2:#f1f5f9; --bd:#cbd5e1; --tx:#1e293b; --tx2:#64748b; --ac:#047857; --acbg:rgba(16,185,129,.1);
360
+ --dg:#be123c; --dgbg:#ffe4e6; --kw:#7c3aed; --st:#047857; --nu:#b45309; }
361
+ .dark { --bg:#0f172a; --bg2:#0b1220; --bd:#334155; --tx:#e2e8f0; --tx2:#94a3b8; --ac:#10b981; --acbg:rgba(16,185,129,.12);
362
+ --dg:#fb7185; --dgbg:rgba(76,5,25,.4); --kw:#a78bfa; --st:#34d399; --nu:#fbbf24; }
363
+ button { font: inherit; cursor: pointer; }
364
+ .badge { position: fixed; right: 16px; bottom: 16px; z-index: 2147483647; display: flex; gap: 8px; align-items: center;
365
+ max-width: min(520px, calc(100vw - 32px)); padding: 9px 14px; border-radius: 999px; font: 600 13px system-ui, sans-serif;
366
+ background: var(--bg); color: var(--tx); border: 1px solid var(--dg); box-shadow: 0 8px 30px rgba(0,0,0,.25); }
367
+ .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dg); flex: none; }
368
+ .count { background: var(--dgbg); color: var(--dg); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
369
+ .backdrop { position: fixed; inset: 0; z-index: 2147483647; background: rgba(2,6,23,.6); display: flex;
370
+ align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto; font: 14px/1.55 system-ui, sans-serif; color: var(--tx); }
371
+ .modal { width: 100%; max-width: 880px; background: var(--bg); border: 1px solid var(--bd); border-radius: 16px; overflow: hidden; }
372
+ .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px;
373
+ border-bottom: 1px solid var(--bd); font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--tx2); }
374
+ .bar button, .actions button { background: var(--bg2); color: var(--tx); border: 1px solid var(--bd); border-radius: 999px; padding: 4px 12px; font-size: 12px; }
375
+ .bar button:hover, .actions button:hover { border-color: var(--ac); }
376
+ .bar-actions, .pager { display: flex; gap: 8px; align-items: center; }
377
+ .panel { padding: 22px 26px 26px; }
378
+ .chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
379
+ .chip { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 10px;
380
+ border-radius: 999px; border: 1px solid var(--bd); color: var(--tx2); }
381
+ .chip.danger { color: var(--dg); background: var(--dgbg); border-color: var(--dg); }
382
+ .chip.accent { color: var(--ac); background: var(--acbg); border-color: var(--ac); }
383
+ h1 { font-size: 22px; line-height: 1.3; margin: 0 0 6px; }
384
+ h2 { font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--tx2); margin: 22px 0 8px; }
385
+ .req { color: var(--tx2); font-size: 12.5px; margin: 0 0 12px; }
386
+ .message { background: var(--bg2); border: 1px solid var(--bd); border-left: 3px solid var(--dg); border-radius: 8px;
387
+ padding: 10px 14px; margin: 0 0 14px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
388
+ .hint { display: flex; flex-direction: column; gap: 2px; background: var(--acbg); border: 1px solid var(--ac); border-radius: 10px; padding: 12px 16px; }
389
+ .hint b { color: var(--ac); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; }
390
+ .code { background: var(--bg2); border: 1px solid var(--bd); border-radius: 10px; padding: 6px 0; overflow-x: auto; }
391
+ .line { display: flex; font-size: 13px; line-height: 1.85; white-space: pre; }
392
+ .gutter { flex: 0 0 52px; text-align: right; padding-right: 14px; color: var(--tx2); user-select: none; }
393
+ .line.hit { background: var(--dgbg); } .line.hit .gutter { color: var(--dg); font-weight: 700; }
394
+ .sql { margin: 0; background: var(--bg2); border: 1px solid var(--bd); border-radius: 10px; padding: 12px 16px;
395
+ font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
396
+ .t-kw { color: var(--kw); font-weight: 600; } .t-str { color: var(--st); } .t-num { color: var(--nu); } .t-ph { color: var(--nu); }
397
+ .t-culprit { color: var(--dg); background: var(--dgbg); border-radius: 4px; padding: 0 3px; font-weight: 700; }
398
+ .params { margin-top: 8px; font-size: 12.5px; color: var(--tx2); background: var(--bg2); border: 1px solid var(--bd);
399
+ border-radius: 10px; padding: 10px 14px; word-break: break-all; }
400
+ .frame { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 7px 0; border-bottom: 1px solid var(--bd); font-size: 13px; }
401
+ .frame span { color: var(--ac); font-size: 12px; word-break: break-all; }
402
+ .actions { display: flex; gap: 8px; margin-top: 22px; }
403
+ `
44
404
  }
45
- }
405
+ }
@@ -1,4 +1,45 @@
1
- // packages/compiler/src/typecheck/tylix-globals.d.ts
1
+
2
+ // Present on failed requests only when the server runs with APP_DEBUG=true.
3
+ interface TylixDebugInfo {
4
+ status: number
5
+ name: string
6
+ message: string
7
+ title: string | null
8
+ hint: string | null
9
+ kind: string | null
10
+ driver: 'mysql' | 'postgres' | 'sqlite' | 'mongodb' | null
11
+ code: string | number | null
12
+ detail: string | null
13
+ table: string | null
14
+ column: string | null
15
+ sql: string | null
16
+ params: unknown[]
17
+ frames: Array<{
18
+ fn: string | null
19
+ file: string
20
+ short: string
21
+ line: number
22
+ column: number
23
+ kind: 'app' | 'vendor' | 'internal'
24
+ }>
25
+ source: {
26
+ file: string
27
+ line: number
28
+ column: number
29
+ start: number
30
+ lines: string[]
31
+ } | null
32
+ request: { method: string; url: string }
33
+ }
34
+
35
+ interface TylixApiResult {
36
+ ok: boolean
37
+ status: number
38
+ data: any
39
+ error?: string | null
40
+ debug?: TylixDebugInfo | null
41
+ }
42
+
2
43
  declare function useApi(
3
44
  path: string,
4
45
  options?: {
@@ -6,35 +47,32 @@ declare function useApi(
6
47
  body?: unknown
7
48
  headers?: Record<string, string>
8
49
  },
9
- ): Promise<{
10
- ok: boolean
11
- status: number
12
- data: any
13
- error?: string
14
- }>
50
+ ): Promise<TylixApiResult>
15
51
 
16
52
  // getApi/postApi/putApi/deleteApi share useApi's response shape --
17
53
  // convenience wrappers over the same underlying call.
18
54
  declare function getApi(
19
55
  path: string,
20
56
  options?: { headers?: Record<string, string> },
21
- ): Promise<{ ok: boolean; status: number; data: any; error?: string }>
57
+ ): Promise<TylixApiResult>
22
58
 
23
59
  declare function postApi(
24
60
  path: string,
25
61
  body?: unknown,
26
62
  options?: { headers?: Record<string, string> },
27
- ): Promise<{ ok: boolean; status: number; data: any; error?: string }>
63
+ ): Promise<TylixApiResult>
28
64
 
29
65
  declare function putApi(
30
66
  path: string,
31
67
  body?: unknown,
32
68
  options?: { headers?: Record<string, string> },
33
- ): Promise<{ ok: boolean; status: number; data: any; error?: string }>
69
+ ): Promise<TylixApiResult>
34
70
 
35
71
  declare function deleteApi(
36
72
  path: string,
37
73
  options?: { headers?: Record<string, string> },
38
- ): Promise<{ ok: boolean; status: number; data: any; error?: string }>
74
+ ): Promise<TylixApiResult>
75
+
76
+ declare function useChannel(name: string): any
39
77
 
40
- declare function useChannel(name: string): any
78
+ declare function notFound(): void