@alecsibilia/oxlint-plugin-ui-kit 0.1.0-alpha.0 → 0.1.0-alpha.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/rules/live-room-authorize.js +11 -5
- package/src/rules/no-hardcoded-route-strings.js +27 -2
- package/src/rules/no-public-cache-with-session.js +40 -13
- package/src/rules/no-raw-websocket.js +1 -1
- package/src/rules/use-server-decodes-input.js +1 -1
- package/src/rules/writes-only-via-mutations.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @alecsibilia/oxlint-plugin-ui-kit
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b994db9: The UI kit's public functions now take one object argument instead of positional arguments (luca's coding standard), for example `hrefFor({ table, route })`, `navigate({ href, replace })`, `createQueryRegistry({ id, queries })`, `ctx.mutate({ mutation, input, toMessage })` and `runRead({ policy, program })`. Key names are the old parameter names. Kept positional on purpose: `update`-shaped functions (`updateRouter(model, msg)`), `story(update, init)`, `matchTag(value, handlers)`, callbacks whose shape a platform fixes (Solid's `handleNoJS`, the Worker route), and single-argument functions. The lint plugin's `no-public-cache-with-session`, `live-room-authorize` and `no-hardcoded-route-strings` rules read the new call shapes.
|
|
8
|
+
|
|
9
|
+
Migration: wrap the arguments in an object named after the parameters, e.g. `roomRef(LIVE_ROOMS, 'plan', id)` becomes `roomRef({ decl: LIVE_ROOMS, type: 'plan', key: id })`, and `every(1000, toMessage, { key })` becomes `every({ ms: 1000, toMessage, key })` (trailing option objects are spread into the one object). The PR lists every changed signature.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bd22a9f: Publish the UI kit and its lint plugin to npm from the release workflow, with the same trusted publishing as `@alecsibilia/luca`. Add `@alecsibilia/ui-kit/test/solid-preload`, a Bun preload that compiles the kit's Solid JSX, so plain Bun (such as `bun test`) can import the view subpaths from the published package.
|
|
14
|
+
|
|
3
15
|
## 0.1.0-alpha.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alecsibilia/oxlint-plugin-ui-kit",
|
|
3
3
|
"description": "oxlint rules for apps built on @alecsibilia/ui-kit: dumb views, pure models, layer-first folders and their imports, snake_case schemas",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Alec Sibilia <sibilia.alec@gmail.com>",
|
|
7
7
|
"homepage": "https://github.com/asibilia/luca-framework/tree/main/packages/oxlint-plugin-ui-kit#readme",
|
|
@@ -4,9 +4,11 @@ import { calleeName, isFunction, unwrap } from '../ast.js'
|
|
|
4
4
|
* Live rooms (framework-rules.md, "Multiplayer"): permissions are a
|
|
5
5
|
* framework hook, not a fixed policy. Every room type the app wires up
|
|
6
6
|
* supplies `authorize(user, room, action)`. The kit API
|
|
7
|
-
* (`@alecsibilia/ui-kit/live/server`): `createLiveRooms(
|
|
8
|
-
* types: { page: { authorize, key }, plan: {
|
|
9
|
-
*
|
|
7
|
+
* (`@alecsibilia/ui-kit/live/server`): `createLiveRooms({ decl: LIVE_ROOMS,
|
|
8
|
+
* hooks: { resolveUser, types: { page: { authorize, key }, plan: {
|
|
9
|
+
* authorize, docs } } } })`.
|
|
10
|
+
* Checked: the hooks of a room factory call (its `hooks` property, or its
|
|
11
|
+
* options object when it has none; option `factories`;
|
|
10
12
|
* default `createLiveRooms`, plus `createRoomObject` / `defineRoom` /
|
|
11
13
|
* `defineLiveRoom` for single-room helpers), and any object literal typed
|
|
12
14
|
* as the hooks (option `hookTypes`; default `LiveRoomsHooks`: `const hooks:
|
|
@@ -144,11 +146,15 @@ export default {
|
|
|
144
146
|
CallExpression: (node) => {
|
|
145
147
|
const factory = calleeName(node.callee)
|
|
146
148
|
if (!factories.has(factory)) return
|
|
147
|
-
const
|
|
149
|
+
const first = node.arguments
|
|
148
150
|
.map(unwrap)
|
|
149
151
|
.find((a) => a?.type === 'ObjectExpression')
|
|
152
|
+
// The kit's object form: `{ decl, hooks }`; the hooks are
|
|
153
|
+
// checked when inline, else where they are declared (typed hooks).
|
|
154
|
+
const hooksProp = first && findProperty(first, 'hooks')
|
|
155
|
+
const options = hooksProp ? unwrap(hooksProp.value) : first
|
|
150
156
|
// An identifier argument is checked where it is declared (typed hooks).
|
|
151
|
-
if (
|
|
157
|
+
if (options?.type !== 'ObjectExpression') return
|
|
152
158
|
const name = node.arguments
|
|
153
159
|
.map(unwrap)
|
|
154
160
|
.find(
|
|
@@ -15,8 +15,9 @@ import { calleeName, unwrap } from '../ast.js'
|
|
|
15
15
|
* (`"/architecture"`, `` `/characters/${id}` `` against
|
|
16
16
|
* `/characters/:characterId`);
|
|
17
17
|
* - any literal starting with `/` given to a navigation sink: a JSX
|
|
18
|
-
* `href` / `to` attribute,
|
|
19
|
-
* `
|
|
18
|
+
* `href` / `to` attribute, the first argument of `pushUrl`, `redirect`
|
|
19
|
+
* or `Response.redirect`, or the `href` of the kit's
|
|
20
|
+
* `navigate({ href })` (or a first argument of `navigate`).
|
|
20
21
|
*
|
|
21
22
|
* The route table is the nearest `routes.ts` above the linted file (or the
|
|
22
23
|
* `routesFile` option, resolved from the working directory); its paths are
|
|
@@ -30,6 +31,8 @@ import { calleeName, unwrap } from '../ast.js'
|
|
|
30
31
|
const ROUTES_FILE = 'routes.ts'
|
|
31
32
|
const PATH_ENTRY = /\bpath\s*:\s*(["'])(\/[^"'\n]*)\1/g
|
|
32
33
|
const SINKS = new Set(['pushUrl', 'navigate', 'redirect'])
|
|
34
|
+
/** Sinks that take `{ href }` (the kit's `navigate`). */
|
|
35
|
+
const OBJECT_SINKS = new Set(['navigate'])
|
|
33
36
|
const JSX_SINKS = new Set(['href', 'to'])
|
|
34
37
|
|
|
35
38
|
const tableCache = new Map()
|
|
@@ -91,6 +94,28 @@ const isSink = (node) => {
|
|
|
91
94
|
const name = calleeName(parent.callee)
|
|
92
95
|
return name !== undefined && SINKS.has(name)
|
|
93
96
|
}
|
|
97
|
+
// The kit's object form: `navigate({ href: "/x" })`.
|
|
98
|
+
if (
|
|
99
|
+
parent?.type === 'Property' &&
|
|
100
|
+
parent.value === target &&
|
|
101
|
+
(parent.key?.name ?? parent.key?.value) === 'href'
|
|
102
|
+
) {
|
|
103
|
+
let object = parent.parent
|
|
104
|
+
let call = object?.parent
|
|
105
|
+
while (
|
|
106
|
+
call &&
|
|
107
|
+
(call.type === 'TSAsExpression' ||
|
|
108
|
+
call.type === 'TSSatisfiesExpression')
|
|
109
|
+
) {
|
|
110
|
+
object = call
|
|
111
|
+
call = call.parent
|
|
112
|
+
}
|
|
113
|
+
return (
|
|
114
|
+
call?.type === 'CallExpression' &&
|
|
115
|
+
call.arguments[0] === object &&
|
|
116
|
+
OBJECT_SINKS.has(calleeName(call.callee))
|
|
117
|
+
)
|
|
118
|
+
}
|
|
94
119
|
return false
|
|
95
120
|
}
|
|
96
121
|
|
|
@@ -35,11 +35,11 @@ import {
|
|
|
35
35
|
* `_tag: "Private"` / `private: true` / `scope: "private"` beside it.
|
|
36
36
|
*
|
|
37
37
|
* The kit also forces `private, no-store` at runtime when a read touched
|
|
38
|
-
* the session (`readCacheHeaders(..., { sessionRead })`); this rule makes
|
|
38
|
+
* the session (`readCacheHeaders({ ..., read: { sessionRead } })`); this rule makes
|
|
39
39
|
* the contradiction visible where the policy is declared.
|
|
40
40
|
*
|
|
41
41
|
* The read it belongs to is the nearest enclosing: entry of a
|
|
42
|
-
* `createQueryRegistry(
|
|
42
|
+
* `createQueryRegistry({ id, queries })` `queries` object, `GET(...)` / `query(...)` call, or
|
|
43
43
|
* top-level statement. That read uses `Session` when the identifier
|
|
44
44
|
* `Session` is referenced in it, in a same-file top-level declaration it
|
|
45
45
|
* references (transitively), or in the declaration of a name it imports
|
|
@@ -47,7 +47,8 @@ import {
|
|
|
47
47
|
* following its own relative imports up to three files deep).
|
|
48
48
|
*
|
|
49
49
|
* A read runner call (option `readRunners`, default `runRead`) whose
|
|
50
|
-
* argument is a table entry
|
|
50
|
+
* `policy` (or any argument) is a table entry
|
|
51
|
+
* (`runRead({ policy: READ_CACHE.loadPlan, program })`) is
|
|
51
52
|
* checked too: the entry is looked up by key in the table's source (this
|
|
52
53
|
* file, or a relative import), and is public when it is a public helper
|
|
53
54
|
* call (`shared(60, 300, ...)`) or a `{ _tag: "Shared" }` object.
|
|
@@ -94,11 +95,38 @@ export default {
|
|
|
94
95
|
)
|
|
95
96
|
const policies = []
|
|
96
97
|
const runnerCalls = []
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
// An entry of `createQueryRegistry({ id, queries: { ... } })`.
|
|
99
|
+
const isRegistryEntry = (node) => {
|
|
100
|
+
if (
|
|
101
|
+
node.type !== 'Property' ||
|
|
102
|
+
node.parent?.type !== 'ObjectExpression'
|
|
103
|
+
)
|
|
104
|
+
return false
|
|
105
|
+
const queries = node.parent.parent
|
|
106
|
+
if (
|
|
107
|
+
queries?.type !== 'Property' ||
|
|
108
|
+
(queries.key?.name ?? queries.key?.value) !== 'queries'
|
|
109
|
+
)
|
|
110
|
+
return false
|
|
111
|
+
const call = queries.parent?.parent
|
|
112
|
+
return (
|
|
113
|
+
call?.type === 'CallExpression' &&
|
|
114
|
+
calleeName(call.callee) === 'createQueryRegistry'
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
// A runner's arguments: the values of its one object argument
|
|
118
|
+
// (`runRead({ policy, program })`), else its positional arguments.
|
|
119
|
+
const argsOf = (call) => {
|
|
120
|
+
const first = unwrap(call.arguments[0])
|
|
121
|
+
if (
|
|
122
|
+
call.arguments.length === 1 &&
|
|
123
|
+
first?.type === 'ObjectExpression'
|
|
124
|
+
)
|
|
125
|
+
return first.properties
|
|
126
|
+
.filter((p) => p.type === 'Property')
|
|
127
|
+
.map((p) => p.value)
|
|
128
|
+
return call.arguments
|
|
129
|
+
}
|
|
102
130
|
const isReadCall = (node) =>
|
|
103
131
|
node.type === 'CallExpression' &&
|
|
104
132
|
['GET', 'query'].includes(calleeName(node.callee))
|
|
@@ -225,7 +253,7 @@ export default {
|
|
|
225
253
|
data: { via },
|
|
226
254
|
})
|
|
227
255
|
}
|
|
228
|
-
// `runRead(
|
|
256
|
+
// `runRead({ policy: TABLE.key, program })`: the policy lives in a table (this
|
|
229
257
|
// file or a relative import); look its entry up by key.
|
|
230
258
|
const sourceText = context.sourceCode?.getText?.() ?? ''
|
|
231
259
|
const entryText = (object, key) => {
|
|
@@ -244,7 +272,8 @@ export default {
|
|
|
244
272
|
return imp ? tableEntryText(imp.path, key) : undefined
|
|
245
273
|
}
|
|
246
274
|
for (const call of runnerCalls) {
|
|
247
|
-
const
|
|
275
|
+
const args = argsOf(call)
|
|
276
|
+
const publicArg = args.find((arg) => {
|
|
248
277
|
const a = unwrap(arg)
|
|
249
278
|
if (policySet.has(a)) return false // inline: reported above
|
|
250
279
|
if (
|
|
@@ -262,9 +291,7 @@ export default {
|
|
|
262
291
|
)
|
|
263
292
|
})
|
|
264
293
|
if (!publicArg) continue
|
|
265
|
-
const program =
|
|
266
|
-
(arg) => arg !== publicArg
|
|
267
|
-
)
|
|
294
|
+
const program = args.filter((arg) => arg !== publicArg)
|
|
268
295
|
let via
|
|
269
296
|
for (const arg of program) {
|
|
270
297
|
via = sessionVia(arg)
|
|
@@ -32,7 +32,7 @@ export default {
|
|
|
32
32
|
'App code opens no raw `WebSocket`; use kit subscriptions (`channel`, `presence`) and live rooms.',
|
|
33
33
|
},
|
|
34
34
|
messages: {
|
|
35
|
-
socket: 'Raw `WebSocket` in app code. Subscribe from a model (`subscriptions: [channel(url, decode, toMessage)]`) or use a kit live room; the kit owns reconnects, sharing and teardown.',
|
|
35
|
+
socket: 'Raw `WebSocket` in app code. Subscribe from a model (`subscriptions: [channel({ url, decode, toMessage })]`) or use a kit live room; the kit owns reconnects, sharing and teardown.',
|
|
36
36
|
},
|
|
37
37
|
schema: [],
|
|
38
38
|
},
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
* What counts as decoding: the first statement that mentions a parameter must
|
|
19
19
|
* pass that parameter straight into either
|
|
20
20
|
* - a decoder: any call whose callee (or curried callee, as in
|
|
21
|
-
* `Schema.decodeUnknownSync(S)(raw)` / `decodeInput(S, "x")(raw)`) is named
|
|
21
|
+
* `Schema.decodeUnknownSync(S)(raw)` / `decodeInput({ schema: S, what: "x" })(raw)`) is named
|
|
22
22
|
* `decode*`, or is listed in `options.decoders`; or
|
|
23
23
|
* - a delegate: a call whose callee name matches one of `options.delegates`
|
|
24
24
|
* (regexes, default `["Program$"]`), e.g. `getPlanProgram(raw)`.
|
|
@@ -72,7 +72,7 @@ export default {
|
|
|
72
72
|
serverImport:
|
|
73
73
|
'`{{source}}` is a `"use server"` module. Only `*.queries.ts` / `*.mutations.ts` registries import server functions; read through a query registry (`<Query>`) and write through a mutation registry (`mutate(...)`).',
|
|
74
74
|
perform:
|
|
75
|
-
'`perform` is kit-internal. Command handlers only `mutate(registry.key, input)` or `Refetch(registry.key)`, so every write goes through the mutation registry and invalidates its queries.',
|
|
75
|
+
'`perform` is kit-internal. Command handlers only `mutate({ mutation: registry.key, input, toMessage })` or `Refetch(registry.key)`, so every write goes through the mutation registry and invalidates its queries.',
|
|
76
76
|
},
|
|
77
77
|
schema: [],
|
|
78
78
|
},
|