@fabrika/check 0.9.0-dev.10 → 0.9.0-dev.12
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 +7 -7
- package/src/check.ts +34 -14
- package/src/reader/surface.ts +4 -2
- package/src/rules/runtime.ts +27 -5
- package/src/scaffold.ts +86 -13
- package/types/src/rules/runtime.d.ts +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/check",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"typecheck": "
|
|
45
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
46
46
|
"test": "bun test"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@babel/parser": "8.0.7",
|
|
50
|
-
"@fabrika/app": "0.9.0-dev.
|
|
51
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
52
|
-
"@fabrika/db": "0.9.0-dev.
|
|
53
|
-
"@fabrika/operations-contract": "0.9.0-dev.
|
|
54
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
50
|
+
"@fabrika/app": "0.9.0-dev.12",
|
|
51
|
+
"@fabrika/auth-core": "0.9.0-dev.12",
|
|
52
|
+
"@fabrika/db": "0.9.0-dev.12",
|
|
53
|
+
"@fabrika/operations-contract": "0.9.0-dev.12",
|
|
54
|
+
"@fabrika/platform-node": "0.9.0-dev.12",
|
|
55
55
|
"zod": "^3.25.76"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/check.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AnyContract, compileContract, ContractError } from '@fabrika/app/contract'
|
|
2
|
-
import type
|
|
2
|
+
import { type ContractArtifact, egressAdmits, type EgressEntry, parseEgressEntry } from '@fabrika/auth-core'
|
|
3
3
|
import { type TablePolicies, tablePolicies, type Tables } from '@fabrika/db/tables'
|
|
4
4
|
import { readdir, readFile } from 'node:fs/promises'
|
|
5
5
|
import { join } from 'node:path'
|
|
@@ -95,8 +95,8 @@ export const readApplicationTree = async (root: string): Promise<ApplicationTree
|
|
|
95
95
|
|
|
96
96
|
/** The findings a module rule leaves until the contract is read: they depend on what it declares. */
|
|
97
97
|
interface ContractDependent {
|
|
98
|
-
/** Each `fetch` of an absolute URL, with its static prefix. */
|
|
99
|
-
readonly fetches: { readonly target: string; readonly finding: Finding }[]
|
|
98
|
+
/** Each `fetch` of an absolute URL, with its static prefix and its labelled authority (`absoluteFetch`). */
|
|
99
|
+
readonly fetches: { readonly target: string; readonly labelled: string | undefined; readonly finding: Finding }[]
|
|
100
100
|
/** Each `ctx.url` with a literal endpoint id. */
|
|
101
101
|
readonly urls: { readonly endpoint: string; readonly finding: Finding }[]
|
|
102
102
|
/** Each insert with literal `onConflict.columns`, checked against the migrations' unique indexes. */
|
|
@@ -146,9 +146,9 @@ const checkSourceModule = async (
|
|
|
146
146
|
isGeneratedEntry,
|
|
147
147
|
rawSql: rawSqlBindings(module.program),
|
|
148
148
|
isServerModule: isServerModule(module.file),
|
|
149
|
-
absoluteFetch: (node: AstNode, target: string) => {
|
|
149
|
+
absoluteFetch: (node: AstNode, target: string, labelled: string | undefined) => {
|
|
150
150
|
const { message, allowed } = crossAppFetchMessage(target)
|
|
151
|
-
for (const finding of deferred(node, 'cross-app-fetch', message, allowed)) dependent.fetches.push({ target, finding })
|
|
151
|
+
for (const finding of deferred(node, 'cross-app-fetch', message, allowed)) dependent.fetches.push({ target, labelled, finding })
|
|
152
152
|
},
|
|
153
153
|
appUrl: (node: AstNode, endpoint: string) => {
|
|
154
154
|
const message = `ctx.url names '${endpoint}', which is no procedure of the contract`
|
|
@@ -189,7 +189,7 @@ const URL_ENDPOINT_ALLOWED = "the id of a procedure of the contract: ctx.url('<m
|
|
|
189
189
|
/** What the module rules that wait for the contract compare against: its procedure ids and every declared origin. */
|
|
190
190
|
interface CompiledReach {
|
|
191
191
|
readonly procedures: ReadonlySet<string>
|
|
192
|
-
readonly
|
|
192
|
+
readonly egress: readonly EgressEntry[]
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
/** The contract's artifact, or `null` when it does not compile, which its own rule reports. */
|
|
@@ -209,24 +209,44 @@ const compiledReach = (artifact: ContractArtifact): CompiledReach => {
|
|
|
209
209
|
)
|
|
210
210
|
return {
|
|
211
211
|
procedures: new Set(procedures.map((row) => row.id)),
|
|
212
|
-
|
|
212
|
+
egress: Object.values(artifact.declared ?? {}).flatMap((reach) =>
|
|
213
|
+
(reach.egress ?? []).flatMap((value) => {
|
|
214
|
+
const parsed = parseEgressEntry(value)
|
|
215
|
+
return parsed.ok ? [parsed.entry] : []
|
|
216
|
+
})
|
|
217
|
+
),
|
|
213
218
|
}
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
/**
|
|
217
222
|
* A `fetch` of an absolute URL stands when no site declares its origin (a static prefix that ends inside the host is
|
|
218
|
-
* not accepted
|
|
219
|
-
* compiles and names no such procedure. The runtime guard on `fetch`
|
|
223
|
+
* not accepted, nor an interpolated label a pattern does not cover), and every one stands when the contract does not
|
|
224
|
+
* compile. A `ctx.url` stands when the contract compiles and names no such procedure. The runtime guard on `fetch`
|
|
225
|
+
* still checks the site that runs.
|
|
220
226
|
*/
|
|
221
227
|
const contractDependentFindings = (dependent: ContractDependent, reach: CompiledReach | null): Finding[] => [
|
|
222
|
-
...dependent.fetches.filter((
|
|
223
|
-
finding
|
|
224
|
-
),
|
|
228
|
+
...dependent.fetches.filter((fetch) => reach === null || !isDeclaredFetch(fetch, reach.egress)).map(({ finding }) => finding),
|
|
225
229
|
...(reach === null ? [] : dependent.urls.filter(({ endpoint }) => !reach.procedures.has(endpoint)).map(({ finding }) => finding)),
|
|
226
230
|
]
|
|
227
231
|
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
/** The static prefix names its whole authority, which an entry admits, or the labelled authority is a pattern's own. */
|
|
233
|
+
const isDeclaredFetch = (fetch: { readonly target: string; readonly labelled: string | undefined }, egress: readonly EgressEntry[]): boolean => {
|
|
234
|
+
const authority = /^https:\/\/[^/?#]+[/?#]/.exec(fetch.target)?.[0]
|
|
235
|
+
const url = authority === undefined ? null : urlOf(authority)
|
|
236
|
+
if (url !== null && egressAdmits(egress, url)) return true
|
|
237
|
+
// The interpolated label as a placeholder one, so the authority normalizes as the runtime's URL will; exact
|
|
238
|
+
// origins stay out, as no literal label is known.
|
|
239
|
+
const labelled = fetch.labelled === undefined ? null : urlOf(`https://${fetch.labelled.replace('*', 'label')}/`)
|
|
240
|
+
return labelled !== null && egressAdmits(egress.filter((entry) => entry.kind === 'pattern'), labelled)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const urlOf = (value: string): URL | null => {
|
|
244
|
+
try {
|
|
245
|
+
return new URL(value)
|
|
246
|
+
} catch {
|
|
247
|
+
return null
|
|
248
|
+
}
|
|
249
|
+
}
|
|
230
250
|
|
|
231
251
|
/** Runs every rule over one application and returns the findings in file, line and column order. */
|
|
232
252
|
export const checkApplication = async (input: CheckInput): Promise<Finding[]> => {
|
package/src/reader/surface.ts
CHANGED
|
@@ -597,7 +597,7 @@ class SurfaceReader {
|
|
|
597
597
|
// ── Sections ────────────────────────────────────────────────────────────────────────────────
|
|
598
598
|
|
|
599
599
|
/**
|
|
600
|
-
* `c.files({ … })`: a kind of stored file. Every option but `types`, `maxBytes` and `
|
|
600
|
+
* `c.files({ … })`: a kind of stored file. Every option but `types`, `maxBytes`, `scan` and `inline` is unknown, as the kit
|
|
601
601
|
* records it, so `buildArtifact` refuses a file collection's `owner` in its own words.
|
|
602
602
|
*/
|
|
603
603
|
#files(value: LiteralValue, form: Form): FileKind {
|
|
@@ -606,11 +606,13 @@ class SurfaceReader {
|
|
|
606
606
|
const [kind] = args(at, 'c.files', 1, 1)
|
|
607
607
|
const options = builderOptions(kind, at, 'c.files')
|
|
608
608
|
const scan = options.get('scan')
|
|
609
|
+
const inline = options.get('inline')
|
|
609
610
|
return {
|
|
610
611
|
kind: 'file-kind',
|
|
611
612
|
types: texts(options.get('types'), at, 'types'),
|
|
612
613
|
maxBytes: numeric(options.get('maxBytes'), at, 'maxBytes'),
|
|
613
614
|
scan: scan === undefined ? undefined : boolean(scan, 'scan'),
|
|
615
|
+
inline: inline === undefined ? undefined : boolean(inline, 'inline'),
|
|
614
616
|
unknownOptions: optionKeys(options, 'fileKind'),
|
|
615
617
|
}
|
|
616
618
|
}
|
|
@@ -799,7 +801,7 @@ function plain(value: LiteralValue | undefined): unknown {
|
|
|
799
801
|
}
|
|
800
802
|
|
|
801
803
|
const DECLARED_ALLOWED =
|
|
802
|
-
"sql: 'read' | 'write', unscoped: { <table>: 'read' | 'write' }, connect: ['<import>'], issues: '<link mount>', mailer: 'installation' | 'own', kicks: ['<cron job>'], binds: '<webhook>', signs: ['<token purpose>'], egress: ['https://<host>']"
|
|
804
|
+
"sql: 'read' | 'write', unscoped: { <table>: 'read' | 'write' }, connect: ['<import>'], issues: '<link mount>', mailer: 'installation' | 'own', kicks: ['<cron job>'], binds: '<webhook>', signs: ['<token purpose>'], egress: ['https://<host>' | 'https://*.<domain>']"
|
|
803
805
|
|
|
804
806
|
/** A builder of the kit read as the `defineContract` builder of the same name, which builds the same declaration. */
|
|
805
807
|
const asSurface = (builder: BuilderValue): LiteralValue => ({
|
package/src/rules/runtime.ts
CHANGED
|
@@ -28,8 +28,11 @@ export interface SourceContext {
|
|
|
28
28
|
readonly rawSql: ReadonlySet<string>
|
|
29
29
|
/** A module under `src/` that is not a test: it reaches no global object and no `Bun` at all. */
|
|
30
30
|
readonly isServerModule: boolean
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* A `fetch` of an absolute URL, by its static prefix and, for a template whose first label alone is interpolated, its
|
|
33
|
+
* authority with that label as `*`: refused once the contract shows that no site declares its origin in `egress`.
|
|
34
|
+
*/
|
|
35
|
+
readonly absoluteFetch: (node: AstNode, target: string, labelled: string | undefined) => void
|
|
33
36
|
/** A `ctx.url('<endpoint id>', …)` with a literal id: refused once the contract shows that it names no procedure. */
|
|
34
37
|
readonly appUrl: (node: AstNode, endpoint: string) => void
|
|
35
38
|
/** A `<table>.insert(values, { onConflict: { columns } })`: refused once the migrations show no unique index of them. */
|
|
@@ -130,10 +133,28 @@ const staticPrefix = (node: AstNode | undefined): string | undefined => {
|
|
|
130
133
|
const ABSOLUTE_URL = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i
|
|
131
134
|
const LOCAL_SCHEMES = /^(?:data|blob):/i
|
|
132
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The authority of `https://${label}.<domain>…` with the interpolated label as `*` (`*.<domain>[:port]`), when the
|
|
138
|
+
* template's static text after it reaches the path, query or fragment; the runtime guard checks the label itself.
|
|
139
|
+
*/
|
|
140
|
+
const labelledAuthority = (node: AstNode | undefined): string | undefined => {
|
|
141
|
+
if (node === undefined) return undefined
|
|
142
|
+
if (node.type === 'NewExpression' && ['URL', 'Request'].includes(identifierName(child(node, 'callee')) ?? '')) {
|
|
143
|
+
return labelledAuthority(argumentAt(node, 0))
|
|
144
|
+
}
|
|
145
|
+
if (node.type !== 'TemplateLiteral') return undefined
|
|
146
|
+
const [head, next] = children(node, 'quasis')
|
|
147
|
+
if (!head || !next || templateText(head).cooked !== 'https://') return undefined
|
|
148
|
+
const rest = templateText(next).cooked ?? ''
|
|
149
|
+
const end = rest.search(/[/?#]/)
|
|
150
|
+
return rest.startsWith('.') && end > 1 ? `*${rest.slice(0, end)}` : undefined
|
|
151
|
+
}
|
|
152
|
+
|
|
133
153
|
const checkFetch = (node: AstNode, path: readonly string[], context: SourceContext): void => {
|
|
134
|
-
const
|
|
154
|
+
const argument = invokedArgument(node, path, 'fetch')
|
|
155
|
+
const target = staticPrefix(argument)
|
|
135
156
|
if (target === undefined || !ABSOLUTE_URL.test(target) || LOCAL_SCHEMES.test(target)) return
|
|
136
|
-
context.absoluteFetch(node, target)
|
|
157
|
+
context.absoluteFetch(node, target, labelledAuthority(argument))
|
|
137
158
|
}
|
|
138
159
|
|
|
139
160
|
/** `ctx.url('<endpoint id>', …)`, also on a `ctx` reached through a member (`args.ctx.url`). */
|
|
@@ -177,7 +198,8 @@ const propertyValue = (object: AstNode, name: string): AstNode | undefined => {
|
|
|
177
198
|
/** The finding of a `fetch` of an absolute URL whose origin no site of the contract declares. */
|
|
178
199
|
export const crossAppFetchMessage = (target: string): { readonly message: string; readonly allowed: string } => ({
|
|
179
200
|
message: `fetch to the absolute origin '${target}' is a hand-written integration`,
|
|
180
|
-
allowed:
|
|
201
|
+
allowed:
|
|
202
|
+
"a same-origin path to a declared endpoint, another application through a connector import, or egress: ['<origin>' | 'https://*.<domain>'] on the site",
|
|
181
203
|
})
|
|
182
204
|
|
|
183
205
|
const checkDynamicCode = (node: AstNode, path: readonly string[], context: SourceContext): void => {
|
package/src/scaffold.ts
CHANGED
|
@@ -9,9 +9,11 @@ import {
|
|
|
9
9
|
GENERATED_INVITATION,
|
|
10
10
|
GENERATED_LINK,
|
|
11
11
|
GENERATED_MEMBER,
|
|
12
|
+
GENERATED_ROW_CAPABILITY,
|
|
12
13
|
GENERATED_ROW_PREFIX,
|
|
13
14
|
} from '@fabrika/app/contract'
|
|
14
15
|
import {
|
|
16
|
+
type AccessForm,
|
|
15
17
|
type ContractArtifact,
|
|
16
18
|
endpointDirectory,
|
|
17
19
|
endpointMembers,
|
|
@@ -249,7 +251,8 @@ const policyTestBody = (
|
|
|
249
251
|
dialect: ApplicationDialect,
|
|
250
252
|
): { readonly body: string; readonly cases: readonly string[] } | undefined => {
|
|
251
253
|
const policy = policies[table]
|
|
252
|
-
|
|
254
|
+
// A view's rows come from the tables it reads, so no probe seeds one; its parent's cases still run.
|
|
255
|
+
if (policy === undefined || policy.view === true) return undefined
|
|
253
256
|
const app = policy.scope.mode === 'app'
|
|
254
257
|
const dimension = grantDimension(policies, policy)
|
|
255
258
|
if (dimension === undefined && !app) return undefined
|
|
@@ -304,7 +307,8 @@ const isLinkProcedure = (row: EndpointRow): boolean =>
|
|
|
304
307
|
* The input an endpoint's cases send: the author's fixture, else a sample of its schema; `undefined` when neither
|
|
305
308
|
* exists. Each field its `members`, `invitations` or `links` name holds `GENERATED_MEMBER`, `GENERATED_INVITATION` or
|
|
306
309
|
* `GENERATED_LINK`, which the kit replaces with a real member, an open invitation or a link it issued; each field its
|
|
307
|
-
* `rows` name holds `GENERATED_ROW_PREFIX` and the table,
|
|
310
|
+
* `rows` name holds `GENERATED_ROW_PREFIX` and the table (and, under `<endpoint id>#<capability>`, the capability), which
|
|
311
|
+
* the kit replaces with the key of a row it seeded; each file
|
|
308
312
|
* field its `files` name holds its kind's marker (in a list, for a list of files), even where the sample left an optional
|
|
309
313
|
* one out, which the kit sends as the named file.
|
|
310
314
|
*/
|
|
@@ -320,6 +324,11 @@ const inputOf = (row: EndpointRow, fixtures: EndpointFixtures): Readonly<Record<
|
|
|
320
324
|
...generated(fixtures.invitations[row.id], GENERATED_INVITATION),
|
|
321
325
|
...generated(fixtures.links[row.id], GENERATED_LINK),
|
|
322
326
|
...Object.entries(fixtures.rows[row.id] ?? {}).map(([field, table]) => [field, `${GENERATED_ROW_PREFIX}${table}`]),
|
|
327
|
+
...Object.keys(row.requirement?.kind === 'capabilities' ? row.requirement.capabilities : {}).flatMap((name) =>
|
|
328
|
+
Object.entries(fixtures.rows[`${row.id}${CAPABILITY_KEY}${name}`] ?? {}).map((
|
|
329
|
+
[field, table],
|
|
330
|
+
) => [field, `${GENERATED_ROW_PREFIX}${table}${GENERATED_ROW_CAPABILITY}${name}`])
|
|
331
|
+
),
|
|
323
332
|
...Object.keys(fixtures.files[row.id] ?? {}).flatMap((field) => {
|
|
324
333
|
const file = fileFieldOf(row.input, field)
|
|
325
334
|
if (file === undefined) return []
|
|
@@ -330,6 +339,9 @@ const inputOf = (row: EndpointRow, fixtures: EndpointFixtures): Readonly<Record<
|
|
|
330
339
|
}
|
|
331
340
|
}
|
|
332
341
|
|
|
342
|
+
/** What separates an endpoint id from a capability's name in a `rows` key: `api.tasks.copy#from`. */
|
|
343
|
+
const CAPABILITY_KEY = '#'
|
|
344
|
+
|
|
333
345
|
/** The file kind of a top-level file field of `input` (a file, an optional or nullable one, or a list of them), or `undefined`. */
|
|
334
346
|
const fileFieldOf = (input: SchemaShape | null, field: string): { readonly kind: string; readonly list: boolean } | undefined => {
|
|
335
347
|
const kindOf = (shape: SchemaShape | undefined): string | undefined =>
|
|
@@ -421,6 +433,29 @@ const liesDirectlyIn = (policies: Policies, table: string, dimension: string): b
|
|
|
421
433
|
return parent?.mode === 'dimension' && parent.dimension === dimension
|
|
422
434
|
}
|
|
423
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Whether a list of `dimension` (`over`) reaches the rows of `table`: a dimension table it contains or of its own when it
|
|
438
|
+
* has no container, or a child of one.
|
|
439
|
+
*/
|
|
440
|
+
const listedBy = (policies: Policies, table: string, dimension: string): boolean => {
|
|
441
|
+
const listedIn = (scope: Policies[string]['scope'] | undefined): string | undefined =>
|
|
442
|
+
scope?.mode === 'dimension' ? (scope.container?.dimension ?? scope.dimension) : undefined
|
|
443
|
+
const scope = policies[table]?.scope
|
|
444
|
+
return (scope?.mode === 'child' ? listedIn(policies[scope.parent]?.scope) : listedIn(scope)) === dimension
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Whether the kit seeds a row of `table` for an endpoint of `access`: in its object (`on`, `in` an object a table owns,
|
|
449
|
+
* the table lying directly in it) or in the scopes it lists (`over`).
|
|
450
|
+
*/
|
|
451
|
+
const rowPlace = (policies: Policies, access: ScopedAccess, table: string): boolean =>
|
|
452
|
+
access.form === 'over'
|
|
453
|
+
? listedBy(policies, table, access.dimension)
|
|
454
|
+
: ownerRead(policies, access.dimension) !== undefined && liesDirectlyIn(policies, table, access.dimension)
|
|
455
|
+
|
|
456
|
+
/** An access form that names a scope: an object (`on`), a value (`in`) or a list (`over`). */
|
|
457
|
+
type ScopedAccess = Extract<AccessForm, { readonly form: 'on' | 'in' | 'over' }>
|
|
458
|
+
|
|
424
459
|
/** The read action of the table that owns `dimension`, or `undefined` when no table owns it. */
|
|
425
460
|
const ownerRead = (policies: Policies, dimension: string): string | undefined =>
|
|
426
461
|
tableActions(
|
|
@@ -714,6 +749,23 @@ const appRowAllowed = (refusal: ApplicationRowRefusal): string => {
|
|
|
714
749
|
}
|
|
715
750
|
}
|
|
716
751
|
|
|
752
|
+
/** The finding of a `rows` table the kit seeds no row of for an endpoint of `access`, and its allowed form. */
|
|
753
|
+
const unplacedRow = (policies: Policies, id: string, table: string, access: ScopedAccess): readonly [string, string] => {
|
|
754
|
+
if (access.form === 'over') {
|
|
755
|
+
return [
|
|
756
|
+
`${id}: a list of ${access.dimension} reaches no ${table} row, so the kit seeds none in the scopes it lists`,
|
|
757
|
+
`a dimension table whose container is ${access.dimension}, or a child table of one`,
|
|
758
|
+
]
|
|
759
|
+
}
|
|
760
|
+
if (ownerRead(policies, access.dimension) === undefined) {
|
|
761
|
+
return [`${id}: no table owns ${access.dimension}, so the kit seeds no ${table} row in one`, `an endpoint on or in a dimension a table owns`]
|
|
762
|
+
}
|
|
763
|
+
return [
|
|
764
|
+
`${id}: ${table} is no dimension or child table that lies directly in a ${access.dimension}, so the kit seeds none in the endpoint's object (it seeds no container between)`,
|
|
765
|
+
`a child table of the table that owns ${access.dimension}, or a dimension table whose container is ${access.dimension}`,
|
|
766
|
+
]
|
|
767
|
+
}
|
|
768
|
+
|
|
717
769
|
/** What the scaffold reads from an application's files; throws `ContractSourceError` or `ContractError` as the reader does. */
|
|
718
770
|
export const scaffoldInputs = (files: ReadonlyMap<string, string>): ScaffoldInputs => {
|
|
719
771
|
const tables = readTablesDefinition(files)
|
|
@@ -803,29 +855,50 @@ export const missingEndpointFixtures = ({ tables, policies, artifact, fixtures }
|
|
|
803
855
|
}
|
|
804
856
|
}
|
|
805
857
|
}
|
|
806
|
-
for (const [
|
|
858
|
+
for (const [key, fields] of Object.entries(fixtures.rows).sort(byKey)) {
|
|
859
|
+
const split = key.indexOf(CAPABILITY_KEY)
|
|
860
|
+
const id = split === -1 ? key : key.slice(0, split)
|
|
861
|
+
const named = split === -1 ? null : key.slice(split + 1)
|
|
807
862
|
const row = tested.find((candidate) => candidate.id === id)
|
|
808
|
-
const
|
|
809
|
-
const
|
|
810
|
-
|
|
863
|
+
const requirement = row?.requirement
|
|
864
|
+
const severalCapabilities = requirement?.kind === 'capabilities'
|
|
865
|
+
const access = requirement?.kind === 'action' && named === null
|
|
866
|
+
? requirement.access
|
|
867
|
+
: requirement?.kind === 'capabilities' && named !== null && Object.hasOwn(requirement.capabilities, named)
|
|
868
|
+
? requirement.capabilities[named]?.access
|
|
869
|
+
: undefined
|
|
870
|
+
const scope = access?.form === 'on' || access?.form === 'in' || access?.form === 'over' ? access : undefined
|
|
871
|
+
if (row === undefined || scope === undefined) {
|
|
811
872
|
findings.push(
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
873
|
+
severalCapabilities && named === null
|
|
874
|
+
? at(
|
|
875
|
+
`${id} has several capabilities, so its rows name the one whose scope they lie in`,
|
|
876
|
+
`export const rows = { '${id}${CAPABILITY_KEY}<capability>': { <input field>: '<table>' } }`,
|
|
877
|
+
)
|
|
878
|
+
: named !== null
|
|
879
|
+
? at(
|
|
880
|
+
`${key} names no capability of a tested endpoint with several, in whose scope the kit could seed a row`,
|
|
881
|
+
`export const rows = { '<endpoint id>${CAPABILITY_KEY}<capability>': { <input field>: '<table>' } }, a capability of the endpoint`,
|
|
882
|
+
)
|
|
883
|
+
: at(
|
|
884
|
+
`${id} is no tested endpoint on, in or over a scope, in which the kit could seed a row`,
|
|
885
|
+
"export const rows = { '<endpoint id>': { <input field>: '<table>' } }, for an endpoint on, in or over a dimension",
|
|
886
|
+
),
|
|
816
887
|
)
|
|
817
888
|
continue
|
|
818
889
|
}
|
|
819
890
|
for (const [field, table] of Object.entries(fields).sort(byKey)) {
|
|
820
891
|
if (row.input?.type !== 'object' || !admitsString(row.input.fields[field])) {
|
|
821
892
|
findings.push(at(`${id}: ${field} is no string field of its input, so it cannot name a row`, 'a top-level string field of the input'))
|
|
822
|
-
} else if (
|
|
893
|
+
} else if (policies[table]?.view === true) {
|
|
823
894
|
findings.push(
|
|
824
895
|
at(
|
|
825
|
-
`${id}: ${
|
|
826
|
-
|
|
896
|
+
`${id}: ${field} names the view ${table}, whose rows the kit cannot seed: they come from the tables it reads`,
|
|
897
|
+
'a row field that names a table the view reads',
|
|
827
898
|
),
|
|
828
899
|
)
|
|
900
|
+
} else if (!rowPlace(policies, scope, table)) {
|
|
901
|
+
findings.push(at(...unplacedRow(policies, id, table, scope)))
|
|
829
902
|
}
|
|
830
903
|
}
|
|
831
904
|
}
|
|
@@ -8,8 +8,11 @@ export interface SourceContext {
|
|
|
8
8
|
readonly rawSql: ReadonlySet<string>;
|
|
9
9
|
/** A module under `src/` that is not a test: it reaches no global object and no `Bun` at all. */
|
|
10
10
|
readonly isServerModule: boolean;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A `fetch` of an absolute URL, by its static prefix and, for a template whose first label alone is interpolated, its
|
|
13
|
+
* authority with that label as `*`: refused once the contract shows that no site declares its origin in `egress`.
|
|
14
|
+
*/
|
|
15
|
+
readonly absoluteFetch: (node: AstNode, target: string, labelled: string | undefined) => void;
|
|
13
16
|
/** A `ctx.url('<endpoint id>', …)` with a literal id: refused once the contract shows that it names no procedure. */
|
|
14
17
|
readonly appUrl: (node: AstNode, endpoint: string) => void;
|
|
15
18
|
/** A `<table>.insert(values, { onConflict: { columns } })`: refused once the migrations show no unique index of them. */
|