@tiaforge-ui/sinter 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/dist/cache.d.ts +5 -0
  4. package/dist/cache.js +95 -0
  5. package/dist/check/index.d.ts +85 -0
  6. package/dist/check/index.js +156 -0
  7. package/dist/check/openapi-types.d.ts +6 -0
  8. package/dist/check/openapi-types.js +84 -0
  9. package/dist/check/shadow.d.ts +49 -0
  10. package/dist/check/shadow.js +279 -0
  11. package/dist/cli.d.ts +2 -0
  12. package/dist/cli.js +67 -0
  13. package/dist/compiler/check-unit.d.ts +109 -0
  14. package/dist/compiler/check-unit.js +3 -0
  15. package/dist/compiler/compile.d.ts +66 -0
  16. package/dist/compiler/compile.js +1316 -0
  17. package/dist/compiler/diagnostic-docs.d.ts +10 -0
  18. package/dist/compiler/diagnostic-docs.js +142 -0
  19. package/dist/compiler/diagnostics.d.ts +57 -0
  20. package/dist/compiler/diagnostics.js +77 -0
  21. package/dist/compiler/expr.d.ts +97 -0
  22. package/dist/compiler/expr.js +853 -0
  23. package/dist/compiler/index.d.ts +22 -0
  24. package/dist/compiler/index.js +160 -0
  25. package/dist/compiler/openapi.d.ts +40 -0
  26. package/dist/compiler/openapi.js +177 -0
  27. package/dist/compiler/vocabulary.d.ts +12 -0
  28. package/dist/compiler/vocabulary.js +39 -0
  29. package/dist/dev.d.ts +10 -0
  30. package/dist/dev.js +92 -0
  31. package/dist/each.d.ts +3 -0
  32. package/dist/each.js +121 -0
  33. package/dist/index.d.ts +7 -0
  34. package/dist/index.js +4 -0
  35. package/dist/ir.d.ts +152 -0
  36. package/dist/ir.js +121 -0
  37. package/dist/lsp/quickfix.d.ts +15 -0
  38. package/dist/lsp/quickfix.js +58 -0
  39. package/dist/lsp/rpc.d.ts +31 -0
  40. package/dist/lsp/rpc.js +120 -0
  41. package/dist/lsp/server.d.ts +36 -0
  42. package/dist/lsp/server.js +281 -0
  43. package/dist/lsp/spec-location.d.ts +9 -0
  44. package/dist/lsp/spec-location.js +42 -0
  45. package/dist/lsp/typescript.d.ts +77 -0
  46. package/dist/lsp/typescript.js +242 -0
  47. package/dist/lsp/workspace.d.ts +56 -0
  48. package/dist/lsp/workspace.js +228 -0
  49. package/dist/optimistic.d.ts +3 -0
  50. package/dist/optimistic.js +15 -0
  51. package/dist/paginate.d.ts +3 -0
  52. package/dist/paginate.js +198 -0
  53. package/dist/persist.d.ts +3 -0
  54. package/dist/persist.js +55 -0
  55. package/dist/project.d.ts +42 -0
  56. package/dist/project.js +103 -0
  57. package/dist/runtime/app.d.ts +152 -0
  58. package/dist/runtime/app.js +1256 -0
  59. package/dist/runtime/config.d.ts +53 -0
  60. package/dist/runtime/config.js +118 -0
  61. package/dist/runtime/env.d.ts +18 -0
  62. package/dist/runtime/env.js +23 -0
  63. package/dist/runtime/helpers.d.ts +9 -0
  64. package/dist/runtime/helpers.js +55 -0
  65. package/dist/runtime/request.d.ts +23 -0
  66. package/dist/runtime/request.js +93 -0
  67. package/dist/runtime/security.d.ts +12 -0
  68. package/dist/runtime/security.js +34 -0
  69. package/dist/runtime/store.d.ts +98 -0
  70. package/dist/runtime/store.js +255 -0
  71. package/dist/sse.d.ts +7 -0
  72. package/dist/sse.js +209 -0
  73. package/dist/testing/index.d.ts +73 -0
  74. package/dist/testing/index.js +359 -0
  75. package/dist/vite.d.ts +11 -0
  76. package/dist/vite.js +96 -0
  77. package/dist/ws.d.ts +18 -0
  78. package/dist/ws.js +57 -0
  79. package/docs/diagnostics.md +283 -0
  80. package/html-custom-data.json +250 -0
  81. package/llms.txt +632 -0
  82. package/package.json +93 -4
@@ -0,0 +1,283 @@
1
+ # sinter diagnostics
2
+
3
+ Generated from `src/compiler/diagnostic-docs.ts` by `npm run docs`. Every diagnostic links to its section here. Codes from SN500 up are warnings; the rest are errors and fail the build.
4
+
5
+ ## SN101 unknown-attribute
6
+
7
+ Error, for example:
8
+
9
+ > `data-sn-txt` is not a sinter attribute. Did you mean `data-sn-text`?
10
+
11
+ An attribute starts with `data-sn-` but is not one sinter knows, usually a typo.
12
+
13
+ **Fix:** Use the suggested name. The attributes are listed in `llms.txt` and, in VS Code, completed from `html-custom-data.json`.
14
+
15
+ ## SN102 wrong-element
16
+
17
+ Error, for example:
18
+
19
+ > `data-sn-for` must be on a `<template>`
20
+
21
+ The attribute or element is valid, but not here: lists and conditionals render from a `<template>`, `data-sn-path` belongs on `<html>`, `<sn-event>` inside `<sn-sync>`, and options such as `data-sn-debounce` need a method attribute on the same element.
22
+
23
+ **Fix:** Move it to where the message says, wrapping the content in a `<template>` if needed.
24
+
25
+ ## SN103 missing-key
26
+
27
+ Error, for example:
28
+
29
+ > a `data-sn-for` over primitive values needs `data-sn-key`
30
+
31
+ sinter keys list rows by the resource key or by object identity. Strings and numbers have neither, so rows could not be matched on update.
32
+
33
+ **Fix:** Add `data-sn-key` with an expression that is unique per row, such as the value itself: `data-sn-key="tag"`.
34
+
35
+ ## SN104 unsupported-model
36
+
37
+ Error, for example:
38
+
39
+ > `data-sn-model` does not support `type="file"`; submit the form instead
40
+
41
+ Two-way binding has no meaningful value for this input type.
42
+
43
+ **Fix:** Submit the form with a method attribute (`data-sn-post`, …) on it; a form with a file input is sent as `FormData`.
44
+
45
+ ## SN201 unknown-identifier
46
+
47
+ Error, for example:
48
+
49
+ > `contcts` is not defined here. Did you mean `contacts`?
50
+
51
+ An expression uses a name that is not a loop variable, state field, resource, magic name, helper or JavaScript global in this scope.
52
+
53
+ **Fix:** Fix the typo, declare the name in `data-sn-state`, or export it from the helpers module. Loop variables are only visible inside their `<template>`.
54
+
55
+ ## SN202 forbidden-global
56
+
57
+ Error, for example:
58
+
59
+ > `window` is a browser API; expressions may use JavaScript, not the browser. Use an island
60
+
61
+ Expressions may use JavaScript built-ins but not browser APIs such as `window`, `document`, `fetch` or timers, so pages stay safe under a strict CSP and testable.
62
+
63
+ **Fix:** Move the browser code into a helper (for a pure function) or an island (a custom element that owns imperative work).
64
+
65
+ ## SN203 side-effect
66
+
67
+ Error, for example:
68
+
69
+ > value expressions cannot assign; move this to `data-sn-on-*`
70
+
71
+ A binding that produces a value (`text`, `attr`, `show`, `for`, …) tried to change state, which would run on every render. Path parameters of `$url` are read-only everywhere.
72
+
73
+ **Fix:** Do the assignment in an event handler (`data-sn-on-click`) or in an action's `then`.
74
+
75
+ ## SN204 optimistic-scope
76
+
77
+ Error, for example:
78
+
79
+ > `data-sn-optimistic` may only call `patch`, `upsert`, `remove`
80
+
81
+ An optimistic change is undone when the request fails, so it may only use the store functions that sinter can roll back.
82
+
83
+ **Fix:** Express the change with `patch`, `upsert` or `remove`; set other state in `then`.
84
+
85
+ ## SN205 resource-mutation
86
+
87
+ Error, for example:
88
+
89
+ > `m.is_read = true` mutates a resource. Use `patch('messages', m, {is_read: true})`
90
+
91
+ Resource data is read-only in expressions: it mirrors the server, and a direct write would be lost on the next refresh or event.
92
+
93
+ **Fix:** Use the `patch()` call from the message, or copy the item with `structuredClone(c)` to edit it in state.
94
+
95
+ ## SN206 unknown-namespace-member
96
+
97
+ Error, for example:
98
+
99
+ > `m.inbox_titel` is not exported by namespace `m`. Did you mean `inbox_title`?
100
+
101
+ A helper namespace (for example paraglide messages) has no export of that name.
102
+
103
+ **Fix:** Use the suggested name, or add the export to the namespace module.
104
+
105
+ ## SN207 unsafe-sink
106
+
107
+ Error, for example:
108
+
109
+ > `onclick` cannot be bound with `data-sn-attr`; use `data-sn-on-click`
110
+
111
+ The binding could run script or inject markup from data: event-handler attributes, `style`, `srcdoc`, `innerHTML`, bindings on `<script>` and similar elements, URL templates that do not start with a literal path, or persisted password fields.
112
+
113
+ **Fix:** Use the safe equivalent the message names: `data-sn-on-*` for events, `data-sn-style` for styles, a literal `/path` at the start of a URL template.
114
+
115
+ ## SN208 type-error
116
+
117
+ Error, for example:
118
+
119
+ > Property 'nmae' does not exist on type 'Contact'. (TS2339)
120
+
121
+ TypeScript found a type error in an expression. Reported by `sinter check`, `sinter({ typecheck: true })` and the editor integration.
122
+
123
+ **Fix:** Fix the expression, or the type: `type` on `<sn-resource>`, the OpenAPI spec, or a JSDoc cast in `data-sn-state`.
124
+
125
+ ## SN301 unknown-resource
126
+
127
+ Error, for example:
128
+
129
+ > resource `mesages` is not declared on this page
130
+
131
+ A store call, `$meta` or embedded data (`data-sn-data`) names a resource that no `<sn-resource>` on the page or its partials declares.
132
+
133
+ **Fix:** Fix the name or add the `<sn-resource>` element.
134
+
135
+ ## SN302 duplicate-resource
136
+
137
+ Error, for example:
138
+
139
+ > resource `contacts` is declared twice
140
+
141
+ Two `<sn-resource>` elements on one page share a name, often once in the page and once in a partial.
142
+
143
+ **Fix:** Rename one, or remove the duplicate.
144
+
145
+ ## SN303 unknown-meta-field
146
+
147
+ Error, for example:
148
+
149
+ > `$meta.contacts.loadng` is not a status field. Did you mean `loading`?
150
+
151
+ `$meta.<resource>` has a fixed set of fields: `loading`, `error`, `loadedAt`, `pending`, `total`, and with `paginate` also `pages`, `from`, `to`, `hasPrev`, `hasNext`; `page` with `paginate="offset"`, or keyset with `offset-param`.
152
+
153
+ **Fix:** Use the suggested field. A pagination field needs `paginate` on the resource.
154
+
155
+ ## SN304 keyset-jump
156
+
157
+ Error, for example:
158
+
159
+ > keyset pagination cannot jump to a page number. Add `offset-param` if the server also accepts an offset, or use `paginate="offset"`
160
+
161
+ Keyset (cursor) pagination only knows the next and previous page, so `page('name', 7)` has nothing to jump to, unless the server can also skip items by offset.
162
+
163
+ **Fix:** If the API accepts an offset next to its cursor, add `offset-param="offset"`: the jump is sent as an offset and `prev`/`next` continue by cursor. Otherwise use `paginate="offset"`, or only step with `first`, `prev`, `next` and `last`.
164
+
165
+ ## SN305 include-not-found
166
+
167
+ Error, for example:
168
+
169
+ > partial `./partials/contact-dialg.html` not found or outside the project root
170
+
171
+ The `src` of `<sn-include>` must be a literal path, relative to the including file, that resolves inside the project root.
172
+
173
+ **Fix:** Fix the path. Partials outside the root are refused on purpose.
174
+
175
+ ## SN306 include-cycle
176
+
177
+ Error, for example:
178
+
179
+ > `a.html` → `b.html` → `a.html` includes itself
180
+
181
+ Partials include each other in a cycle.
182
+
183
+ **Fix:** Move the shared part into a third partial that neither includes back.
184
+
185
+ ## SN307 openapi-invalid
186
+
187
+ Error, for example:
188
+
189
+ > OpenAPI spec `api.yml` is not an OpenAPI 3 document (needs `openapi: 3.x` and `paths`)
190
+
191
+ A spec given to `sinter({ openapi })` is missing, unreadable, or not OpenAPI 3.
192
+
193
+ **Fix:** Fix the path in the Vite config, or convert a Swagger 2 spec to OpenAPI 3.
194
+
195
+ ## SN308 unknown-schema-field
196
+
197
+ Error, for example:
198
+
199
+ > the response of `GET /articles` has no `articls`. Did you mean `articles`?
200
+
201
+ The resource matched an operation in the OpenAPI spec, but its `items` or `total` path is not in the response schema.
202
+
203
+ **Fix:** Fix the path in `items` or `total`, or the spec if the API changed.
204
+
205
+ ## SN310 unknown-action
206
+
207
+ Error, for example:
208
+
209
+ > `pgp.decrpyt` is not exported by the actions module. Did you mean `pgp.decrypt`?
210
+
211
+ `data-sn-call` and `<sn-resource call>` name a function the actions module (`src/sinter.actions.js` or `.ts`) exports, directly or through `export * as ns`.
212
+
213
+ **Fix:** Use the suggested name, or export the function from the actions module.
214
+
215
+ ## SN401 parse-error
216
+
217
+ Error, for example:
218
+
219
+ > `data-sn-for` takes `item in list` or `(item, i) in list`
220
+
221
+ An attribute value has the wrong form: a JavaScript syntax error (the column points inside the attribute), or a value outside what the attribute accepts, such as `paginate` or `data-sn-concurrency`.
222
+
223
+ **Fix:** Fix the value as the message says. Handlers are statements separated by `;`; value bindings are a single expression.
224
+
225
+ ## SN501 unused-resource
226
+
227
+ Warning, for example:
228
+
229
+ > resource `addressbooks` is declared but never read
230
+
231
+ The page fetches a resource that nothing on it uses, which costs a request on every load.
232
+
233
+ **Fix:** Remove the `<sn-resource>`, or use it.
234
+
235
+ ## SN502 non-reactive-value
236
+
237
+ Warning, for example:
238
+
239
+ > `Date.now()` in a binding never updates. Use `$now`
240
+
241
+ The binding reads the time or a random number once and is never re-rendered by it.
242
+
243
+ **Fix:** Use `$now`, which sinter updates, or compute the value in a handler.
244
+
245
+ ## SN503 data-bound-id
246
+
247
+ Warning, for example:
248
+
249
+ > `id` bound from data can shadow globals other scripts read (DOM clobbering)
250
+
251
+ An `id` or `name` set from server data can create a global that overrides one another script relies on.
252
+
253
+ **Fix:** Prefix the value (`'contact-' + c.id`) or use a `data-*` attribute instead.
254
+
255
+ ## SN504 untyped-resource
256
+
257
+ Warning, for example:
258
+
259
+ > resource `contacts` has no type: expressions using it are not checked
260
+
261
+ The type checker has no type for the resource, so expressions that use it are not checked. Reported by `sinter check` only.
262
+
263
+ **Fix:** Add `type="Contact[]"` with a type from `src/sinter.types.ts`, configure an OpenAPI spec that matches `src`, load it with `call` (typed by what the action returns), or write `type="any"` to opt out.
264
+
265
+ ## SN505 unknown-query-param
266
+
267
+ Warning, for example:
268
+
269
+ > `GET /articles` declares no query parameter `tagg`. Did you mean `tag`?
270
+
271
+ A literal query parameter in `src` is not declared by the matched OpenAPI operation, usually a typo the server would ignore.
272
+
273
+ **Fix:** Use the suggested name, or add the parameter to the spec.
274
+
275
+ ## SN506 untyped-event
276
+
277
+ Warning, for example:
278
+
279
+ > event `contact_updated` has no type: expressions reading its payload are not checked
280
+
281
+ An `<sn-event>` reads its payload but has no `type`, so those expressions are not checked. Reported by `sinter check` only.
282
+
283
+ **Fix:** Add `type` with a payload type from `src/sinter.types.ts`, or `type="any"` to opt out.
@@ -0,0 +1,250 @@
1
+ {
2
+ "version": 1.1,
3
+ "tags": [
4
+ {
5
+ "name": "sn-resource",
6
+ "description": "a named, page-wide cache of server data; `cache` (or `cache=\"10m\"`) shows the data from the last page load at once, then revalidates",
7
+ "attributes": [
8
+ {
9
+ "name": "name"
10
+ },
11
+ {
12
+ "name": "src"
13
+ },
14
+ {
15
+ "name": "call"
16
+ },
17
+ {
18
+ "name": "each"
19
+ },
20
+ {
21
+ "name": "key"
22
+ },
23
+ {
24
+ "name": "items"
25
+ },
26
+ {
27
+ "name": "total"
28
+ },
29
+ {
30
+ "name": "order"
31
+ },
32
+ {
33
+ "name": "when"
34
+ },
35
+ {
36
+ "name": "paginate"
37
+ },
38
+ {
39
+ "name": "page-size"
40
+ },
41
+ {
42
+ "name": "size-param"
43
+ },
44
+ {
45
+ "name": "cursor"
46
+ },
47
+ {
48
+ "name": "direction-param"
49
+ },
50
+ {
51
+ "name": "direction-values"
52
+ },
53
+ {
54
+ "name": "page-param"
55
+ },
56
+ {
57
+ "name": "offset-param"
58
+ },
59
+ {
60
+ "name": "type"
61
+ },
62
+ {
63
+ "name": "cache"
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ "name": "sn-sync",
69
+ "description": "one server event stream",
70
+ "attributes": [
71
+ {
72
+ "name": "src"
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ "name": "sn-event",
78
+ "description": "maps one server event to a change message; child of <sn-sync>",
79
+ "attributes": [
80
+ {
81
+ "name": "name"
82
+ },
83
+ {
84
+ "name": "resource"
85
+ },
86
+ {
87
+ "name": "op"
88
+ },
89
+ {
90
+ "name": "item"
91
+ },
92
+ {
93
+ "name": "set"
94
+ },
95
+ {
96
+ "name": "when"
97
+ },
98
+ {
99
+ "name": "fallback"
100
+ },
101
+ {
102
+ "name": "type"
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ "name": "sn-include",
108
+ "description": "inlines a partial at build time",
109
+ "attributes": [
110
+ {
111
+ "name": "src"
112
+ }
113
+ ]
114
+ }
115
+ ],
116
+ "globalAttributes": [
117
+ {
118
+ "name": "data-sn-state",
119
+ "description": "declares local reactive state for the element and its subtree (object literal)"
120
+ },
121
+ {
122
+ "name": "data-sn-text",
123
+ "description": "sets textContent; never HTML (value expression)"
124
+ },
125
+ {
126
+ "name": "data-sn-attr",
127
+ "description": "literal keys; null/false removes, true sets empty; URL values are checked (object literal {href: …})"
128
+ },
129
+ {
130
+ "name": "data-sn-class",
131
+ "description": "toggles each class (object literal {unread: …})"
132
+ },
133
+ {
134
+ "name": "data-sn-style",
135
+ "description": "sets each property with style.setProperty (object literal {'--color': …})"
136
+ },
137
+ {
138
+ "name": "data-sn-show",
139
+ "description": "toggles the hidden attribute (value expression)"
140
+ },
141
+ {
142
+ "name": "data-sn-prop",
143
+ "description": "sets JS properties; custom elements only (object literal)"
144
+ },
145
+ {
146
+ "name": "data-sn-model",
147
+ "description": "two-way binding for form controls (state path)"
148
+ },
149
+ {
150
+ "name": "data-sn-for",
151
+ "description": "repeats a <template> per item (item in list | (item, i) in list)"
152
+ },
153
+ {
154
+ "name": "data-sn-key",
155
+ "description": "row identity; defaults to the resource key or object identity (value expression)"
156
+ },
157
+ {
158
+ "name": "data-sn-if",
159
+ "description": "renders a <template> while truthy (value expression)"
160
+ },
161
+ {
162
+ "name": "data-sn-else",
163
+ "description": "on a <template> directly after an if template"
164
+ },
165
+ {
166
+ "name": "data-sn-persist",
167
+ "description": "persists the model or state in localStorage under sn: (storage key)"
168
+ },
169
+ {
170
+ "name": "data-sn-get",
171
+ "description": "GET action; latest wins (URL template)"
172
+ },
173
+ {
174
+ "name": "data-sn-post",
175
+ "description": "POST action (URL template)"
176
+ },
177
+ {
178
+ "name": "data-sn-put",
179
+ "description": "PUT action (URL template)"
180
+ },
181
+ {
182
+ "name": "data-sn-patch",
183
+ "description": "PATCH action (URL template)"
184
+ },
185
+ {
186
+ "name": "data-sn-delete",
187
+ "description": "DELETE action (URL template)"
188
+ },
189
+ {
190
+ "name": "data-sn-call",
191
+ "description": "local action: calls a function from the actions module, e.g. pgp.decrypt(msg) (action call)"
192
+ },
193
+ {
194
+ "name": "data-sn-body",
195
+ "description": "JSON request body; overrides form serialization (value expression)"
196
+ },
197
+ {
198
+ "name": "data-sn-trigger",
199
+ "description": "overrides the default trigger (DOM event name)"
200
+ },
201
+ {
202
+ "name": "data-sn-debounce",
203
+ "description": "delays the trigger, resets on each event; without a method, delays the element's data-sn-on-* handlers (milliseconds)"
204
+ },
205
+ {
206
+ "name": "data-sn-concurrency",
207
+ "description": "mutations only; default block for forms, queue otherwise (block | queue | latest)"
208
+ },
209
+ {
210
+ "name": "data-sn-optimistic",
211
+ "description": "patch/upsert/remove calls applied before the request, rolled back on failure (handler expression)"
212
+ },
213
+ {
214
+ "name": "data-sn-then",
215
+ "description": "runs after a 2xx response; $result = parsed body (handler expression)"
216
+ },
217
+ {
218
+ "name": "data-sn-catch",
219
+ "description": "runs after an error; $error = {status, body, message} (handler expression)"
220
+ },
221
+ {
222
+ "name": "data-sn-path",
223
+ "description": "on <html>: the path shapes this page is served for; `:name` segments appear read-only in $url (URL patterns /a/:b …)"
224
+ },
225
+ {
226
+ "name": "data-sn-data",
227
+ "description": "on <script type=\"application/json\"> in <head>: initial data for a resource (resource name)"
228
+ },
229
+ {
230
+ "name": "data-sn-on-click",
231
+ "description": "plain event handler, no request; e.g. data-sn-on-click"
232
+ },
233
+ {
234
+ "name": "data-sn-on-input",
235
+ "description": "plain event handler, no request; e.g. data-sn-on-click"
236
+ },
237
+ {
238
+ "name": "data-sn-on-change",
239
+ "description": "plain event handler, no request; e.g. data-sn-on-click"
240
+ },
241
+ {
242
+ "name": "data-sn-on-submit",
243
+ "description": "plain event handler, no request; e.g. data-sn-on-click"
244
+ },
245
+ {
246
+ "name": "data-sn-on-keydown",
247
+ "description": "plain event handler, no request; e.g. data-sn-on-click"
248
+ }
249
+ ]
250
+ }