@pylonts/dsl 1.1.1 → 1.1.3

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.
Files changed (72) hide show
  1. package/dist/action.d.ts +7 -0
  2. package/dist/action.js +3 -0
  3. package/dist/asset.d.ts +2 -2
  4. package/dist/asset.js +2 -2
  5. package/dist/component.d.ts +20 -0
  6. package/dist/component.js +1 -0
  7. package/dist/convert.d.ts +9 -0
  8. package/dist/convert.js +3 -0
  9. package/dist/curd.d.ts +3 -1
  10. package/dist/db.d.ts +4 -0
  11. package/dist/db.js +29 -0
  12. package/dist/dsl.d.ts +5 -0
  13. package/dist/dto.d.ts +2 -2
  14. package/dist/dto.js +1 -1
  15. package/dist/event.d.ts +8 -0
  16. package/dist/event.js +3 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.js +10 -0
  19. package/dist/mermaid-driver.js +2 -1
  20. package/dist/mock.d.ts +3 -21
  21. package/dist/mock.js +1 -18
  22. package/dist/mysql-driver.d.ts +4 -0
  23. package/dist/mysql-driver.js +8 -3
  24. package/dist/navigation.d.ts +22 -0
  25. package/dist/navigation.js +15 -0
  26. package/dist/page-def.d.ts +40 -0
  27. package/dist/page-def.js +38 -0
  28. package/dist/page-flow.d.ts +4 -2
  29. package/dist/page-flow.js +107 -12
  30. package/dist/page.d.ts +32 -10
  31. package/dist/page.js +20 -5
  32. package/dist/popup.d.ts +18 -0
  33. package/dist/popup.js +8 -0
  34. package/dist/project.d.ts +7 -0
  35. package/dist/provider.d.ts +54 -0
  36. package/dist/provider.js +18 -0
  37. package/dist/ref.d.ts +14 -0
  38. package/dist/ref.js +6 -0
  39. package/dist/route.d.ts +8 -0
  40. package/dist/route.js +3 -0
  41. package/docs/curd.md +110 -110
  42. package/docs/dto.md +66 -66
  43. package/docs/table.md +4 -2
  44. package/package.json +1 -1
  45. package/src/action.ts +11 -0
  46. package/src/asset.ts +63 -63
  47. package/src/bases.ts +29 -29
  48. package/src/component.ts +22 -0
  49. package/src/convert.ts +13 -0
  50. package/src/curd.ts +93 -91
  51. package/src/db.ts +37 -0
  52. package/src/dsl.ts +188 -182
  53. package/src/dto.ts +247 -247
  54. package/src/enum-driver.ts +42 -42
  55. package/src/event.ts +12 -0
  56. package/src/flow.ts +103 -103
  57. package/src/index.ts +31 -21
  58. package/src/mermaid-driver.ts +2 -1
  59. package/src/mock.ts +12 -45
  60. package/src/mysql-driver.ts +8 -2
  61. package/src/navigation.ts +29 -0
  62. package/src/page-def.ts +80 -0
  63. package/src/page-flow.ts +116 -14
  64. package/src/page.ts +51 -14
  65. package/src/patterns/retry.ts +54 -54
  66. package/src/popup.ts +25 -0
  67. package/src/project.ts +97 -90
  68. package/src/prototype.ts +29 -29
  69. package/src/provider.ts +73 -0
  70. package/src/ref.ts +19 -0
  71. package/src/route.ts +12 -0
  72. package/src/utils.ts +10 -10
package/src/dsl.ts CHANGED
@@ -1,183 +1,189 @@
1
- // DSL field type definitions.
2
- // Shape: { type: <type name>, <extension fields> }
3
-
4
- import type { DictionaryEntry } from './dictionary.js';
5
- import type { MockDescriptor } from './mock.js';
6
-
7
- /** Field query comparison operators (search field semantics). */
8
- export type Operator = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ne';
9
-
10
- export interface SchemaBase {
11
- name: string;
12
- description?: string;
13
- }
14
-
15
- /** Field collection schemas (DB table vs DTO message); `type` is the discriminator */
16
- export interface CollectionSchemaBase extends SchemaBase {
17
- type: string;
18
- }
19
-
20
- export interface BaseField {
21
- name: string;
22
- /** 显示名称(中文标签) */
23
- label?: string;
24
- /** 字段描述 */
25
- description?: string;
26
- optional?: boolean;
27
- readOnly?: boolean;
28
- default?: string;
29
- /** 所属 schema(db 或 dto) */
30
- schema?: CollectionSchemaBase;
31
- /** Pure-data mock descriptor for test data generation */
32
- mock?: MockDescriptor;
33
- }
34
-
35
- interface StringField extends BaseField {
36
- type: 'string';
37
- jsType: 'string';
38
- minLength?: number;
39
- maxLength?: number;
40
- }
41
-
42
- interface TextField extends BaseField {
43
- type: 'text';
44
- jsType: 'string';
45
- }
46
-
47
- interface IntField extends BaseField {
48
- type: 'integer';
49
- jsType: 'number';
50
- min?: number;
51
- max?: number;
52
- }
53
-
54
- interface BigintField extends BaseField {
55
- type: 'bigint';
56
- jsType: 'string';
57
- // Value is transported as string to keep precision beyond 2^53.
58
- }
59
-
60
- interface DecimalField extends BaseField {
61
- type: 'decimal';
62
- jsType: 'string';
63
- precision: number;
64
- scale: number;
65
- // Value is transported as string to avoid binary float error.
66
- }
67
-
68
- interface BooleanField extends BaseField {
69
- type: 'boolean';
70
- jsType: 'boolean';
71
- }
72
-
73
- interface DateField extends BaseField {
74
- type: 'date';
75
- jsType: 'Date';
76
- }
77
-
78
- interface TimeField extends BaseField {
79
- type: 'time';
80
- jsType: 'string';
81
- }
82
-
83
- interface DateTimeField extends BaseField {
84
- type: 'datetime';
85
- jsType: 'Date';
86
- }
87
-
88
- export interface EnumValue {
89
- value: string | number;
90
- symbol: string;
91
- label: string;
92
- }
93
-
94
- /** Shared enum definition. Pure value object, safe to reference from multiple fields/tables. */
95
- export interface EnumDef {
96
- /** JS 定义名称,如 MerchantStatus */
97
- jsName: string;
98
- valueType: 'string' | 'integer';
99
- values: EnumValue[];
100
- }
101
-
102
- export function defineEnum(
103
- jsName: string,
104
- valueType: 'string' | 'integer',
105
- values: EnumValue[],
106
- ): EnumDef {
107
- return { jsName, valueType, values };
108
- }
109
-
110
- export interface EnumField extends BaseField {
111
- type: 'enum';
112
- jsType: 'string' | 'number';
113
- /** Reference to a shared enum definition (see defineEnum). */
114
- enum: EnumDef;
115
- }
116
-
117
- interface JsonField extends BaseField {
118
- type: 'json';
119
- jsType: 'object';
120
- }
121
-
122
- export type Field =
123
- | StringField
124
- | TextField
125
- | IntField
126
- | BigintField
127
- | DecimalField
128
- | BooleanField
129
- | DateField
130
- | TimeField
131
- | DateTimeField
132
- | EnumField
133
- | JsonField;
134
-
135
- // Field builders: type and jsType are fixed, pass extra properties only.
136
- // The field name is written back from the map key later (see defineTable).
137
-
138
- type FieldExtras<T extends Field> = Omit<T, 'name' | 'type' | 'jsType'>;
139
-
140
- export function stringField(extra: FieldExtras<StringField> = {}): StringField {
141
- return { name: '', type: 'string', jsType: 'string', ...extra };
142
- }
143
-
144
- export function textField(extra: FieldExtras<TextField> = {}): TextField {
145
- return { name: '', type: 'text', jsType: 'string', ...extra };
146
- }
147
-
148
- export function intField(extra: FieldExtras<IntField> = {}): IntField {
149
- return { name: '', type: 'integer', jsType: 'number', ...extra };
150
- }
151
-
152
- export function bigintField(extra: FieldExtras<BigintField> = {}): BigintField {
153
- return { name: '', type: 'bigint', jsType: 'string', ...extra };
154
- }
155
-
156
- export function decimalField(extra: FieldExtras<DecimalField>): DecimalField {
157
- return { name: '', type: 'decimal', jsType: 'string', ...extra };
158
- }
159
-
160
- export function booleanField(extra: FieldExtras<BooleanField> = {}): BooleanField {
161
- return { name: '', type: 'boolean', jsType: 'boolean', ...extra };
162
- }
163
-
164
- export function dateField(extra: FieldExtras<DateField> = {}): DateField {
165
- return { name: '', type: 'date', jsType: 'Date', ...extra };
166
- }
167
-
168
- export function timeField(extra: FieldExtras<TimeField> = {}): TimeField {
169
- return { name: '', type: 'time', jsType: 'string', ...extra };
170
- }
171
-
172
- export function datetimeField(extra: FieldExtras<DateTimeField> = {}): DateTimeField {
173
- return { name: '', type: 'datetime', jsType: 'Date', ...extra };
174
- }
175
-
176
- export function jsonField(extra: FieldExtras<JsonField> = {}): JsonField {
177
- return { name: '', type: 'json', jsType: 'object', ...extra };
178
- }
179
-
180
- export function enumField(extra: Omit<EnumField, 'name' | 'type' | 'jsType'>): EnumField {
181
- const jsType = extra.enum.valueType === 'integer' ? 'number' : 'string';
182
- return { name: '', type: 'enum', jsType, ...extra };
1
+ // DSL field type definitions.
2
+ // Shape: { type: <type name>, <extension fields> }
3
+
4
+ import type { DictionaryEntry } from './dictionary.js';
5
+ import type { ImportBase } from './import-base.js';
6
+ import type { MockDescriptor } from './mock.js';
7
+
8
+ /** Field query comparison operators (search field semantics). */
9
+ export type Operator = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ne';
10
+
11
+ export interface SchemaBase {
12
+ name: string;
13
+ description?: string;
14
+ }
15
+
16
+ /** Schema base for cross-file entities. importRef locates the generating module; inline schemas omit it. */
17
+ export interface ImportableSchemaBase extends SchemaBase {
18
+ importRef?: ImportBase;
19
+ }
20
+
21
+ /** Field collection schemas (DB table vs DTO message); `type` is the discriminator */
22
+ export interface CollectionSchemaBase extends SchemaBase {
23
+ type: string;
24
+ }
25
+
26
+ export interface BaseField {
27
+ name: string;
28
+ /** 显示名称(中文标签) */
29
+ label?: string;
30
+ /** 字段描述 */
31
+ description?: string;
32
+ optional?: boolean;
33
+ readOnly?: boolean;
34
+ default?: string;
35
+ /** 所属 schema(db dto) */
36
+ schema?: CollectionSchemaBase;
37
+ /** Pure-data mock descriptor for test data generation */
38
+ mock?: MockDescriptor;
39
+ }
40
+
41
+ interface StringField extends BaseField {
42
+ type: 'string';
43
+ jsType: 'string';
44
+ minLength?: number;
45
+ maxLength?: number;
46
+ }
47
+
48
+ interface TextField extends BaseField {
49
+ type: 'text';
50
+ jsType: 'string';
51
+ }
52
+
53
+ interface IntField extends BaseField {
54
+ type: 'integer';
55
+ jsType: 'number';
56
+ min?: number;
57
+ max?: number;
58
+ }
59
+
60
+ interface BigintField extends BaseField {
61
+ type: 'bigint';
62
+ jsType: 'string';
63
+ // Value is transported as string to keep precision beyond 2^53.
64
+ }
65
+
66
+ interface DecimalField extends BaseField {
67
+ type: 'decimal';
68
+ jsType: 'string';
69
+ precision: number;
70
+ scale: number;
71
+ // Value is transported as string to avoid binary float error.
72
+ }
73
+
74
+ interface BooleanField extends BaseField {
75
+ type: 'boolean';
76
+ jsType: 'boolean';
77
+ }
78
+
79
+ interface DateField extends BaseField {
80
+ type: 'date';
81
+ jsType: 'Date';
82
+ }
83
+
84
+ interface TimeField extends BaseField {
85
+ type: 'time';
86
+ jsType: 'string';
87
+ }
88
+
89
+ interface DateTimeField extends BaseField {
90
+ type: 'datetime';
91
+ jsType: 'Date';
92
+ }
93
+
94
+ export interface EnumValue {
95
+ value: string | number;
96
+ symbol: string;
97
+ label: string;
98
+ }
99
+
100
+ /** Shared enum definition. Pure value object, safe to reference from multiple fields/tables. */
101
+ export interface EnumDef {
102
+ /** JS 定义名称,如 MerchantStatus */
103
+ jsName: string;
104
+ valueType: 'string' | 'integer';
105
+ values: EnumValue[];
106
+ }
107
+
108
+ export function defineEnum(
109
+ jsName: string,
110
+ valueType: 'string' | 'integer',
111
+ values: EnumValue[],
112
+ ): EnumDef {
113
+ return { jsName, valueType, values };
114
+ }
115
+
116
+ export interface EnumField extends BaseField {
117
+ type: 'enum';
118
+ jsType: 'string' | 'number';
119
+ /** Reference to a shared enum definition (see defineEnum). */
120
+ enum: EnumDef;
121
+ }
122
+
123
+ interface JsonField extends BaseField {
124
+ type: 'json';
125
+ jsType: 'object';
126
+ }
127
+
128
+ export type Field =
129
+ | StringField
130
+ | TextField
131
+ | IntField
132
+ | BigintField
133
+ | DecimalField
134
+ | BooleanField
135
+ | DateField
136
+ | TimeField
137
+ | DateTimeField
138
+ | EnumField
139
+ | JsonField;
140
+
141
+ // Field builders: type and jsType are fixed, pass extra properties only.
142
+ // The field name is written back from the map key later (see defineTable).
143
+
144
+ type FieldExtras<T extends Field> = Omit<T, 'name' | 'type' | 'jsType'>;
145
+
146
+ export function stringField(extra: FieldExtras<StringField> = {}): StringField {
147
+ return { name: '', type: 'string', jsType: 'string', ...extra };
148
+ }
149
+
150
+ export function textField(extra: FieldExtras<TextField> = {}): TextField {
151
+ return { name: '', type: 'text', jsType: 'string', ...extra };
152
+ }
153
+
154
+ export function intField(extra: FieldExtras<IntField> = {}): IntField {
155
+ return { name: '', type: 'integer', jsType: 'number', ...extra };
156
+ }
157
+
158
+ export function bigintField(extra: FieldExtras<BigintField> = {}): BigintField {
159
+ return { name: '', type: 'bigint', jsType: 'string', ...extra };
160
+ }
161
+
162
+ export function decimalField(extra: FieldExtras<DecimalField>): DecimalField {
163
+ return { name: '', type: 'decimal', jsType: 'string', ...extra };
164
+ }
165
+
166
+ export function booleanField(extra: FieldExtras<BooleanField> = {}): BooleanField {
167
+ return { name: '', type: 'boolean', jsType: 'boolean', ...extra };
168
+ }
169
+
170
+ export function dateField(extra: FieldExtras<DateField> = {}): DateField {
171
+ return { name: '', type: 'date', jsType: 'Date', ...extra };
172
+ }
173
+
174
+ export function timeField(extra: FieldExtras<TimeField> = {}): TimeField {
175
+ return { name: '', type: 'time', jsType: 'string', ...extra };
176
+ }
177
+
178
+ export function datetimeField(extra: FieldExtras<DateTimeField> = {}): DateTimeField {
179
+ return { name: '', type: 'datetime', jsType: 'Date', ...extra };
180
+ }
181
+
182
+ export function jsonField(extra: FieldExtras<JsonField> = {}): JsonField {
183
+ return { name: '', type: 'json', jsType: 'object', ...extra };
184
+ }
185
+
186
+ export function enumField(extra: Omit<EnumField, 'name' | 'type' | 'jsType'>): EnumField {
187
+ const jsType = extra.enum.valueType === 'integer' ? 'number' : 'string';
188
+ return { name: '', type: 'enum', jsType, ...extra };
183
189
  }