create-erxes 0.1.3 → 0.1.4
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/dist/index.js +1 -1
- package/dist/templates/base/.agents/skills/endpoint/SKILL.md +13 -7
- package/dist/templates/base/AGENTS.md +5 -2
- package/dist/templates/base/api/package.json +3 -2
- package/dist/templates/base/api/src/modules/items/items.ts +6 -8
- package/dist/templates/base/doctor.config.jsonc +20 -0
- package/dist/templates/base/knip.ts +3 -2
- package/dist/templates/base/package.json +2 -1
- package/dist/templates/base/ui/package.json +2 -2
- package/dist/templates/base/vite.config.ts +5 -1
- package/dist/templates/migrate/.agents/skills/plugin-migrate/SKILL.md +6 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdir, readFile, readdir, symlink, writeFile } from "node:fs/promises";
|
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.1.
|
|
12
|
+
var version = "0.1.4";
|
|
13
13
|
// src/existing-plugins.ts
|
|
14
14
|
/** The old erxes plugins a new-core plugin can be migrated from (`backend/plugins/<name>_api`). */
|
|
15
15
|
const OLD_PLUGINS = [
|
|
@@ -6,15 +6,21 @@ description: Add or change an API procedure. Use when editing api/src/modules, a
|
|
|
6
6
|
1. Pick the permission from `PERMISSIONS` in `api/src/core.ts`. A new one goes
|
|
7
7
|
there and into `manifest.permissions`, named `__id__.<record>.<verb>`.
|
|
8
8
|
2. Write the procedure in `api/src/modules/<module>/<module>.ts` on `reads(action)`
|
|
9
|
-
or `writes(action)` from `api/src/orpc.ts`, with zod `.input()` and `.output()`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
or `writes(action)` from `api/src/orpc.ts`, with a zod `.input()` and an `.output()` built
|
|
10
|
+
from the table: `createSelectSchema(table).omit({ orgId: true })`, as `items` does
|
|
11
|
+
(`erxes/procedure-output` fails a procedure without one). Query through `context.tx` with no
|
|
12
|
+
org filter: row-level security scopes it. Lists page by cursor, newest first, as
|
|
13
|
+
`items.list` does.
|
|
14
|
+
3. Return the rows as selected: flat, under their column names (`referenceType` and
|
|
15
|
+
`referenceId`, never `reference: { type, id }`), with no `.map` that renames or strips
|
|
16
|
+
fields. A value the row lacks comes from the query, a join or subquery in the `select`, and
|
|
17
|
+
goes on the schema with `.extend()`.
|
|
18
|
+
4. Fail with `ORPCError` (`NOT_FOUND`, `FORBIDDEN`, `CONFLICT`, `BAD_REQUEST`);
|
|
13
19
|
the UI shows its `message`.
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
5. Add the module to `router` in `api/src/router.ts`. The UI's types follow.
|
|
21
|
+
6. In the UI, read with `orpc.<group>.<name>.queryOptions()` and write with
|
|
16
22
|
`mutationOptions()`, invalidating `orpc.<group>.key()` on success.
|
|
17
|
-
|
|
23
|
+
7. Test it in the module's `__tests__`: the happy path, another organisation
|
|
18
24
|
seeing nothing, and a member without the permission getting `FORBIDDEN`.
|
|
19
25
|
|
|
20
26
|
Done when that test passes in `vp run test` and `vp run check` is clean.
|
|
@@ -21,6 +21,7 @@ without line-by-line review.
|
|
|
21
21
|
- Use a maintained library when one does the job. Keep dependencies near their latest release and off deprecated APIs. [typescript/no-deprecated, review]
|
|
22
22
|
- One way to do each job. Search for the existing helper before writing one, merge the repeats you find, delete what nothing uses. [knip, review]
|
|
23
23
|
- Types flow from the database schema to the contract to the UI. Infer them, so each shape is written once. [pnpm check:generated, review]
|
|
24
|
+
- API input, output and events are flat rows, as the table stores them: `referenceType` and `referenceId`, never a nested `{ type, id }` object or a `to…Dto` mapper. A value the row lacks comes from the query. [erxes/no-dto-mapper, review]
|
|
24
25
|
- Parse outside input with zod and narrow it, so the code needs no `any`, cast or `!`. [typescript/no-explicit-any, typescript/no-unsafe-type-assertion, typescript/no-non-null-assertion]
|
|
25
26
|
- Lint and type rules are the spec: when one fires, fix the code. Silencing it is never the fix, whether by a disable comment, `@ts-ignore`, an override, an ignore, a weaker option or a raised limit. A rule that is wrong changes in its own PR. [typescript/ban-ts-comment, review]
|
|
26
27
|
- Split a file or function that outgrows its limit by responsibility (router, service, queries). [max-lines, max-lines-per-function, review]
|
|
@@ -35,8 +36,10 @@ without line-by-line review.
|
|
|
35
36
|
|
|
36
37
|
## This repo
|
|
37
38
|
|
|
38
|
-
- `vp run check` runs the escape guard, format, lint, types,
|
|
39
|
-
and `pnpm check:generated`, which
|
|
39
|
+
- `vp run check` runs the escape guard, format, lint, types, React Doctor on `ui/`
|
|
40
|
+
(`doctor.config.jsonc`), knip, the docs guard and `pnpm check:generated`, which
|
|
41
|
+
compares the migrations with the schema. `pnpm exec react-doctor why <file:line>`,
|
|
42
|
+
run in `ui/`, explains a React Doctor hit.
|
|
40
43
|
- Other gates: `vp run test` on real Postgres via `DATA_TEST_URL`,
|
|
41
44
|
`pnpm check:rls`, `pnpm build`. `vp run fix` formats and fixes lint.
|
|
42
45
|
- Core finds the plugin by these names, so they stay fixed: plugin `__id__`,
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"db:check": "drizzle-kit check"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
25
|
-
"@erxes/plugin-sdk": "0.1.0-v2.
|
|
24
|
+
"@erxes/core-contract": "0.1.0-v2.4",
|
|
25
|
+
"@erxes/plugin-sdk": "0.1.0-v2.4",
|
|
26
26
|
"@opentelemetry/instrumentation-express": "^0.73.0",
|
|
27
27
|
"@opentelemetry/instrumentation-http": "^0.301.1",
|
|
28
28
|
"@opentelemetry/instrumentation-pg": "^0.78.0",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@orpc/server": "1.16.2",
|
|
32
32
|
"cors": "^2.8.6",
|
|
33
33
|
"drizzle-orm": "0.45.4",
|
|
34
|
+
"drizzle-zod": "0.8.3",
|
|
34
35
|
"express": "^5.3.0",
|
|
35
36
|
"import-in-the-middle": "^3.6.0",
|
|
36
37
|
"pg": "^8.23.1",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ORPCErrorConstructorMap, ORPCError } from '@orpc/server';
|
|
2
2
|
import { and, desc, eq, getTableColumns, ilike, sql } from 'drizzle-orm';
|
|
3
|
+
import { createSelectSchema } from 'drizzle-zod';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { PERMISSIONS } from '#/core.ts';
|
|
5
6
|
import { uniqueViolation } from '#/db/client.ts';
|
|
@@ -12,14 +13,11 @@ const { orgId, ...columns } = getTableColumns(items);
|
|
|
12
13
|
const Name = z.string().trim().min(1).max(200);
|
|
13
14
|
const Description = z.string().trim().max(5000);
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
createdAt: z.date(),
|
|
21
|
-
updatedAt: z.date(),
|
|
22
|
-
});
|
|
16
|
+
/**
|
|
17
|
+
* The row as the table stores it, flat and under its column names. A value the row lacks is
|
|
18
|
+
* selected by the query and added with `.extend()`; no mapper reshapes rows.
|
|
19
|
+
*/
|
|
20
|
+
const Item = createSelectSchema(items).omit({ orgId: true });
|
|
23
21
|
|
|
24
22
|
/** The failures a client can branch on: `isDefinedError(error) && error.code === ...`. */
|
|
25
23
|
const itemErrors = {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// React Doctor's rules for erxes React code. `vp run check` runs it and fails on any warning.
|
|
2
|
+
// create-erxes gives every plugin this file, with its ui/ as the one project.
|
|
3
|
+
{
|
|
4
|
+
"$schema": "https://react.doctor/schema/config.json",
|
|
5
|
+
"projects": ["ui"],
|
|
6
|
+
"rules": {
|
|
7
|
+
// How big or branchy a component grows is opinion; max-lines-per-function already caps it.
|
|
8
|
+
"react-doctor/no-high-complexity-react-function": "off",
|
|
9
|
+
"react-doctor/no-giant-component": "off",
|
|
10
|
+
// Mutations refresh through helpers this rule can't see into.
|
|
11
|
+
"react-doctor/query-mutation-missing-invalidation": "off",
|
|
12
|
+
// Micro-optimisations for lists of a few dozen items at most.
|
|
13
|
+
"react-doctor/js-set-map-lookups": "off",
|
|
14
|
+
"react-doctor/js-index-maps": "off",
|
|
15
|
+
"react-doctor/js-hoist-intl": "off",
|
|
16
|
+
// Only costs a full reload in development, and oxlint's react/only-export-components is
|
|
17
|
+
// the place to turn it on.
|
|
18
|
+
"react-doctor/only-export-components": "off",
|
|
19
|
+
},
|
|
20
|
+
}
|
|
@@ -5,8 +5,9 @@ const config: KnipConfig = {
|
|
|
5
5
|
'.': {
|
|
6
6
|
entry: ['{tools,migration,scripts}/*.ts'],
|
|
7
7
|
project: ['*.ts', '{tools,migration,scripts}/**/*.ts'],
|
|
8
|
-
//
|
|
9
|
-
|
|
8
|
+
// The check task runs these: oxlint calls tsrs-lint through OXLINT_TSGOLINT_PATH, and
|
|
9
|
+
// react-doctor reads doctor.config.jsonc.
|
|
10
|
+
ignoreDependencies: ['tsrs', 'react-doctor'],
|
|
10
11
|
},
|
|
11
12
|
api: {
|
|
12
13
|
project: ['src/**/*.ts'],
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"image:context": "pnpm build && rm -rf .runtime && pnpm --filter @__id__/api deploy --prod .runtime"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@erxes/lint": "0.1.
|
|
19
|
+
"@erxes/lint": "0.1.2",
|
|
20
20
|
"@types/node": "^26.6.6",
|
|
21
21
|
"knip": "^6.45.1",
|
|
22
|
+
"react-doctor": "0.9.23",
|
|
22
23
|
"tsrs": "0.25.0-ts7.1.0-beta",
|
|
23
24
|
"typescript": "7.0.2",
|
|
24
25
|
"vite-plus": "catalog:"
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"build": "rsbuild build"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
11
|
+
"@erxes/core-contract": "0.1.0-v2.4",
|
|
12
12
|
"@orpc/client": "1.16.2",
|
|
13
13
|
"@orpc/tanstack-query": "1.16.2",
|
|
14
14
|
"@tabler/icons-react": "3.34.0",
|
|
15
15
|
"@tanstack/react-query": "^5.107.1",
|
|
16
|
-
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.
|
|
16
|
+
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.5",
|
|
17
17
|
"jotai": "^3.0.2",
|
|
18
18
|
"nuqs": "^2.10.3",
|
|
19
19
|
"react": "19.3.1",
|
|
@@ -6,6 +6,10 @@ import { noSkips } from './tools/test/no-skips.ts';
|
|
|
6
6
|
// The type check is tsrs (TypeScript 7) running as oxlint's tsgolint.
|
|
7
7
|
const tsrs = 'OXLINT_TSGOLINT_PATH=node_modules/.bin/tsrs-lint';
|
|
8
8
|
|
|
9
|
+
// React Doctor on ui/ (doctor.config.jsonc), failing on any warning. Offline: no score upload,
|
|
10
|
+
// share link or crash reports, and no dependency scan.
|
|
11
|
+
const reactDoctor = 'react-doctor --no-score --no-supply-chain --blocking warning';
|
|
12
|
+
|
|
9
13
|
// Vite Task tracks the files each command reads; the lockfile is listed too, so an
|
|
10
14
|
// install that changes a dependency always reruns the task.
|
|
11
15
|
const tracked = { input: [{ auto: true }, 'pnpm-lock.yaml'] };
|
|
@@ -15,7 +19,7 @@ export default defineConfig({
|
|
|
15
19
|
tasks: {
|
|
16
20
|
// A rerun with no edits replays the last result.
|
|
17
21
|
check: {
|
|
18
|
-
command: `erxes-check-escapes && ${tsrs} vp check && knip && erxes-check-docs && pnpm check:generated`,
|
|
22
|
+
command: `erxes-check-escapes && ${tsrs} vp check && ${reactDoctor} && knip && erxes-check-docs && pnpm check:generated`,
|
|
19
23
|
cache: tracked,
|
|
20
24
|
},
|
|
21
25
|
fix: { command: `${tsrs} vp check --fix`, cache: false },
|
|
@@ -34,6 +34,12 @@ data only. The inventory reads code, never a database.
|
|
|
34
34
|
(`tasks.list`, not `getTasks`), and fold operations that only differ by
|
|
35
35
|
filter into one input. A failure the UI acts on gets a typed error. An
|
|
36
36
|
operation the new UI never calls is ticked with no procedure.
|
|
37
|
+
The answer is the table's rows, flat, through the `.output()` the `endpoint` skill builds,
|
|
38
|
+
not the old GraphQL type. Where the old type nested a reference (`contentType` with
|
|
39
|
+
`contentTypeId`, `{ type, id }`), store and return the two columns (`referenceType`,
|
|
40
|
+
`referenceId`). An old field resolver (`createdUser`, `stage`) becomes a join or subquery
|
|
41
|
+
in the `select`, or the UI's own lookup (`MemberInline` for members), never a mapper after
|
|
42
|
+
the query.
|
|
37
43
|
4. Core calls. Do what the arrow says: `sdk` is
|
|
38
44
|
`core.forOrg(orgId).<procedure>` in the API with that scope in
|
|
39
45
|
`manifest.scopes`; `contract` is a call from the UI with the member's own
|