cvx-kit 0.1.3 → 0.1.5
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 +33 -0
- package/README.md +81 -24
- package/dist/agent-tools.d.mts +28 -12
- package/dist/agent-tools.mjs +1 -1
- package/dist/agent-tools.mjs.map +1 -1
- package/dist/auth.d.mts +4 -2
- package/dist/auth.mjs +1 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/components/approvals/_generated/api.d.mts +1 -1
- package/dist/components/approvals/audit.mjs +1 -1
- package/dist/components/approvals/audit.mjs.map +1 -1
- package/dist/components/approvals/client.d.mts +1 -1
- package/dist/components/approvals/client.mjs +1 -1
- package/dist/components/approvals/client.mjs.map +1 -1
- package/dist/components/approvals/constants.mjs.map +1 -1
- package/dist/components/approvals/decisions.d.mts +6 -7
- package/dist/components/approvals/decisions.mjs +1 -1
- package/dist/components/approvals/decisions.mjs.map +1 -1
- package/dist/components/approvals/functions.mjs +1 -1
- package/dist/components/approvals/functions.mjs.map +1 -1
- package/dist/components/approvals/health.mjs.map +1 -1
- package/dist/components/approvals/requests.mjs.map +1 -1
- package/dist/components/approvals/validators.mjs.map +1 -1
- package/dist/components/approvals/workflow.mjs +1 -1
- package/dist/components/approvals/workflow.mjs.map +1 -1
- package/dist/components/approvals/workflow_steps.d.mts +3 -3
- package/dist/components/approvals/workflow_steps.mjs +1 -1
- package/dist/components/approvals/workflow_steps.mjs.map +1 -1
- package/dist/components/foundation/client.d.mts +17 -24
- package/dist/components/foundation/client.mjs +1 -1
- package/dist/components/foundation/client.mjs.map +1 -1
- package/dist/components/foundation/modules/command/command.d.mts +4 -4
- package/dist/components/foundation/modules/command/command.mjs.map +1 -1
- package/dist/components/foundation/modules/observability/observability.d.mts +1 -1
- package/dist/components/foundation/modules/observability/observability.mjs +1 -1
- package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
- package/dist/components/foundation/modules/query/query.d.mts +8 -8
- package/dist/components/foundation/modules/query/query.mjs +1 -1
- package/dist/components/foundation/modules/query/query.mjs.map +1 -1
- package/dist/components/foundation/operation.d.mts +1 -1
- package/dist/components/foundation/operation.mjs.map +1 -1
- package/dist/components/foundation/result.d.mts +1 -1
- package/dist/components/foundation/result.mjs.map +1 -1
- package/dist/components/foundation/telemetry.mjs +1 -1
- package/dist/components/foundation/telemetry.mjs.map +1 -1
- package/dist/crud.d.mts +177 -16
- package/dist/crud.mjs +1 -1
- package/dist/crud.mjs.map +1 -1
- package/dist/middleware.d.mts +7 -7
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/oxlint.d.mts +8 -0
- package/dist/oxlint.mjs +2 -0
- package/dist/oxlint.mjs.map +1 -0
- package/dist/tenancy.mjs +1 -1
- package/dist/tenancy.mjs.map +1 -1
- package/dist/triggers.mjs +1 -1
- package/dist/triggers.mjs.map +1 -1
- package/dist/webhooks.d.mts +17 -106
- package/dist/webhooks.mjs.map +1 -1
- package/dist/zod-table.d.mts +46 -90
- package/dist/zod-table.mjs +1 -1
- package/dist/zod-table.mjs.map +1 -1
- package/docs/approvals.md +57 -56
- package/docs/architecture.md +1 -1
- package/docs/auth.md +57 -33
- package/docs/commands.md +53 -53
- package/docs/conventions.md +40 -40
- package/docs/crud.md +5 -5
- package/docs/llms.md +120 -71
- package/docs/maintainability.md +4 -4
- package/docs/migration.md +33 -33
- package/docs/oxlint.md +98 -0
- package/docs/tenancy.md +5 -8
- package/docs/triggers.md +4 -2
- package/docs/upgrading.md +47 -7
- package/docs/zod-table.md +48 -45
- package/package.json +33 -22
- package/scripts/convex-config-bridge.mjs +7 -18
- package/scripts/smoke-packed-components.mjs +20 -61
- package/scripts/test-packed-ids.mjs +16 -24
- package/scripts/test-packed-oxlint.mjs +141 -0
- package/src/test.ts +8 -17
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert'
|
|
2
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
3
|
+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { rules } from '../dist/oxlint.mjs'
|
|
7
|
+
|
|
8
|
+
const root = join(import.meta.dirname, '..')
|
|
9
|
+
const temporary = mkdtempSync(join(tmpdir(), 'cvx-kit-oxlint-'))
|
|
10
|
+
const manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
11
|
+
const ruleNames = Object.keys(rules)
|
|
12
|
+
assert.equal(ruleNames.length, 15)
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
run('bun', ['pm', 'pack', '--destination', temporary, '--ignore-scripts'], root)
|
|
16
|
+
for (const installer of ['npm', 'bun']) {
|
|
17
|
+
const fixture = join(temporary, installer)
|
|
18
|
+
mkdirSync(join(fixture, 'convex/components/example'), { recursive: true })
|
|
19
|
+
mkdirSync(join(fixture, 'convex/api'), { recursive: true })
|
|
20
|
+
mkdirSync(join(fixture, 'convex/domain/orders'), { recursive: true })
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(fixture, 'package.json'),
|
|
23
|
+
JSON.stringify({
|
|
24
|
+
private: true,
|
|
25
|
+
type: 'module',
|
|
26
|
+
dependencies: {
|
|
27
|
+
'cvx-kit': `file:${join(temporary, `cvx-kit-${manifest.version}.tgz`)}`,
|
|
28
|
+
convex: manifest.devDependencies.convex,
|
|
29
|
+
'convex-helpers': manifest.devDependencies['convex-helpers'],
|
|
30
|
+
zod: manifest.devDependencies.zod,
|
|
31
|
+
},
|
|
32
|
+
devDependencies: { oxlint: manifest.devDependencies.oxlint },
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
run(installer, ['install', '--ignore-scripts'], fixture)
|
|
36
|
+
writeFileSync(
|
|
37
|
+
join(fixture, '.oxlintrc.json'),
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
jsPlugins: [{ name: 'cvx', specifier: 'cvx-kit/oxlint' }],
|
|
40
|
+
rules: Object.fromEntries(ruleNames.map((name) => [`cvx/${name}`, 'error'])),
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
writeFileSync(
|
|
44
|
+
join(fixture, 'convex/api/orders.ts'),
|
|
45
|
+
"import { authMutation } from '../functions'; import { executeSaveOrder } from '../domain/orders/commands'; export const save = authMutation({ handler: (ctx, args) => executeSaveOrder(ctx, args) })\n",
|
|
46
|
+
)
|
|
47
|
+
writeFileSync(
|
|
48
|
+
join(fixture, 'convex/components/example/client.ts'),
|
|
49
|
+
'export function run() { return 1 }\n',
|
|
50
|
+
)
|
|
51
|
+
const oxlint = join(fixture, 'node_modules/.bin/oxlint')
|
|
52
|
+
run(oxlint, ['--config', '.oxlintrc.json', 'convex'], fixture)
|
|
53
|
+
writeFileSync(
|
|
54
|
+
join(fixture, 'convex/components/example/bad.ts'),
|
|
55
|
+
`
|
|
56
|
+
import { defineTable } from 'convex/server'
|
|
57
|
+
import { host } from '../../host'
|
|
58
|
+
function helper() { return process.env.SECRET }
|
|
59
|
+
const privateHelper = () => helper()
|
|
60
|
+
export const table = defineTable({})
|
|
61
|
+
export { host }
|
|
62
|
+
export const value = privateHelper()
|
|
63
|
+
`,
|
|
64
|
+
)
|
|
65
|
+
writeFileSync(
|
|
66
|
+
join(fixture, 'convex/host.ts'),
|
|
67
|
+
"import { authMutation } from './functions'; export const save = authMutation({}); export const host = 1; import './components/example/bad'\n",
|
|
68
|
+
)
|
|
69
|
+
writeFileSync(
|
|
70
|
+
join(fixture, 'convex/api/orders.ts'),
|
|
71
|
+
`import { mutation } from '../_generated/server'
|
|
72
|
+
import { makeFunctionReference as ref } from 'convex/server'
|
|
73
|
+
import { z } from 'zod'
|
|
74
|
+
import { createAuthFunctions } from 'cvx-kit/auth'
|
|
75
|
+
import { other } from '../domain/users/commands'
|
|
76
|
+
export const save = mutation({ handler: async (ctx) => {
|
|
77
|
+
await ctx.db.insert('orders', { updatedAt: Date.now() })
|
|
78
|
+
return ctx.db.query('orders').collect()
|
|
79
|
+
}})
|
|
80
|
+
export const constructors = createAuthFunctions({})
|
|
81
|
+
export const state = z.enum(['draft'])
|
|
82
|
+
export const target = ref('orders:save')
|
|
83
|
+
export const value = other
|
|
84
|
+
`,
|
|
85
|
+
)
|
|
86
|
+
const invalid = spawnSync(
|
|
87
|
+
oxlint,
|
|
88
|
+
['--config', '.oxlintrc.json', '--format', 'json', 'convex'],
|
|
89
|
+
{
|
|
90
|
+
cwd: fixture,
|
|
91
|
+
encoding: 'utf8',
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
assert.ifError(invalid.error)
|
|
95
|
+
assert.equal(invalid.status, 1, invalid.stderr)
|
|
96
|
+
const diagnostics = JSON.parse(invalid.stdout).diagnostics
|
|
97
|
+
for (const name of ruleNames) {
|
|
98
|
+
assert.ok(
|
|
99
|
+
diagnostics.some((item) => item.code === `cvx(${name})`),
|
|
100
|
+
`${installer}: missing ${name}: ${invalid.stdout}`,
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
writeFileSync(
|
|
104
|
+
join(fixture, 'plugin-types.ts'),
|
|
105
|
+
`
|
|
106
|
+
import plugin, { rules, type RuleName } from 'cvx-kit/oxlint'
|
|
107
|
+
import type { Plugin, Rule } from '@oxlint/plugins'
|
|
108
|
+
const compatible: Plugin = plugin
|
|
109
|
+
const name: RuleName = 'component-boundaries'
|
|
110
|
+
const rule: Rule = rules[name]
|
|
111
|
+
void compatible
|
|
112
|
+
void rule
|
|
113
|
+
`,
|
|
114
|
+
)
|
|
115
|
+
run(
|
|
116
|
+
join(root, 'node_modules/.bin/tsc'),
|
|
117
|
+
[
|
|
118
|
+
'--noEmit',
|
|
119
|
+
'--strict',
|
|
120
|
+
'--skipLibCheck',
|
|
121
|
+
'--target',
|
|
122
|
+
'es2025',
|
|
123
|
+
'--module',
|
|
124
|
+
'esnext',
|
|
125
|
+
'--moduleResolution',
|
|
126
|
+
'bundler',
|
|
127
|
+
'plugin-types.ts',
|
|
128
|
+
],
|
|
129
|
+
fixture,
|
|
130
|
+
)
|
|
131
|
+
console.log(
|
|
132
|
+
`${installer}: packed Oxlint plugin loads, all consumer rules report, and declarations typecheck`,
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
} finally {
|
|
136
|
+
rmSync(temporary, { recursive: true, force: true })
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function run(command, args, cwd) {
|
|
140
|
+
return execFileSync(command, args, { cwd, encoding: 'utf8', stdio: 'pipe' })
|
|
141
|
+
}
|
package/src/test.ts
CHANGED
|
@@ -6,30 +6,21 @@
|
|
|
6
6
|
* registers the COMPILED component modules from dist, so dist is the only
|
|
7
7
|
* code the package ships.
|
|
8
8
|
*/
|
|
9
|
+
import type { TestConvex } from 'convex-test'
|
|
9
10
|
import type { GenericSchema, SchemaDefinition } from 'convex/server'
|
|
10
11
|
import approvalsSchema from '../dist/components/approvals/schema.js'
|
|
11
12
|
import foundationSchema from '../dist/components/foundation/schema.js'
|
|
12
13
|
|
|
13
|
-
const foundationModules = import.meta.glob(
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
const approvalsModules = import.meta.glob(
|
|
17
|
-
'../dist/components/approvals/**/*.mjs',
|
|
18
|
-
)
|
|
14
|
+
const foundationModules = import.meta.glob('../dist/components/foundation/**/*.mjs')
|
|
15
|
+
const approvalsModules = import.meta.glob('../dist/components/approvals/**/*.mjs')
|
|
19
16
|
|
|
20
|
-
type RegistersComponents =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
modules: Record<string, () => Promise<unknown>>,
|
|
25
|
-
) => void
|
|
26
|
-
}
|
|
17
|
+
type RegistersComponents = Pick<
|
|
18
|
+
TestConvex<SchemaDefinition<GenericSchema, boolean>>,
|
|
19
|
+
'registerComponent'
|
|
20
|
+
>
|
|
27
21
|
|
|
28
22
|
/** Registers the foundation component under its default install name. */
|
|
29
|
-
export function registerFoundation(
|
|
30
|
-
t: RegistersComponents,
|
|
31
|
-
name = 'foundation',
|
|
32
|
-
) {
|
|
23
|
+
export function registerFoundation(t: RegistersComponents, name = 'foundation') {
|
|
33
24
|
t.registerComponent(name, foundationSchema, foundationModules)
|
|
34
25
|
}
|
|
35
26
|
|