@fabrika/check 0.9.0-dev.15 → 0.9.0-dev.16
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 +6 -6
- package/src/endpoint-fixtures.ts +16 -7
- package/src/scaffold.ts +11 -2
- package/types/src/endpoint-fixtures.d.ts +3 -0
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.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,11 +47,11 @@
|
|
|
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.16",
|
|
51
|
+
"@fabrika/auth-core": "0.9.0-dev.16",
|
|
52
|
+
"@fabrika/db": "0.9.0-dev.16",
|
|
53
|
+
"@fabrika/operations-contract": "0.9.0-dev.16",
|
|
54
|
+
"@fabrika/platform-node": "0.9.0-dev.16",
|
|
55
55
|
"zod": "^3.25.76"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/endpoint-fixtures.ts
CHANGED
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
// (a package a handler inspects), by input field, relative to the application's root; `refusals` the error types of the
|
|
11
11
|
// 400s an endpoint's handler answers its own object with when no fixture can meet its domain rule, which the kit then
|
|
12
12
|
// counts as the handler's answer; `pins` known values of text columns of the row an endpoint addresses (a skill's slug a
|
|
13
|
-
// package must name), the own scope's, which the kit writes there instead of a marker
|
|
13
|
+
// package must name), the own scope's, which the kit writes there instead of a marker; `callerRows` the rows of
|
|
14
|
+
// application tables the caller of every global case holds (a person's card bound to the account), by table, a column
|
|
15
|
+
// valued `fabrika:caller` getting the caller's id, which the kit seeds before each global case asks.
|
|
14
16
|
// Read from source, never executed, within the reader's budget: `export const fixtures = { '<endpoint id>': { … } }`,
|
|
15
17
|
// `export const seeds = { '<endpoint id>': { <column>: <value> } }`, `export const members = { '<endpoint id>':
|
|
16
18
|
// ['<field>'] }` (`invitations`, `links` alike), `export const rows = { '<endpoint id>': { <field>: '<table>' } }` and
|
|
17
19
|
// `export const appRows = { '<endpoint id>': { <table>: { <column>: <value> } } }`, `export const files = { '<endpoint
|
|
18
20
|
// id>': { <field>: '<path>' } }`, `export const refusals = { '<endpoint id>': ['<error type>'] }` and `export const pins
|
|
19
|
-
// = { '<endpoint id>': { <column>: '<value>' } }`,
|
|
21
|
+
// = { '<endpoint id>': { <column>: '<value>' } }`, and `export const callerRows = { <table>: { <column>: <value> } }`,
|
|
22
|
+
// plain literals only.
|
|
20
23
|
// Browser-safe.
|
|
21
24
|
|
|
22
25
|
import { type AstNode, child, children, identifierName, nodeDepth, parseModule, positionOf, staticKey, staticString } from './ast'
|
|
@@ -35,6 +38,7 @@ export const APP_ROWS_EXPORT = 'appRows'
|
|
|
35
38
|
export const FILES_EXPORT = 'files'
|
|
36
39
|
export const REFUSALS_EXPORT = 'refusals'
|
|
37
40
|
export const PINS_EXPORT = 'pins'
|
|
41
|
+
export const CALLER_ROWS_EXPORT = 'callerRows'
|
|
38
42
|
|
|
39
43
|
/** The exports that list strings by endpoint id: the input fields the kit fills with something it holds, and the refusals. */
|
|
40
44
|
const FIELD_EXPORTS = [MEMBERS_EXPORT, INVITATIONS_EXPORT, LINKS_EXPORT, REFUSALS_EXPORT] as const
|
|
@@ -42,7 +46,7 @@ type FieldExport = (typeof FIELD_EXPORTS)[number]
|
|
|
42
46
|
const isFieldExport = (name: string | undefined): name is FieldExport => FIELD_EXPORTS.some((field) => field === name)
|
|
43
47
|
|
|
44
48
|
const ALLOWED =
|
|
45
|
-
"export const fixtures = { 'api.notes.get': { id: '…' } }, export const seeds = { 'api.deals.reopen': { stage: 'won' } }, export const members = { 'api.deals.assign': ['ownerId'] }, export const invitations = { 'api.members.cancel': ['invitationId'] }, export const links = { 'api.notes.unshare': ['linkId'] }, export const rows = { 'api.notes.editComment': { commentId: 'note_comments' } }, export const appRows = { 'portal.guide': { guides: { active: true } } }, export const files = { 'api.skills.publish': { package: 'src/__tests__/fixtures/skill.zip' } }, export const refusals = { 'api.skills.publish': ['skill_frontmatter'] } and export const pins = { 'api.skills.publish': { slug: 'sample-skill' } }: string keys, and strings, numbers, booleans, null, arrays and objects"
|
|
49
|
+
"export const fixtures = { 'api.notes.get': { id: '…' } }, export const seeds = { 'api.deals.reopen': { stage: 'won' } }, export const members = { 'api.deals.assign': ['ownerId'] }, export const invitations = { 'api.members.cancel': ['invitationId'] }, export const links = { 'api.notes.unshare': ['linkId'] }, export const rows = { 'api.notes.editComment': { commentId: 'note_comments' } }, export const appRows = { 'portal.guide': { guides: { active: true } } }, export const files = { 'api.skills.publish': { package: 'src/__tests__/fixtures/skill.zip' } }, export const refusals = { 'api.skills.publish': ['skill_frontmatter'] } and export const pins = { 'api.skills.publish': { slug: 'sample-skill' } } and export const callerRows = { people: { principal_id: 'fabrika:caller' } }: string keys, and strings, numbers, booleans, null, arrays and objects"
|
|
46
50
|
|
|
47
51
|
type ById = Readonly<Record<string, Readonly<Record<string, Sample>>>>
|
|
48
52
|
|
|
@@ -67,6 +71,8 @@ export interface EndpointFixtures {
|
|
|
67
71
|
readonly refusals: Readonly<Record<string, readonly string[]>>
|
|
68
72
|
/** The own scope's value of each pinned text column of the row the endpoint addresses, by endpoint id. */
|
|
69
73
|
readonly pins: Readonly<Record<string, Readonly<Record<string, string>>>>
|
|
74
|
+
/** The rows of application tables the caller of every global case holds, by table, each with its columns. */
|
|
75
|
+
readonly callerRows: Readonly<Record<string, Readonly<Record<string, Sample>>>>
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
export const NO_FIXTURES: EndpointFixtures = {
|
|
@@ -80,6 +86,7 @@ export const NO_FIXTURES: EndpointFixtures = {
|
|
|
80
86
|
files: {},
|
|
81
87
|
refusals: {},
|
|
82
88
|
pins: {},
|
|
89
|
+
callerRows: {},
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
/**
|
|
@@ -151,13 +158,14 @@ function byId(
|
|
|
151
158
|
const value = literal(init)
|
|
152
159
|
if (!value.ok) return { ok: false, findings: [finding(value.at, 'not a plain literal')] }
|
|
153
160
|
const all = value.value
|
|
161
|
+
const keyed = name === CALLER_ROWS_EXPORT ? 'table' : 'endpoint id'
|
|
154
162
|
if (!isSampleObject(all)) {
|
|
155
|
-
return { ok: false, findings: [finding(init, `the ${name} are an object keyed by
|
|
163
|
+
return { ok: false, findings: [finding(init, `the ${name} are an object keyed by ${keyed}`)] }
|
|
156
164
|
}
|
|
157
165
|
const entries: Record<string, Readonly<Record<string, Sample>>> = {}
|
|
158
166
|
for (const [id, entry] of Object.entries(all)) {
|
|
159
167
|
if (!isSampleObject(entry)) {
|
|
160
|
-
const of = name === SEEDS_EXPORT ? 'columns' : name === APP_ROWS_EXPORT ? 'tables' : 'input fields'
|
|
168
|
+
const of = name === SEEDS_EXPORT || name === CALLER_ROWS_EXPORT ? 'columns' : name === APP_ROWS_EXPORT ? 'tables' : 'input fields'
|
|
161
169
|
return { ok: false, findings: [finding(init, `the ${name} of ${id} is not an object of ${of}`)] }
|
|
162
170
|
}
|
|
163
171
|
entries[id] = entry
|
|
@@ -224,7 +232,7 @@ export function readEndpointFixtures(
|
|
|
224
232
|
if (
|
|
225
233
|
statement?.type !== 'ExportNamedDeclaration' || declarator === null || declarator === undefined
|
|
226
234
|
|| (name !== FIXTURES_EXPORT && name !== SEEDS_EXPORT && name !== ROWS_EXPORT && name !== APP_ROWS_EXPORT && name !== FILES_EXPORT
|
|
227
|
-
&& name !== PINS_EXPORT && !isFieldExport(name))
|
|
235
|
+
&& name !== PINS_EXPORT && name !== CALLER_ROWS_EXPORT && !isFieldExport(name))
|
|
228
236
|
|| read.has(name)
|
|
229
237
|
|| (isFieldExport(name) && fields.has(name))
|
|
230
238
|
) {
|
|
@@ -233,7 +241,7 @@ export function readEndpointFixtures(
|
|
|
233
241
|
findings: [
|
|
234
242
|
finding(
|
|
235
243
|
statement ?? undefined,
|
|
236
|
-
`the file holds export const ${FIXTURES_EXPORT}, ${SEEDS_EXPORT}, ${MEMBERS_EXPORT}, ${INVITATIONS_EXPORT}, ${LINKS_EXPORT}, ${ROWS_EXPORT}, ${APP_ROWS_EXPORT}, ${FILES_EXPORT}, ${REFUSALS_EXPORT} and ${
|
|
244
|
+
`the file holds export const ${FIXTURES_EXPORT}, ${SEEDS_EXPORT}, ${MEMBERS_EXPORT}, ${INVITATIONS_EXPORT}, ${LINKS_EXPORT}, ${ROWS_EXPORT}, ${APP_ROWS_EXPORT}, ${FILES_EXPORT}, ${REFUSALS_EXPORT}, ${PINS_EXPORT} and ${CALLER_ROWS_EXPORT} = { … }, each at most once`,
|
|
237
245
|
),
|
|
238
246
|
],
|
|
239
247
|
}
|
|
@@ -296,6 +304,7 @@ export function readEndpointFixtures(
|
|
|
296
304
|
]),
|
|
297
305
|
),
|
|
298
306
|
pins: stringsById(read.get(PINS_EXPORT) ?? {}),
|
|
307
|
+
callerRows: read.get(CALLER_ROWS_EXPORT) ?? {},
|
|
299
308
|
files: Object.fromEntries(
|
|
300
309
|
Object.entries(read.get(FILES_EXPORT) ?? {}).map(([id, named]) => [
|
|
301
310
|
id,
|
package/src/scaffold.ts
CHANGED
|
@@ -364,8 +364,8 @@ const testedEndpoints = (artifact: ContractArtifact): ReadonlySet<string> =>
|
|
|
364
364
|
const ROOT_FROM_ENDPOINT_TEST = '../'.repeat(ENDPOINT_ACCESS_TEST.split('/').length - 1)
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
|
-
* The options of the generated test's kit: the file fixtures of the tested endpoints, each a URL beside the test
|
|
368
|
-
* without any, so a test without
|
|
367
|
+
* The options of the generated test's kit: the file fixtures of the tested endpoints, each a URL beside the test, their
|
|
368
|
+
* refusals and pins, and the caller rows. Empty without any, so a test without them stays as it was.
|
|
369
369
|
*/
|
|
370
370
|
const kitOptions = (fixtures: EndpointFixtures, tested: ReadonlySet<string>): string => {
|
|
371
371
|
const files = Object.entries(fixtures.files).sort(byKey).flatMap(([id, fields]) => {
|
|
@@ -388,6 +388,7 @@ const kitOptions = (fixtures: EndpointFixtures, tested: ReadonlySet<string>): st
|
|
|
388
388
|
...(files.length === 0 ? [] : [`files: { ${files.join(', ')} }`]),
|
|
389
389
|
...(refusals.length === 0 ? [] : [`refusals: { ${refusals.join(', ')} }`]),
|
|
390
390
|
...(pins.length === 0 ? [] : [`pins: { ${pins.join(', ')} }`]),
|
|
391
|
+
...(Object.keys(fixtures.callerRows).length === 0 ? [] : [`callerRows: ${renderSample(fixtures.callerRows)}`]),
|
|
391
392
|
]
|
|
392
393
|
return options.length === 0 ? '' : `, { ${options.join(', ')} }`
|
|
393
394
|
}
|
|
@@ -917,6 +918,14 @@ export const missingEndpointFixtures = ({ tables, policies, artifact, fixtures }
|
|
|
917
918
|
findings.push(at(`${id}: ${applicationRowRefusalText(refusal)}`, appRowAllowed(refusal)))
|
|
918
919
|
}
|
|
919
920
|
}
|
|
921
|
+
for (const refusal of applicationRowsPlan(tables, fixtures.callerRows).refusals) {
|
|
922
|
+
findings.push(
|
|
923
|
+
at(
|
|
924
|
+
`callerRows: ${applicationRowRefusalText(refusal)}`,
|
|
925
|
+
refusal.kind === 'table' ? 'the name of a table with scope: { app } in src/db/tables.ts' : appRowAllowed(refusal),
|
|
926
|
+
),
|
|
927
|
+
)
|
|
928
|
+
}
|
|
920
929
|
for (const [id, fields] of Object.entries(fixtures.files).sort(byKey)) {
|
|
921
930
|
const row = tested.find((candidate) => candidate.id === id)
|
|
922
931
|
if (row === undefined) {
|
|
@@ -10,6 +10,7 @@ export declare const APP_ROWS_EXPORT = "appRows";
|
|
|
10
10
|
export declare const FILES_EXPORT = "files";
|
|
11
11
|
export declare const REFUSALS_EXPORT = "refusals";
|
|
12
12
|
export declare const PINS_EXPORT = "pins";
|
|
13
|
+
export declare const CALLER_ROWS_EXPORT = "callerRows";
|
|
13
14
|
type ById = Readonly<Record<string, Readonly<Record<string, Sample>>>>;
|
|
14
15
|
export interface EndpointFixtures {
|
|
15
16
|
/** The input each endpoint's cases send, by endpoint id. */
|
|
@@ -32,6 +33,8 @@ export interface EndpointFixtures {
|
|
|
32
33
|
readonly refusals: Readonly<Record<string, readonly string[]>>;
|
|
33
34
|
/** The own scope's value of each pinned text column of the row the endpoint addresses, by endpoint id. */
|
|
34
35
|
readonly pins: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
36
|
+
/** The rows of application tables the caller of every global case holds, by table, each with its columns. */
|
|
37
|
+
readonly callerRows: Readonly<Record<string, Readonly<Record<string, Sample>>>>;
|
|
35
38
|
}
|
|
36
39
|
export declare const NO_FIXTURES: EndpointFixtures;
|
|
37
40
|
/**
|