@pylonts/dsl 1.1.12 → 1.1.13
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/convert.d.ts +6 -8
- package/dist/curd.js +1 -1
- package/dist/dao.d.ts +10 -7
- package/dist/dao.js +20 -7
- package/dist/dsl.d.ts +18 -1
- package/dist/dsl.js +40 -0
- package/dist/dto.d.ts +13 -8
- package/dist/dto.js +68 -13
- package/dist/entity.d.ts +4 -3
- package/dist/entity.js +1 -1
- package/dist/filter.d.ts +6 -4
- package/dist/filter.js +1 -1
- package/dist/flow-script.js +8 -2
- package/dist/flow.d.ts +10 -2
- package/dist/flow.js +44 -4
- package/dist/mermaid-driver.js +2 -2
- package/dist/service.d.ts +13 -8
- package/dist/service.js +1 -1
- package/dist/third-service.d.ts +10 -53
- package/dist/third-service.js +3 -78
- package/dist/typebox-driver.d.ts +0 -6
- package/dist/typebox-driver.js +8 -36
- package/dist/utils.d.ts +2 -2
- package/docs/curd.md +146 -146
- package/docs/dao-generation.md +477 -477
- package/docs/project.md +31 -31
- package/docs/token.md +326 -326
- package/package.json +1 -1
- package/src/action.ts +51 -51
- package/src/controller.ts +53 -53
- package/src/convert.ts +76 -78
- package/src/curd.ts +104 -104
- package/src/dao.ts +504 -485
- package/src/dsl.ts +296 -257
- package/src/dto.ts +323 -266
- package/src/entity.ts +43 -42
- package/src/expr.ts +64 -64
- package/src/filter.ts +71 -69
- package/src/flow-script.ts +702 -695
- package/src/flow.ts +1272 -1226
- package/src/index.ts +46 -46
- package/src/mermaid-driver.ts +339 -339
- package/src/mysql-driver.ts +108 -108
- package/src/project.ts +138 -138
- package/src/service.ts +112 -107
- package/src/third-service.ts +68 -191
- package/src/typebox-driver.ts +234 -268
- package/src/utils.ts +74 -74
package/dist/service.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import type { SchemaBase } from './dsl.js';
|
|
1
|
+
import type { CollectionSchemaBase, SchemaBase } from './dsl.js';
|
|
2
2
|
import type { FrontAppSchema, ProjectApiSchema } from './project.js';
|
|
3
3
|
import type { DtoMessage } from './dto.js';
|
|
4
4
|
import type { ExceptionSchema } from './exception.js';
|
|
5
5
|
import type { FlowSchema } from './flow.js';
|
|
6
|
-
/** A backend service serving
|
|
7
|
-
|
|
6
|
+
/** A backend service serving one frontend app (1:1 module), or a
|
|
7
|
+
* platform-shared domain service (app unset — shared across modules). */
|
|
8
|
+
export interface ServiceSchema extends CollectionSchemaBase {
|
|
8
9
|
type: 'service';
|
|
9
10
|
/** The backend api module this service belongs to (shared instance from
|
|
10
11
|
* project.config.ts apis). Services are always backend-side, so storage is
|
|
11
|
-
* service_schema/{api.name}/{app.name}/service
|
|
12
|
+
* service_schema/{api.name}/{app.name}/service/ — app unset = the api-level
|
|
13
|
+
* common domain layer, stored at service_schema/{api.name}/common/service/. */
|
|
12
14
|
api: ProjectApiSchema;
|
|
13
|
-
/** The frontend app this service serves (shared instance from project.config).
|
|
14
|
-
|
|
15
|
+
/** The frontend app this service serves (shared instance from project.config).
|
|
16
|
+
* Unset = api-level common domain service shared by all modules of the api. */
|
|
17
|
+
app?: FrontAppSchema;
|
|
15
18
|
/** Methods keyed by name — the map key is written back as the method name. */
|
|
16
19
|
methods: Record<string, ServiceMethodSchema>;
|
|
17
20
|
}
|
|
@@ -20,11 +23,13 @@ export type ServiceMethodDef = Omit<ServiceMethodSchema, 'type' | 'schema' | 'na
|
|
|
20
23
|
export declare function defineService(options: {
|
|
21
24
|
name: string;
|
|
22
25
|
api: ProjectApiSchema;
|
|
23
|
-
app
|
|
26
|
+
app?: FrontAppSchema;
|
|
24
27
|
methods: Record<string, ServiceMethodDef>;
|
|
25
28
|
description?: string;
|
|
26
29
|
}): ServiceSchema;
|
|
27
|
-
/** A method exposed by a service
|
|
30
|
+
/** A method exposed by a business service — the contract with the calling
|
|
31
|
+
* frontend. Third-party integration methods are a separate contract
|
|
32
|
+
* (ThirdServiceMethodSchema): they can never bind a flow. */
|
|
28
33
|
export interface ServiceMethodSchema extends SchemaBase {
|
|
29
34
|
type: 'method';
|
|
30
35
|
schema: ServiceSchema;
|
package/dist/service.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exceptionEndNames } from './flow.js';
|
|
2
2
|
export function defineService(options) {
|
|
3
|
-
if (!options.api.apps.includes(options.app)) {
|
|
3
|
+
if (options.app && !options.api.apps.includes(options.app)) {
|
|
4
4
|
throw new Error(`service ${options.name}: api '${options.api.name}' does not serve app '${options.app.name}'`);
|
|
5
5
|
}
|
|
6
6
|
const schema = {
|
package/dist/third-service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SchemaBase } from './dsl.js';
|
|
2
|
+
import type { DtoMessage } from './dto.js';
|
|
2
3
|
import type { ExceptionSchema } from './exception.js';
|
|
3
|
-
import type { FieldRuleEnd, FieldRuleSchema } from './field-rule.js';
|
|
4
4
|
import type { ThirdApiSchema } from './project.js';
|
|
5
5
|
/** A third-party integration service (e.g. tenpay wechat pay).
|
|
6
6
|
* Distinct from ServiceSchema (backend service bound to an app) and
|
|
@@ -13,65 +13,22 @@ export interface ThirdServiceSchema extends SchemaBase {
|
|
|
13
13
|
/** Methods keyed by name — the map key is written back as the method name. */
|
|
14
14
|
methods: Record<string, ThirdServiceMethodSchema>;
|
|
15
15
|
}
|
|
16
|
-
/** A method
|
|
16
|
+
/** A method of a third-party integration service. Same contract shape as
|
|
17
|
+
* ServiceMethodSchema minus flow — the implementation lives in the external
|
|
18
|
+
* system, there is nothing to model. Kept separate so a third method can
|
|
19
|
+
* never bind a flow. */
|
|
17
20
|
export interface ThirdServiceMethodSchema extends SchemaBase {
|
|
18
21
|
type: 'method';
|
|
19
22
|
schema: ThirdServiceSchema;
|
|
20
|
-
/** Input message — the Field-collection counterpart of a DtoMessage. */
|
|
21
|
-
args: ThirdMethodSchema;
|
|
22
|
-
/** Output message. */
|
|
23
|
-
results: ThirdMethodSchema;
|
|
24
|
-
/** Exceptions this method may throw (e.g. IOException, CodeException). */
|
|
25
|
-
throws?: ExceptionSchema[];
|
|
26
|
-
}
|
|
27
|
-
/** Field binding to a rule: which end the local wire field stands on.
|
|
28
|
-
* The ref always stands on the other end — from/to carry no extra information. */
|
|
29
|
-
export interface ConvertFieldSchema {
|
|
30
|
-
/** The rule binding field and ref (rule = name + two ends). */
|
|
31
|
-
rule: FieldRuleSchema;
|
|
32
|
-
/** The end instance the local wire field stands on. */
|
|
33
|
-
end: FieldRuleEnd;
|
|
34
|
-
}
|
|
35
|
-
/** Same-fact variant link: a wire field carrying the same fact as a local
|
|
36
|
-
* entity column under a different type/format (e.g. total_fee in fen vs amount in yuan). */
|
|
37
|
-
export interface ThirdFieldRef {
|
|
38
|
-
/** Wire field defined in this message (local definition). */
|
|
39
|
-
field: Field;
|
|
40
|
-
/** Field in another schema (table column or another message). */
|
|
41
|
-
ref: Field;
|
|
42
|
-
/** Optional rule binding — omitted when the fact is merely linked, not converted. */
|
|
43
|
-
convert?: ConvertFieldSchema;
|
|
44
|
-
}
|
|
45
|
-
/** A directional message of a third-party method: a Field collection mirroring
|
|
46
|
-
* TableSchema.columns, but fields hold wire-format names/types. A field may be
|
|
47
|
-
* a shared instance of a local entity column (same fact, same type) — its
|
|
48
|
-
* name/schema keep pointing at the table and the DTO projection inherits
|
|
49
|
-
* type/semantics from the entity, exactly like from(table). */
|
|
50
|
-
export interface ThirdMethodSchema extends CollectionSchemaBase {
|
|
51
|
-
type: 'thirdMethod';
|
|
52
|
-
/** The method this message belongs to (direction implied by args/results slot). */
|
|
53
|
-
schema: ThirdServiceMethodSchema;
|
|
54
|
-
/** Wire-format fields. */
|
|
55
|
-
fields: Record<string, Field>;
|
|
56
|
-
/** Same-fact variant links: wire field -> local entity column. */
|
|
57
|
-
refs?: ThirdFieldRef[];
|
|
58
|
-
}
|
|
59
|
-
/** Message input for defineThirdMethod: type/schema are set by the builder. */
|
|
60
|
-
export type ThirdMethodDef = Omit<ThirdMethodSchema, 'type' | 'schema'>;
|
|
61
|
-
/** Build a third-party method message. Writes back name/schema on own fields
|
|
62
|
-
* (top-level and nested); shared entity columns keep their table identity and
|
|
63
|
-
* must be keyed by their column name. */
|
|
64
|
-
export declare function defineThirdMethod(def: ThirdMethodDef): ThirdMethodSchema;
|
|
65
|
-
/** Method input for defineThirdService: name is written back from the methods map key. */
|
|
66
|
-
export interface ThirdServiceMethodDef {
|
|
67
23
|
/** Input message. */
|
|
68
|
-
args:
|
|
24
|
+
args: DtoMessage;
|
|
69
25
|
/** Output message. */
|
|
70
|
-
results:
|
|
26
|
+
results: DtoMessage;
|
|
71
27
|
/** Exceptions this method may throw (e.g. IOException, CodeException). */
|
|
72
28
|
throws?: ExceptionSchema[];
|
|
73
|
-
description?: string;
|
|
74
29
|
}
|
|
30
|
+
/** Method input for defineThirdService: name/schema are set by the builder. */
|
|
31
|
+
export type ThirdServiceMethodDef = Omit<ThirdServiceMethodSchema, 'type' | 'schema' | 'name'>;
|
|
75
32
|
export declare function defineThirdService(options: {
|
|
76
33
|
schema: ThirdApiSchema;
|
|
77
34
|
name: string;
|
package/dist/third-service.js
CHANGED
|
@@ -1,73 +1,3 @@
|
|
|
1
|
-
/** Build a third-party method message. Writes back name/schema on own fields
|
|
2
|
-
* (top-level and nested); shared entity columns keep their table identity and
|
|
3
|
-
* must be keyed by their column name. */
|
|
4
|
-
export function defineThirdMethod(def) {
|
|
5
|
-
const message = {
|
|
6
|
-
type: 'thirdMethod',
|
|
7
|
-
name: def.name,
|
|
8
|
-
description: def.description,
|
|
9
|
-
// Filled by defineThirdService.
|
|
10
|
-
schema: undefined,
|
|
11
|
-
fields: def.fields,
|
|
12
|
-
refs: def.refs,
|
|
13
|
-
};
|
|
14
|
-
for (const key of Object.keys(message.fields)) {
|
|
15
|
-
const field = message.fields[key];
|
|
16
|
-
if (field.schema === undefined) {
|
|
17
|
-
field.name = key;
|
|
18
|
-
field.schema = message;
|
|
19
|
-
}
|
|
20
|
-
else if (field.schema.type === 'table') {
|
|
21
|
-
// Shared entity column: from() names the projection after field.name, so
|
|
22
|
-
// a mismatched key would silently rename the wire field. Same-fact fields
|
|
23
|
-
// with different names go through refs instead.
|
|
24
|
-
if (field.name !== key) {
|
|
25
|
-
throw new Error(`thirdMethod '${message.name}': shared column key '${key}' must match the column name '${field.name}' — ` +
|
|
26
|
-
`same-fact fields with different names go through refs instead`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (field.schema !== message) {
|
|
30
|
-
throw new Error(`thirdMethod '${message.name}': field '${key}' already belongs to ${field.schema.type} '${field.schema.name}', cannot reuse`);
|
|
31
|
-
}
|
|
32
|
-
writeBackNested(message, field);
|
|
33
|
-
}
|
|
34
|
-
if (message.refs !== undefined) {
|
|
35
|
-
const ownFields = Object.values(message.fields);
|
|
36
|
-
for (const link of message.refs) {
|
|
37
|
-
if (!ownFields.includes(link.field)) {
|
|
38
|
-
throw new Error(`thirdMethod '${message.name}': ref field must be one of its fields`);
|
|
39
|
-
}
|
|
40
|
-
if (link.ref.schema === undefined || link.ref.schema === message) {
|
|
41
|
-
throw new Error(`thirdMethod '${message.name}': ref target '${link.ref.name}' must be defined in another schema`);
|
|
42
|
-
}
|
|
43
|
-
if (link.convert !== undefined) {
|
|
44
|
-
const ends = Object.values(link.convert.rule.ends);
|
|
45
|
-
if (!ends.includes(link.convert.end)) {
|
|
46
|
-
throw new Error(`thirdMethod '${message.name}': convert end '${link.convert.end.name}' must be one of rule '${link.convert.rule.name}' ends`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return message;
|
|
52
|
-
}
|
|
53
|
-
/** Write back name/schema on nested wire fields (array items, object properties);
|
|
54
|
-
* shared entity columns keep their table identity. */
|
|
55
|
-
function writeBackNested(message, field) {
|
|
56
|
-
if (field.type === 'array') {
|
|
57
|
-
writeBackNested(message, field.items);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (field.type !== 'object')
|
|
61
|
-
return;
|
|
62
|
-
for (const key of Object.keys(field.properties)) {
|
|
63
|
-
const child = field.properties[key];
|
|
64
|
-
if (child.schema === undefined) {
|
|
65
|
-
child.name = key;
|
|
66
|
-
child.schema = message;
|
|
67
|
-
}
|
|
68
|
-
writeBackNested(message, child);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
1
|
export function defineThirdService(options) {
|
|
72
2
|
const schema = {
|
|
73
3
|
type: 'thirdService',
|
|
@@ -78,20 +8,15 @@ export function defineThirdService(options) {
|
|
|
78
8
|
};
|
|
79
9
|
for (const key of Object.keys(options.methods)) {
|
|
80
10
|
const method = options.methods[key];
|
|
81
|
-
|
|
11
|
+
schema.methods[key] = {
|
|
82
12
|
type: 'method',
|
|
83
13
|
name: key,
|
|
84
14
|
description: method.description,
|
|
85
15
|
schema,
|
|
86
|
-
args:
|
|
87
|
-
results:
|
|
16
|
+
args: method.args,
|
|
17
|
+
results: method.results,
|
|
88
18
|
throws: method.throws,
|
|
89
19
|
};
|
|
90
|
-
methodSchema.args = defineThirdMethod(method.args);
|
|
91
|
-
methodSchema.results = defineThirdMethod(method.results);
|
|
92
|
-
methodSchema.args.schema = methodSchema;
|
|
93
|
-
methodSchema.results.schema = methodSchema;
|
|
94
|
-
schema.methods[key] = methodSchema;
|
|
95
20
|
}
|
|
96
21
|
return schema;
|
|
97
22
|
}
|
package/dist/typebox-driver.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DtoMessage, ImportBase } from './dto.js';
|
|
2
|
-
import type { ThirdMethodSchema } from './third-service.js';
|
|
3
2
|
export type EnumResolver = (enumName: string) => ImportBase | undefined;
|
|
4
3
|
/** Collect all imports needed to render a DTO: include() bases + enum references. */
|
|
5
4
|
export declare function collectDtoImports(schema: DtoMessage, resolver: EnumResolver | undefined, out: Map<string, ImportBase>): void;
|
|
@@ -11,8 +10,3 @@ export declare function renderDtoMessage(schema: DtoMessage, options?: {
|
|
|
11
10
|
resolver?: EnumResolver;
|
|
12
11
|
source?: string;
|
|
13
12
|
}): string;
|
|
14
|
-
/** Render one third-party method message export (const only — pair with
|
|
15
|
-
* renderDtoTypeExport for the Static type). */
|
|
16
|
-
export declare function renderThirdMethodExport(schema: ThirdMethodSchema, resolver: EnumResolver | undefined): string;
|
|
17
|
-
/** Collect all imports needed to render a third-party method message: enum references. */
|
|
18
|
-
export declare function collectThirdMethodImports(schema: ThirdMethodSchema, resolver: EnumResolver | undefined, out: Map<string, ImportBase>): void;
|
package/dist/typebox-driver.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isDtoField, isDtoMessage } from './dto.js';
|
|
2
|
+
import { collectEnumRefs } from './dsl.js';
|
|
1
3
|
function renderString(s) {
|
|
2
4
|
return `'${s.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
3
5
|
}
|
|
@@ -116,18 +118,6 @@ function renderValue(f, indent, resolver) {
|
|
|
116
118
|
// annotations; DB field defaults are not carried into the API contract.
|
|
117
119
|
return renderBasic(f.field, f.pattern, f.default, resolver, indent);
|
|
118
120
|
}
|
|
119
|
-
/** Structural check — DtoMessage instances may come from a different module copy, so instanceof is unreliable. */
|
|
120
|
-
function isDtoMessage(v) {
|
|
121
|
-
if (typeof v !== 'object' || v === null)
|
|
122
|
-
return false;
|
|
123
|
-
return v.type === 'dto';
|
|
124
|
-
}
|
|
125
|
-
/** Structural check — a DtoField wraps a Field in a .field property and has no .type of its own. */
|
|
126
|
-
function isDtoField(v) {
|
|
127
|
-
if (typeof v !== 'object' || v === null)
|
|
128
|
-
return false;
|
|
129
|
-
return 'field' in v && !('type' in v);
|
|
130
|
-
}
|
|
131
121
|
function collectEnumImports(f, resolver, out) {
|
|
132
122
|
if (f.field.type === 'array') {
|
|
133
123
|
const items = f.field.items;
|
|
@@ -154,23 +144,15 @@ function collectEnumImports(f, resolver, out) {
|
|
|
154
144
|
}
|
|
155
145
|
/** Enum import collection over a plain Field (wire-format nested fields). */
|
|
156
146
|
function collectFieldEnumImports(field, resolver, out) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
for (const child of Object.values(field.properties))
|
|
163
|
-
collectFieldEnumImports(child, resolver, out);
|
|
164
|
-
return;
|
|
147
|
+
for (const jsName of collectEnumRefs(field)) {
|
|
148
|
+
const ref = resolver?.(jsName);
|
|
149
|
+
if (!ref)
|
|
150
|
+
throw new Error(`enum ${jsName}: no import ref — pass an EnumResolver`);
|
|
151
|
+
out.set(`${ref.from}#${ref.name}`, ref);
|
|
165
152
|
}
|
|
166
|
-
if (field.type === 'enum')
|
|
167
|
-
collectEnumRef(field, resolver, out);
|
|
168
153
|
}
|
|
169
154
|
function collectEnumRef(field, resolver, out) {
|
|
170
|
-
|
|
171
|
-
if (!ref)
|
|
172
|
-
throw new Error(`enum field ${field.name}: no import ref for ${field.enum.jsName} — pass an EnumResolver`);
|
|
173
|
-
out.set(`${ref.from}#${ref.name}`, ref);
|
|
155
|
+
collectFieldEnumImports(field, resolver, out);
|
|
174
156
|
}
|
|
175
157
|
/** Collect all imports needed to render a DTO: include() bases + enum references. */
|
|
176
158
|
export function collectDtoImports(schema, resolver, out) {
|
|
@@ -216,13 +198,3 @@ function renderBase(base) {
|
|
|
216
198
|
const args = base.args.map((a) => (typeof a === 'string' ? a : a.name));
|
|
217
199
|
return `${base.name}(${args.join(', ')})`;
|
|
218
200
|
}
|
|
219
|
-
/** Render one third-party method message export (const only — pair with
|
|
220
|
-
* renderDtoTypeExport for the Static type). */
|
|
221
|
-
export function renderThirdMethodExport(schema, resolver) {
|
|
222
|
-
return `export const ${schema.name} = ${renderFieldObject(schema.fields, 1, resolver)};`;
|
|
223
|
-
}
|
|
224
|
-
/** Collect all imports needed to render a third-party method message: enum references. */
|
|
225
|
-
export function collectThirdMethodImports(schema, resolver, out) {
|
|
226
|
-
for (const f of Object.values(schema.fields))
|
|
227
|
-
collectFieldEnumImports(f, resolver, out);
|
|
228
|
-
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Field, SchemaBase } from './dsl.js';
|
|
1
|
+
import type { CollectionSchemaBase, Field, SchemaBase } from './dsl.js';
|
|
2
2
|
import type { FrontAppSchema, ProjectApiSchema } from './project.js';
|
|
3
3
|
/** A utility method with a full signature. */
|
|
4
4
|
export interface UtilsMethodSchema extends SchemaBase {
|
|
@@ -13,7 +13,7 @@ export interface UtilsMethodSchema extends SchemaBase {
|
|
|
13
13
|
/** Method input for defineUtils: type/schema/name are set by the builder. */
|
|
14
14
|
export type UtilsMethodDef = Omit<UtilsMethodSchema, 'type' | 'schema' | 'name'>;
|
|
15
15
|
/** A base utility module (e.g. DateTimeUtils). */
|
|
16
|
-
export interface UtilsSchema extends
|
|
16
|
+
export interface UtilsSchema extends CollectionSchemaBase {
|
|
17
17
|
type: 'utils';
|
|
18
18
|
/** Backend binding — the api module this utils belongs to (shared instance
|
|
19
19
|
* from project.config.ts apis). With `app` it serves that frontend
|
package/docs/curd.md
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
# 管理端 CRUD 页面标准(CurdSchema)
|
|
2
|
-
|
|
3
|
-
CurdSchema 是**管理端专用**(`FrontAppSchema.type === 'admin'`)的 CRUD 页面标准:绑定一张实体表 + 一个管理端 app,描述列表页与新增/编辑/详情动作页生成所需的全部页面语义。一条 CurdSchema = 列表页(+ 动作页)的生成规格。
|
|
4
|
-
|
|
5
|
-
页面定义文件按实体组织:`{project}/pages/{entity}.curd.ts`(与 `schema/*.table.ts` 平级)。
|
|
6
|
-
|
|
7
|
-
**CurdSchema 只依赖 table schema(`Field` 实例),不挂钩 DTO(`DtoMessage`)**——DTO 由生成器按标准从 `columns` 推导。
|
|
8
|
-
|
|
9
|
-
## 定义
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { defineCurd } from '@pylonts/dsl';
|
|
13
|
-
import { admin } from '../project.config';
|
|
14
|
-
import { order } from '../schema/order.table';
|
|
15
|
-
import { merchant } from '../schema/merchant.table';
|
|
16
|
-
import { orderListFilter } from '../filter_schema/api/admin/filter/order-list.filter';
|
|
17
|
-
|
|
18
|
-
export const orderCurd = defineCurd('order', { // name = table.name 的 kebab(即 admin 路由路径)
|
|
19
|
-
description: '订单管理',
|
|
20
|
-
app: admin, // 所属管理端(project.config.ts 的 FrontAppSchema 共享实例)
|
|
21
|
-
table: order, // 绑定实体表(共享实例)
|
|
22
|
-
title: '订单管理',
|
|
23
|
-
section: '订单管理', // 必填:sidebar 分组名
|
|
24
|
-
actions: [defineAction('EXPORT', '导出订单')], // 额外操作按钮
|
|
25
|
-
actionPages: {
|
|
26
|
-
add: { mode: 'modal', columns: [order.columns.order_no, order.columns.mer_id] },
|
|
27
|
-
update: { mode: 'modal', columns: [order.columns.id, order.columns.order_no] },
|
|
28
|
-
detail: { mode: 'route', columns: [order.columns.id, order.columns.order_no, order.columns.amount] },
|
|
29
|
-
},
|
|
30
|
-
list: {
|
|
31
|
-
columns: [order.columns.id, order.columns.order_no, merchant.columns.name], // 可跨表
|
|
32
|
-
filter: orderListFilter, // 搜索表单 + keyword(FilterSchema 引用,可选)
|
|
33
|
-
orderBy: { column: order.columns.id, direction: 'desc' },
|
|
34
|
-
columnTitles: { order_no: '订单号', name: '商户名称' }, // Field.name → 文案
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
搜索条件**不内联在 list 里**,而是独立的 **FilterSchema**(`defineFilter`)声明,存放在 `filter_schema/{api.name}/{app.name}/filter/`(机器校验:一文件一 filter,文件名 = 名字去 Filter 后缀转 kebab):
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
// filter_schema/api/admin/filter/order-list.filter.ts
|
|
43
|
-
import { defineFilter } from '@pylonts/dsl';
|
|
44
|
-
import { admin, api } from '../../../project.config';
|
|
45
|
-
import { order } from '../../../schema/order.table';
|
|
46
|
-
|
|
47
|
-
export const orderListFilter = defineFilter({
|
|
48
|
-
name: 'OrderListFilter',
|
|
49
|
-
api,
|
|
50
|
-
app: admin,
|
|
51
|
-
conditions: [
|
|
52
|
-
{ field: order.columns.status, optional: true }, // op 默认 eq;optional = 有值才加 WHERE
|
|
53
|
-
{ field: order.columns.order_no, op: 'like', optional: true },
|
|
54
|
-
],
|
|
55
|
-
keyword: { columns: [order.columns.order_no] }, // 单输入值多列 OR 模糊
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
生成物为 `{api}/src/modules/{app}/filter/{FilterName}.ts`(两段柯里化 WHERE 拼装方法,DAO/Service 列表查询共用)。
|
|
60
|
-
|
|
61
|
-
## 字段
|
|
62
|
-
|
|
63
|
-
| 字段 | 类型 | 说明 |
|
|
64
|
-
|---|---|---|
|
|
65
|
-
| `app` | `FrontAppSchema` | 所属管理端(共享实例,`type` 必须为 `'admin'`) |
|
|
66
|
-
| `table` | `TableSchema` | 绑定实体表(共享实例) |
|
|
67
|
-
| `title` | `string` | 列表页中文标题 |
|
|
68
|
-
| `section` | `string` | **必填**:sidebar 分组名 |
|
|
69
|
-
| `actions?` | `ActionSchema[]` | 页面额外可执行动作(标准 CRUD 之外,如导出、审核) |
|
|
70
|
-
| `actionPages?` | `{ add? / update? / detail? }` | 动作页:`{ mode: 'modal' \| 'route'; columns: Field[] }` |
|
|
71
|
-
| `list` | `CurdListConfig` | 列表页配置(必填) |
|
|
72
|
-
|
|
73
|
-
### ActionPage
|
|
74
|
-
|
|
75
|
-
| 字段 | 类型 | 说明 |
|
|
76
|
-
|---|---|---|
|
|
77
|
-
| `mode` | `'modal' \| 'route'` | 弹窗或独立路由 |
|
|
78
|
-
| `columns` | `Field[]` | 该页面渲染的字段,**必填非空**——前端要显示的字段必须全部显式列出 |
|
|
79
|
-
|
|
80
|
-
### CurdListConfig
|
|
81
|
-
|
|
82
|
-
| 字段 | 类型 | 说明 |
|
|
83
|
-
|---|---|---|
|
|
84
|
-
| `columns` | `Field[]` | 列表列,**必填非空**;可含跨表字段 |
|
|
85
|
-
| `filter?` | `FilterSchema` | 页面过滤器引用:搜索表单(AND 条件)+ keyword(多列 OR 模糊);缺省 = 无搜索表单 |
|
|
86
|
-
| `orderBy` | `{ column: Field; direction: 'asc' \| 'desc' }` | 默认排序,**必填**,column 与 direction 都必填;column 必须是**本表字段实例** |
|
|
87
|
-
| `columnTitles?` | `Record<string, string>` | 列标题覆盖:`Field.name` → 中文文案 |
|
|
88
|
-
|
|
89
|
-
### FilterSchema(`defineFilter`)
|
|
90
|
-
|
|
91
|
-
| 字段 | 类型 | 说明 |
|
|
92
|
-
|---|---|---|
|
|
93
|
-
| `name` | `string` | PascalCase、`Filter` 结尾;导出名 = name 首字母小写 |
|
|
94
|
-
| `api` | `ProjectApiSchema` | 所属后端 api(project.config.ts 共享实例);`api.apps` 必须包含 `app` |
|
|
95
|
-
| `app` | `FrontAppSchema` | 所属前端 app(共享实例);必须与引用它的 curd 同 app |
|
|
96
|
-
| `conditions?` | `FilterCondition[]` | AND 组合条件:`{ field, op?='eq', right?, optional? }`;`optional: true` = 有值才加 WHERE(页面搜索场景) |
|
|
97
|
-
| `keyword?` | `{ columns: Field[] }` | 单输入值对多列 OR like 模糊;配置后驱动「关键词查询」端点(`query({ keyword })`,供 Select/AutoComplete 搜索) |
|
|
98
|
-
|
|
99
|
-
## 跨表字段
|
|
100
|
-
|
|
101
|
-
`list.columns` 与 filter `conditions` 里的 `Field` 实例可指向**本表或其他表**的列——列表列与搜索条件因此可以显示/过滤关联表字段(如订单列表显示商户名称、按商户名称过滤)。
|
|
102
|
-
|
|
103
|
-
## 默认与校验
|
|
104
|
-
|
|
105
|
-
- `list.columns` / `actionPages.*.columns` **必填非空**(不允许省略、不允许空数组)
|
|
106
|
-
- `list.orderBy` **必填**,`column` 与 `direction` 都必填(规格:默认主键 desc 由定义方显式写出)
|
|
107
|
-
- 运行时校验(`defineCurd`,仿 `defineTable` 强校验风格):
|
|
108
|
-
- `app.type` 必须为 `'admin'`,否则抛错
|
|
109
|
-
- **`name` 必须是 `table.name` 的 kebab 形式**(name 即 admin 路由路径,不允许与所服务的表漂移)
|
|
110
|
-
- `section` 必填
|
|
111
|
-
- 所有 `columns` 非空,否则抛错
|
|
112
|
-
- `list.filter.app` 必须 === `curd.app`,否则抛错
|
|
113
|
-
- `list.orderBy.column` 必须属于 `table`,否则抛错
|
|
114
|
-
- `list.columns` 允许跨表,**不校验归属**
|
|
115
|
-
- 运行时校验(`defineFilter`):`api.apps` 包含 `app`;conditions 与 keyword 不能同时为空;keyword.columns 非空
|
|
116
|
-
- 生成时校验(curd 生成器,`DtoSchemaGen.add` / `update`):
|
|
117
|
-
- 表配置 `autoIncrement` 或 `generator`(主键由服务端生成)时,`actionPages.add.columns` **不允许包含主键字段**,否则抛错——AddRequest 不携带服务端生成的主键
|
|
118
|
-
- `actionPages.update.columns` **必须包含主键字段**,否则抛错——UpdateRequest 靠主键定位记录
|
|
119
|
-
|
|
120
|
-
## DTO 推导(生成器约定)
|
|
121
|
-
|
|
122
|
-
DTO 由 curd 生成器从 `CurdSchema` 按标准命名推导,页面语义不持有 DTO 实例:
|
|
123
|
-
|
|
124
|
-
| DTO | 命名 | 字段来源 |
|
|
125
|
-
|---|---|---|
|
|
126
|
-
| Row | `{Pascal}Row` | `list.columns` |
|
|
127
|
-
| ListRequest | `{Pascal}ListRequest` | filter 的 conditions(camelCase + op)与 keyword + 分页参数(`PageRequest`,仅 paginated 表) |
|
|
128
|
-
| QueryRequest | `{Pascal}QueryRequest` | filter 的 conditions + keyword,无分页——keyword 查询端点专用(仅配置 keyword 时生成) |
|
|
129
|
-
| ListResponse | `{Pascal}ListResponse` | `PageResult(Row)`(仅 paginated 表;非分页表列表接口直接返回 `Row[]`,不生成 ListResponse) |
|
|
130
|
-
| AddRequest | `{Pascal}AddRequest` | `actionPages.add.columns` |
|
|
131
|
-
| UpdateRequest | `{Pascal}UpdateRequest` | `actionPages.update.columns` |
|
|
132
|
-
| DetailRequest | `{Pascal}DetailRequest` | 主键 |
|
|
133
|
-
| DetailResponse | `{Pascal}DetailResponse` | `actionPages.detail.columns` |
|
|
134
|
-
|
|
135
|
-
## 与旧 PageConfig 的差异
|
|
136
|
-
|
|
137
|
-
| PageConfig(旧方案,已废弃) | CurdSchema |
|
|
138
|
-
|---|---|
|
|
139
|
-
| `module: string` | 由 `app` 推导(后端模块 == app 1:1) |
|
|
140
|
-
| `schema: 'bd'` 字符串 | `table: TableSchema` 实例(类型安全) |
|
|
141
|
-
| `operations: { label, action }` | `actions: ActionSchema[]` |
|
|
142
|
-
| `detail.mode` 单例 | `actionPages.detail.mode` |
|
|
143
|
-
| `forms.add / forms.update` | `actionPages.add / actionPages.update` |
|
|
144
|
-
| `keyword` / `orderBy` / `columnTitles` | `list.filter`(FilterSchema)/ `list.orderBy` / `list.columnTitles` |
|
|
145
|
-
| `naming` | 去掉(DTO 命名是生成器约定,非页面语义) |
|
|
146
|
-
| DTO 引用(`request` / `fields` / `DtoFields`) | 去掉(DTO 由生成器推导,页面只依赖 table) |
|
|
1
|
+
# 管理端 CRUD 页面标准(CurdSchema)
|
|
2
|
+
|
|
3
|
+
CurdSchema 是**管理端专用**(`FrontAppSchema.type === 'admin'`)的 CRUD 页面标准:绑定一张实体表 + 一个管理端 app,描述列表页与新增/编辑/详情动作页生成所需的全部页面语义。一条 CurdSchema = 列表页(+ 动作页)的生成规格。
|
|
4
|
+
|
|
5
|
+
页面定义文件按实体组织:`{project}/pages/{entity}.curd.ts`(与 `schema/*.table.ts` 平级)。
|
|
6
|
+
|
|
7
|
+
**CurdSchema 只依赖 table schema(`Field` 实例),不挂钩 DTO(`DtoMessage`)**——DTO 由生成器按标准从 `columns` 推导。
|
|
8
|
+
|
|
9
|
+
## 定义
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineCurd } from '@pylonts/dsl';
|
|
13
|
+
import { admin } from '../project.config';
|
|
14
|
+
import { order } from '../schema/order.table';
|
|
15
|
+
import { merchant } from '../schema/merchant.table';
|
|
16
|
+
import { orderListFilter } from '../filter_schema/api/admin/filter/order-list.filter';
|
|
17
|
+
|
|
18
|
+
export const orderCurd = defineCurd('order', { // name = table.name 的 kebab(即 admin 路由路径)
|
|
19
|
+
description: '订单管理',
|
|
20
|
+
app: admin, // 所属管理端(project.config.ts 的 FrontAppSchema 共享实例)
|
|
21
|
+
table: order, // 绑定实体表(共享实例)
|
|
22
|
+
title: '订单管理',
|
|
23
|
+
section: '订单管理', // 必填:sidebar 分组名
|
|
24
|
+
actions: [defineAction('EXPORT', '导出订单')], // 额外操作按钮
|
|
25
|
+
actionPages: {
|
|
26
|
+
add: { mode: 'modal', columns: [order.columns.order_no, order.columns.mer_id] },
|
|
27
|
+
update: { mode: 'modal', columns: [order.columns.id, order.columns.order_no] },
|
|
28
|
+
detail: { mode: 'route', columns: [order.columns.id, order.columns.order_no, order.columns.amount] },
|
|
29
|
+
},
|
|
30
|
+
list: {
|
|
31
|
+
columns: [order.columns.id, order.columns.order_no, merchant.columns.name], // 可跨表
|
|
32
|
+
filter: orderListFilter, // 搜索表单 + keyword(FilterSchema 引用,可选)
|
|
33
|
+
orderBy: { column: order.columns.id, direction: 'desc' },
|
|
34
|
+
columnTitles: { order_no: '订单号', name: '商户名称' }, // Field.name → 文案
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
搜索条件**不内联在 list 里**,而是独立的 **FilterSchema**(`defineFilter`)声明,存放在 `filter_schema/{api.name}/{app.name}/filter/`(机器校验:一文件一 filter,文件名 = 名字去 Filter 后缀转 kebab):
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// filter_schema/api/admin/filter/order-list.filter.ts
|
|
43
|
+
import { defineFilter } from '@pylonts/dsl';
|
|
44
|
+
import { admin, api } from '../../../project.config';
|
|
45
|
+
import { order } from '../../../schema/order.table';
|
|
46
|
+
|
|
47
|
+
export const orderListFilter = defineFilter({
|
|
48
|
+
name: 'OrderListFilter',
|
|
49
|
+
api,
|
|
50
|
+
app: admin,
|
|
51
|
+
conditions: [
|
|
52
|
+
{ field: order.columns.status, optional: true }, // op 默认 eq;optional = 有值才加 WHERE
|
|
53
|
+
{ field: order.columns.order_no, op: 'like', optional: true },
|
|
54
|
+
],
|
|
55
|
+
keyword: { columns: [order.columns.order_no] }, // 单输入值多列 OR 模糊
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
生成物为 `{api}/src/modules/{app}/filter/{FilterName}.ts`(两段柯里化 WHERE 拼装方法,DAO/Service 列表查询共用)。
|
|
60
|
+
|
|
61
|
+
## 字段
|
|
62
|
+
|
|
63
|
+
| 字段 | 类型 | 说明 |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `app` | `FrontAppSchema` | 所属管理端(共享实例,`type` 必须为 `'admin'`) |
|
|
66
|
+
| `table` | `TableSchema` | 绑定实体表(共享实例) |
|
|
67
|
+
| `title` | `string` | 列表页中文标题 |
|
|
68
|
+
| `section` | `string` | **必填**:sidebar 分组名 |
|
|
69
|
+
| `actions?` | `ActionSchema[]` | 页面额外可执行动作(标准 CRUD 之外,如导出、审核) |
|
|
70
|
+
| `actionPages?` | `{ add? / update? / detail? }` | 动作页:`{ mode: 'modal' \| 'route'; columns: Field[] }` |
|
|
71
|
+
| `list` | `CurdListConfig` | 列表页配置(必填) |
|
|
72
|
+
|
|
73
|
+
### ActionPage
|
|
74
|
+
|
|
75
|
+
| 字段 | 类型 | 说明 |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `mode` | `'modal' \| 'route'` | 弹窗或独立路由 |
|
|
78
|
+
| `columns` | `Field[]` | 该页面渲染的字段,**必填非空**——前端要显示的字段必须全部显式列出 |
|
|
79
|
+
|
|
80
|
+
### CurdListConfig
|
|
81
|
+
|
|
82
|
+
| 字段 | 类型 | 说明 |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `columns` | `Field[]` | 列表列,**必填非空**;可含跨表字段 |
|
|
85
|
+
| `filter?` | `FilterSchema` | 页面过滤器引用:搜索表单(AND 条件)+ keyword(多列 OR 模糊);缺省 = 无搜索表单 |
|
|
86
|
+
| `orderBy` | `{ column: Field; direction: 'asc' \| 'desc' }` | 默认排序,**必填**,column 与 direction 都必填;column 必须是**本表字段实例** |
|
|
87
|
+
| `columnTitles?` | `Record<string, string>` | 列标题覆盖:`Field.name` → 中文文案 |
|
|
88
|
+
|
|
89
|
+
### FilterSchema(`defineFilter`)
|
|
90
|
+
|
|
91
|
+
| 字段 | 类型 | 说明 |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `name` | `string` | PascalCase、`Filter` 结尾;导出名 = name 首字母小写 |
|
|
94
|
+
| `api` | `ProjectApiSchema` | 所属后端 api(project.config.ts 共享实例);`api.apps` 必须包含 `app` |
|
|
95
|
+
| `app` | `FrontAppSchema` | 所属前端 app(共享实例);必须与引用它的 curd 同 app |
|
|
96
|
+
| `conditions?` | `FilterCondition[]` | AND 组合条件:`{ field, op?='eq', right?, optional? }`;`optional: true` = 有值才加 WHERE(页面搜索场景) |
|
|
97
|
+
| `keyword?` | `{ columns: Field[] }` | 单输入值对多列 OR like 模糊;配置后驱动「关键词查询」端点(`query({ keyword })`,供 Select/AutoComplete 搜索) |
|
|
98
|
+
|
|
99
|
+
## 跨表字段
|
|
100
|
+
|
|
101
|
+
`list.columns` 与 filter `conditions` 里的 `Field` 实例可指向**本表或其他表**的列——列表列与搜索条件因此可以显示/过滤关联表字段(如订单列表显示商户名称、按商户名称过滤)。
|
|
102
|
+
|
|
103
|
+
## 默认与校验
|
|
104
|
+
|
|
105
|
+
- `list.columns` / `actionPages.*.columns` **必填非空**(不允许省略、不允许空数组)
|
|
106
|
+
- `list.orderBy` **必填**,`column` 与 `direction` 都必填(规格:默认主键 desc 由定义方显式写出)
|
|
107
|
+
- 运行时校验(`defineCurd`,仿 `defineTable` 强校验风格):
|
|
108
|
+
- `app.type` 必须为 `'admin'`,否则抛错
|
|
109
|
+
- **`name` 必须是 `table.name` 的 kebab 形式**(name 即 admin 路由路径,不允许与所服务的表漂移)
|
|
110
|
+
- `section` 必填
|
|
111
|
+
- 所有 `columns` 非空,否则抛错
|
|
112
|
+
- `list.filter.app` 必须 === `curd.app`,否则抛错
|
|
113
|
+
- `list.orderBy.column` 必须属于 `table`,否则抛错
|
|
114
|
+
- `list.columns` 允许跨表,**不校验归属**
|
|
115
|
+
- 运行时校验(`defineFilter`):`api.apps` 包含 `app`;conditions 与 keyword 不能同时为空;keyword.columns 非空
|
|
116
|
+
- 生成时校验(curd 生成器,`DtoSchemaGen.add` / `update`):
|
|
117
|
+
- 表配置 `autoIncrement` 或 `generator`(主键由服务端生成)时,`actionPages.add.columns` **不允许包含主键字段**,否则抛错——AddRequest 不携带服务端生成的主键
|
|
118
|
+
- `actionPages.update.columns` **必须包含主键字段**,否则抛错——UpdateRequest 靠主键定位记录
|
|
119
|
+
|
|
120
|
+
## DTO 推导(生成器约定)
|
|
121
|
+
|
|
122
|
+
DTO 由 curd 生成器从 `CurdSchema` 按标准命名推导,页面语义不持有 DTO 实例:
|
|
123
|
+
|
|
124
|
+
| DTO | 命名 | 字段来源 |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| Row | `{Pascal}Row` | `list.columns` |
|
|
127
|
+
| ListRequest | `{Pascal}ListRequest` | filter 的 conditions(camelCase + op)与 keyword + 分页参数(`PageRequest`,仅 paginated 表) |
|
|
128
|
+
| QueryRequest | `{Pascal}QueryRequest` | filter 的 conditions + keyword,无分页——keyword 查询端点专用(仅配置 keyword 时生成) |
|
|
129
|
+
| ListResponse | `{Pascal}ListResponse` | `PageResult(Row)`(仅 paginated 表;非分页表列表接口直接返回 `Row[]`,不生成 ListResponse) |
|
|
130
|
+
| AddRequest | `{Pascal}AddRequest` | `actionPages.add.columns` |
|
|
131
|
+
| UpdateRequest | `{Pascal}UpdateRequest` | `actionPages.update.columns` |
|
|
132
|
+
| DetailRequest | `{Pascal}DetailRequest` | 主键 |
|
|
133
|
+
| DetailResponse | `{Pascal}DetailResponse` | `actionPages.detail.columns` |
|
|
134
|
+
|
|
135
|
+
## 与旧 PageConfig 的差异
|
|
136
|
+
|
|
137
|
+
| PageConfig(旧方案,已废弃) | CurdSchema |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `module: string` | 由 `app` 推导(后端模块 == app 1:1) |
|
|
140
|
+
| `schema: 'bd'` 字符串 | `table: TableSchema` 实例(类型安全) |
|
|
141
|
+
| `operations: { label, action }` | `actions: ActionSchema[]` |
|
|
142
|
+
| `detail.mode` 单例 | `actionPages.detail.mode` |
|
|
143
|
+
| `forms.add / forms.update` | `actionPages.add / actionPages.update` |
|
|
144
|
+
| `keyword` / `orderBy` / `columnTitles` | `list.filter`(FilterSchema)/ `list.orderBy` / `list.columnTitles` |
|
|
145
|
+
| `naming` | 去掉(DTO 命名是生成器约定,非页面语义) |
|
|
146
|
+
| DTO 引用(`request` / `fields` / `DtoFields`) | 去掉(DTO 由生成器推导,页面只依赖 table) |
|