@yongdall/model 0.1.0

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/index.d.mts ADDED
@@ -0,0 +1,458 @@
1
+ import * as imodel0 from "imodel";
2
+ import { ClassDecorator, FieldDecorator, FieldDefine, FieldDefineOption, Fields, Hooks, IndexInfo, MainFieldType, TableDefine, ToType, VirtualTable } from "imodel";
3
+ import * as _yongdall_types0 from "@yongdall/types";
4
+ import { Field, Permission } from "@yongdall/types";
5
+ export * from "imodel";
6
+
7
+ //#region packages/model/createField.d.mts
8
+ /**
9
+ * @template {MainFieldType} T
10
+ * @overload
11
+ * @param {T} type
12
+ * @param {{
13
+ * nullable?: false;
14
+ * array?: false;
15
+ * default?: ToType<T, false, false> | symbol;
16
+ * } & FieldDefineOption & FieldDefineExtends} [options]
17
+ * @returns {FieldDefine<T, false, false>}
18
+ */
19
+ declare function createField<T extends MainFieldType>(type: T, options?: ({
20
+ nullable?: false;
21
+ array?: false;
22
+ default?: ToType<T, false, false> | symbol;
23
+ } & FieldDefineOption & FieldDefineExtends) | undefined): FieldDefine<T, false, false>;
24
+ /**
25
+ * @template {MainFieldType} T
26
+ * @overload
27
+ * @param {T} type
28
+ * @param {{
29
+ * nullable?: false;
30
+ * array: true;
31
+ * default?: ToType<T, true, false> | symbol;
32
+ * } & FieldDefineOption & FieldDefineExtends} options
33
+ * @returns {FieldDefine<T, true, false>}
34
+ */
35
+ declare function createField<T extends MainFieldType>(type: T, options: {
36
+ nullable?: false;
37
+ array: true;
38
+ default?: ToType<T, true, false> | symbol;
39
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, true, false>;
40
+ /**
41
+ * @template {MainFieldType} T
42
+ * @overload
43
+ * @param {T} type
44
+ * @param {{
45
+ * nullable: true;
46
+ * array?: false;
47
+ * default?: ToType<T, false, true> | symbol;
48
+ * } & FieldDefineOption & FieldDefineExtends} options
49
+ * @returns {FieldDefine<T, false, true>}
50
+ */
51
+ declare function createField<T extends MainFieldType>(type: T, options: {
52
+ nullable: true;
53
+ array?: false;
54
+ default?: ToType<T, false, true> | symbol;
55
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, false, true>;
56
+ /**
57
+ * @template {MainFieldType} T
58
+ * @overload
59
+ * @param {T} type
60
+ * @param {{
61
+ * nullable: true;
62
+ * array: true;
63
+ * default?: ToType<T, true, true> | symbol;
64
+ * } & FieldDefineOption & FieldDefineExtends} options
65
+ * @returns {FieldDefine<T, true, true>}
66
+ */
67
+ declare function createField<T extends MainFieldType>(type: T, options: {
68
+ nullable: true;
69
+ array: true;
70
+ default?: ToType<T, true, true> | symbol;
71
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, true, true>;
72
+ /**
73
+ * @template {MainFieldType} T
74
+ * @template {boolean} A
75
+ * @overload
76
+ * @param {T} type
77
+ * @param {{
78
+ * nullable: true;
79
+ * array: A;
80
+ * default?: ToType<T, A, true> | symbol;
81
+ * } & FieldDefineOption & FieldDefineExtends} options
82
+ * @returns {FieldDefine<T, A, true>}
83
+ */
84
+ declare function createField<T extends MainFieldType, A extends boolean>(type: T, options: {
85
+ nullable: true;
86
+ array: A;
87
+ default?: ToType<T, A, true> | symbol;
88
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, A, true>;
89
+ /**
90
+ * @template {MainFieldType} T
91
+ * @template {boolean} A
92
+ * @overload
93
+ * @param {T} type
94
+ * @param {{
95
+ * nullable?: false;
96
+ * array: A;
97
+ * default?: ToType<T, A, false> | symbol;
98
+ * } & FieldDefineOption & FieldDefineExtends} options
99
+ * @returns {FieldDefine<T, A, false>}
100
+ */
101
+ declare function createField<T extends MainFieldType, A extends boolean>(type: T, options: {
102
+ nullable?: false;
103
+ array: A;
104
+ default?: ToType<T, A, false> | symbol;
105
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, A, false>;
106
+ /**
107
+ * @template {MainFieldType} T
108
+ * @template {boolean} N
109
+ * @overload
110
+ * @param {T} type
111
+ * @param {{
112
+ * nullable: N;
113
+ * array?: false;
114
+ * default?: ToType<T, false, N> | symbol;
115
+ * } & FieldDefineOption & FieldDefineExtends} options
116
+ * @returns {FieldDefine<T, false, N>}
117
+ */
118
+ declare function createField<T extends MainFieldType, N extends boolean>(type: T, options: {
119
+ nullable: N;
120
+ array?: false;
121
+ default?: ToType<T, false, N> | symbol;
122
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, false, N>;
123
+ /**
124
+ * @template {MainFieldType} T
125
+ * @template {boolean} N
126
+ * @overload
127
+ * @param {T} type
128
+ * @param {{
129
+ * nullable: N;
130
+ * array: true;
131
+ * default?: ToType<T, true, N> | symbol;
132
+ * } & FieldDefineOption & FieldDefineExtends} options
133
+ * @returns {FieldDefine<T, true, N>}
134
+ */
135
+ declare function createField<T extends MainFieldType, N extends boolean>(type: T, options: {
136
+ nullable: N;
137
+ array: true;
138
+ default?: ToType<T, true, N> | symbol;
139
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, true, N>;
140
+ /**
141
+ * @template {MainFieldType} T
142
+ * @template {boolean} A
143
+ * @template {boolean} N
144
+ * @overload
145
+ * @param {T} type
146
+ * @param {{
147
+ * nullable: N;
148
+ * array: A;
149
+ * default?: ToType<T, A, N> | symbol;
150
+ * } & FieldDefineOption & FieldDefineExtends} options
151
+ * @returns {FieldDefine<T, A, N>}
152
+ */
153
+ declare function createField<T extends MainFieldType, A extends boolean, N extends boolean>(type: T, options: {
154
+ nullable: N;
155
+ array: A;
156
+ default?: ToType<T, A, N> | symbol;
157
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, A, N>;
158
+ /**
159
+ * @template {MainFieldType} T
160
+ * @overload
161
+ * @param {T} type
162
+ * @param {{
163
+ * nullable?: boolean;
164
+ * array?: boolean;
165
+ * default?: ToType<T, boolean, boolean> | symbol;
166
+ * } & FieldDefineOption & FieldDefineExtends} options
167
+ * @returns {FieldDefine<T, boolean, boolean>}
168
+ */
169
+ declare function createField<T extends MainFieldType>(type: T, options: {
170
+ nullable?: boolean;
171
+ array?: boolean;
172
+ default?: ToType<T, boolean, boolean> | symbol;
173
+ } & FieldDefineOption & FieldDefineExtends): FieldDefine<T, boolean, boolean>;
174
+ type FieldDefineExtends = {
175
+ /**
176
+ * - 字段序号
177
+ */
178
+ no?: number | undefined;
179
+ /**
180
+ * - 字段的显示标签。
181
+ */
182
+ label?: string | undefined;
183
+ /**
184
+ * - 字段的详细描述信息,可用于提示或帮助文本。
185
+ */
186
+ description?: string | undefined;
187
+ /**
188
+ * - 输入框等控件的占位提示文字。
189
+ */
190
+ placeholder?: string | undefined;
191
+ /**
192
+ * - 数值输入时的步长(如用于 number 类型 input 的 step 属性)。
193
+ */
194
+ step?: number | undefined;
195
+ /**
196
+ * - 字段允许的最大值(常用于数值或日期类型校验)。
197
+ */
198
+ max?: number | undefined;
199
+ /**
200
+ * - 字段允许的最小值(常用于数值或日期类型校验)。
201
+ */
202
+ min?: number | undefined;
203
+ /**
204
+ * - 是否只读,用户可聚焦但不可修改内容。
205
+ */
206
+ readonly?: boolean | undefined;
207
+ /**
208
+ * - 是否为必填项,用于表单验证。
209
+ */
210
+ required?: boolean | undefined;
211
+ /**
212
+ * - 是否支持清空操作(如带“×”按钮的输入框或选择器)。
213
+ */
214
+ clearable?: boolean | undefined;
215
+ /**
216
+ * - 是否禁用,禁用状态下用户无法交互且通常视觉上置灰。
217
+ */
218
+ disabled?: boolean | undefined;
219
+ /**
220
+ * - 字段所属的逻辑分组名称,用于权限分组。
221
+ */
222
+ group?: string | undefined;
223
+ /**
224
+ * - 布局顺序
225
+ */
226
+ layoutOrder?: number | undefined;
227
+ /**
228
+ * - 渲染器配置数组
229
+ */
230
+ renderer?: string | {
231
+ [k: string]: any;
232
+ component: string;
233
+ values?: any[];
234
+ } | (string | {
235
+ [k: string]: any;
236
+ component: string;
237
+ values?: any[];
238
+ })[] | undefined;
239
+ /**
240
+ * - 脚本列表,可以是字符串或 [脚本名, 配置对象] 的元组
241
+ */
242
+ scripts?: (string | [string, object])[] | undefined;
243
+ /**
244
+ * - 布局信息
245
+ */
246
+ layout?: Field.Layout | undefined;
247
+ /**
248
+ * - 关联模型
249
+ */
250
+ model?: string | undefined;
251
+ };
252
+ //#endregion
253
+ //#region packages/model/createModel.d.mts
254
+ /**
255
+ *
256
+ * @template {string | VirtualTable} [TT=string | VirtualTable]
257
+ * @template {Fields} [TF=Fields]
258
+ * @param {TT} table
259
+ * @param {TF} fields
260
+ * @param {ModelOptions} [options]
261
+ * @returns {ModelTable<TF, TT>}
262
+ */
263
+ declare function createModel<TT extends string | VirtualTable = string | VirtualTable<object>, TF extends Fields = Fields>(table: TT, fields: TF, {
264
+ pseudo,
265
+ indexes,
266
+ hooks,
267
+ databaseId,
268
+ ...options
269
+ }?: ModelOptions): ModelTable<TF, TT>;
270
+ /**
271
+ * 表定义配置接口
272
+ */
273
+ type ModelOptions = {
274
+ /**
275
+ * - 是否启用软删除
276
+ */
277
+ pseudo?: string | undefined;
278
+ /**
279
+ * - 索引信息
280
+ */
281
+ indexes?: IndexInfo[] | undefined;
282
+ /**
283
+ * - 钩子函数集合
284
+ */
285
+ hooks?: Partial<Hooks<Record<string, any>>> | undefined;
286
+ /**
287
+ * 权限配置
288
+ */
289
+ databaseId?: string | null | undefined;
290
+ label?: string | null | undefined;
291
+ /**
292
+ * 图标字段
293
+ */
294
+ iconField?: string | null | undefined;
295
+ /**
296
+ * 图像字段
297
+ */
298
+ imageField?: string | null | undefined;
299
+ /**
300
+ * 标签字段
301
+ */
302
+ labelField?: string | null | undefined;
303
+ /**
304
+ * 标签命名规则
305
+ */
306
+ labelPattern?: string | null | undefined;
307
+ /**
308
+ * 权限配置
309
+ */
310
+ permissions?: Permission[] | undefined;
311
+ /**
312
+ * 关联前端脚本
313
+ */
314
+ scripts?: (string | [string, object])[] | null | undefined;
315
+ };
316
+ type ModelTable<T extends Fields = Fields, TT extends string | VirtualTable | undefined = string | VirtualTable<object> | undefined> = TableDefine<T, TT> & {
317
+ databaseId?: string | null;
318
+ };
319
+ //#endregion
320
+ //#region packages/model/decorators.d.mts
321
+ /** @param {string} value */
322
+ declare function imageField(value: string): ClassDecorator;
323
+ /** @param {string} value */
324
+ declare function iconField(value: string): ClassDecorator;
325
+ /** @param {string} value */
326
+ declare function labelField(value: string): ClassDecorator;
327
+ /** @param {string} value */
328
+ declare function labelPattern(value: string): ClassDecorator;
329
+ /**
330
+ *
331
+ * @param {...Permission | Permission[]} permissions
332
+ * @returns {ClassDecorator}
333
+ */
334
+ declare function permission(...permissions: (Permission | Permission[])[]): ClassDecorator;
335
+ /**
336
+ *
337
+ * @param {string} label
338
+ * @returns {FieldDecorator<any> & ClassDecorator}
339
+ */
340
+ declare function label(label: string): FieldDecorator<any> & ClassDecorator;
341
+ /**
342
+ *
343
+ * @param {string} script
344
+ * @param {Record<string, any>} [options]
345
+ * @returns {FieldDecorator<any> & ClassDecorator}
346
+ */
347
+ declare function script(script: string, options?: Record<string, any>): FieldDecorator<any> & ClassDecorator;
348
+ /**
349
+ *
350
+ * @param {string} component
351
+ * @param {Record<string, any> | any[]} [options]
352
+ * @returns {FieldDecorator<any>}
353
+ */
354
+ declare function renderer(component: string, options?: Record<string, any> | any[]): FieldDecorator<any>;
355
+ /**
356
+ *
357
+ * @param {Field.Layout} layout
358
+ * @returns {FieldDecorator<any>}
359
+ */
360
+ declare function layout(layout: Field.Layout): FieldDecorator<any>;
361
+ /**
362
+ *
363
+ * @param {string} group
364
+ * @returns {FieldDecorator<any>}
365
+ */
366
+ declare function group(group: string): FieldDecorator<any>;
367
+ /**
368
+ *
369
+ * @param {string} description
370
+ * @returns {FieldDecorator<any>}
371
+ */
372
+ declare function description(description: string): FieldDecorator<any>;
373
+ /**
374
+ *
375
+ * @param {string} placeholder
376
+ * @returns {FieldDecorator<any>}
377
+ */
378
+ declare function placeholder(placeholder: string): FieldDecorator<any>;
379
+ /**
380
+ *
381
+ * @param {number} step
382
+ * @returns {FieldDecorator<any>}
383
+ */
384
+ declare function step(step: number): FieldDecorator<any>;
385
+ /**
386
+ *
387
+ * @param {number} max
388
+ * @returns {FieldDecorator<any>}
389
+ */
390
+ declare function max(max: number): FieldDecorator<any>;
391
+ /**
392
+ *
393
+ * @param {number} min
394
+ * @returns {FieldDecorator<any>}
395
+ */
396
+ declare function min(min: number): FieldDecorator<any>;
397
+ /**
398
+ *
399
+ * @param {boolean} [readonly]
400
+ * @returns {FieldDecorator<any>}
401
+ */
402
+ declare function readonly(readonly?: boolean): FieldDecorator<any>;
403
+ /**
404
+ *
405
+ * @param {boolean} [required]
406
+ * @returns {FieldDecorator<any>}
407
+ */
408
+ declare function required(required?: boolean): FieldDecorator<any>;
409
+ /**
410
+ *
411
+ * @param {boolean} [clearable]
412
+ * @returns {FieldDecorator<any>}
413
+ */
414
+ declare function clearable(clearable?: boolean): FieldDecorator<any>;
415
+ /**
416
+ *
417
+ * @param {boolean} [disabled]
418
+ * @returns {FieldDecorator<any>}
419
+ */
420
+ declare function disabled(disabled?: boolean): FieldDecorator<any>;
421
+ //#endregion
422
+ //#region packages/model/expandModel.d.mts
423
+ /** @import { Fields, TableDefine } from 'imodel' */
424
+ /** @import { ModelTable } from './createModel.mjs' */
425
+ /**
426
+ *
427
+ * @template {Fields<TableDefine>} [TF=Fields<TableDefine>]
428
+ * @param {ModelTable} model
429
+ * @param {TF} fields
430
+ * @returns {ModelTable}
431
+ */
432
+ declare function expandModel<TF extends Fields<TableDefine> = Fields<TableDefine<Fields<imodel0.MainFieldType>, string | imodel0.VirtualTable<object> | undefined>>>(model: ModelTable, fields: TF): ModelTable;
433
+ //#endregion
434
+ //#region packages/model/get.d.mts
435
+ /**
436
+ *
437
+ * @param {any} v
438
+ */
439
+ declare function getModelOptions(v: any): {
440
+ readonly label: string;
441
+ readonly iconField: string;
442
+ readonly imageField: string;
443
+ readonly labelPattern: any;
444
+ readonly permissions: _yongdall_types0.Permission[];
445
+ readonly scripts: (string | [string, object])[];
446
+ };
447
+ /**
448
+ *
449
+ * @param {any} v
450
+ */
451
+ declare function getDefinePermission(v: any): _yongdall_types0.Permission[];
452
+ /**
453
+ *
454
+ * @param {any} v
455
+ */
456
+ declare function getLabelPattern(v: any): any;
457
+ //#endregion
458
+ export { FieldDefineExtends, ModelOptions, ModelTable, clearable, createField, createModel, description, disabled, expandModel, getDefinePermission, getLabelPattern, getModelOptions, group, iconField, imageField, label, labelField, labelPattern, layout, max, min, permission, placeholder, readonly, renderer, required, script, step };
package/index.mjs ADDED
@@ -0,0 +1,495 @@
1
+ import { define, prop } from "imodel";
2
+
3
+ export * from "imodel"
4
+
5
+ //#region packages/model/createField.mjs
6
+ /** @import { FieldDefine, FieldDefineOption, MainFieldType, ToType } from 'imodel' */
7
+ /** @import { Field } from '@yongdall/types' */
8
+ /**
9
+ * @typedef {Object} FieldDefineExtends
10
+ * @property {number} [no] - 字段序号
11
+ * @property {string} [label] - 字段的显示标签。
12
+ * @property {string} [description] - 字段的详细描述信息,可用于提示或帮助文本。
13
+ * @property {string} [placeholder] - 输入框等控件的占位提示文字。
14
+ * @property {number} [step] - 数值输入时的步长(如用于 number 类型 input 的 step 属性)。
15
+ * @property {number} [max] - 字段允许的最大值(常用于数值或日期类型校验)。
16
+ * @property {number} [min] - 字段允许的最小值(常用于数值或日期类型校验)。
17
+ * @property {boolean} [readonly] - 是否只读,用户可聚焦但不可修改内容。
18
+ * @property {boolean} [required] - 是否为必填项,用于表单验证。
19
+ * @property {boolean} [clearable] - 是否支持清空操作(如带“×”按钮的输入框或选择器)。
20
+ * @property {boolean} [disabled] - 是否禁用,禁用状态下用户无法交互且通常视觉上置灰。
21
+ * @property {string} [group] - 字段所属的逻辑分组名称,用于权限分组。
22
+ * @property {number} [layoutOrder] - 布局顺序
23
+ * @property {({component: string; values?: any[]; [k: string]: any} | string)[] | {component: string; values?: any[]; [k: string]: any} | string} [renderer] - 渲染器配置数组
24
+ * @property {(string | [string, object])[]} [scripts] - 脚本列表,可以是字符串或 [脚本名, 配置对象] 的元组
25
+ * @property {Field.Layout} [layout] - 布局信息
26
+ * @property {string} [model] - 关联模型
27
+ */
28
+ /**
29
+ * @template {MainFieldType} T
30
+ * @overload
31
+ * @param {T} type
32
+ * @param {{
33
+ * nullable?: false;
34
+ * array?: false;
35
+ * default?: ToType<T, false, false> | symbol;
36
+ * } & FieldDefineOption & FieldDefineExtends} [options]
37
+ * @returns {FieldDefine<T, false, false>}
38
+ */
39
+ /**
40
+ * @template {MainFieldType} T
41
+ * @overload
42
+ * @param {T} type
43
+ * @param {{
44
+ * nullable?: false;
45
+ * array: true;
46
+ * default?: ToType<T, true, false> | symbol;
47
+ * } & FieldDefineOption & FieldDefineExtends} options
48
+ * @returns {FieldDefine<T, true, false>}
49
+ */
50
+ /**
51
+ * @template {MainFieldType} T
52
+ * @overload
53
+ * @param {T} type
54
+ * @param {{
55
+ * nullable: true;
56
+ * array?: false;
57
+ * default?: ToType<T, false, true> | symbol;
58
+ * } & FieldDefineOption & FieldDefineExtends} options
59
+ * @returns {FieldDefine<T, false, true>}
60
+ */
61
+ /**
62
+ * @template {MainFieldType} T
63
+ * @overload
64
+ * @param {T} type
65
+ * @param {{
66
+ * nullable: true;
67
+ * array: true;
68
+ * default?: ToType<T, true, true> | symbol;
69
+ * } & FieldDefineOption & FieldDefineExtends} options
70
+ * @returns {FieldDefine<T, true, true>}
71
+ */
72
+ /**
73
+ * @template {MainFieldType} T
74
+ * @template {boolean} A
75
+ * @overload
76
+ * @param {T} type
77
+ * @param {{
78
+ * nullable: true;
79
+ * array: A;
80
+ * default?: ToType<T, A, true> | symbol;
81
+ * } & FieldDefineOption & FieldDefineExtends} options
82
+ * @returns {FieldDefine<T, A, true>}
83
+ */
84
+ /**
85
+ * @template {MainFieldType} T
86
+ * @template {boolean} A
87
+ * @overload
88
+ * @param {T} type
89
+ * @param {{
90
+ * nullable?: false;
91
+ * array: A;
92
+ * default?: ToType<T, A, false> | symbol;
93
+ * } & FieldDefineOption & FieldDefineExtends} options
94
+ * @returns {FieldDefine<T, A, false>}
95
+ */
96
+ /**
97
+ * @template {MainFieldType} T
98
+ * @template {boolean} N
99
+ * @overload
100
+ * @param {T} type
101
+ * @param {{
102
+ * nullable: N;
103
+ * array?: false;
104
+ * default?: ToType<T, false, N> | symbol;
105
+ * } & FieldDefineOption & FieldDefineExtends} options
106
+ * @returns {FieldDefine<T, false, N>}
107
+ */
108
+ /**
109
+ * @template {MainFieldType} T
110
+ * @template {boolean} N
111
+ * @overload
112
+ * @param {T} type
113
+ * @param {{
114
+ * nullable: N;
115
+ * array: true;
116
+ * default?: ToType<T, true, N> | symbol;
117
+ * } & FieldDefineOption & FieldDefineExtends} options
118
+ * @returns {FieldDefine<T, true, N>}
119
+ */
120
+ /**
121
+ * @template {MainFieldType} T
122
+ * @template {boolean} A
123
+ * @template {boolean} N
124
+ * @overload
125
+ * @param {T} type
126
+ * @param {{
127
+ * nullable: N;
128
+ * array: A;
129
+ * default?: ToType<T, A, N> | symbol;
130
+ * } & FieldDefineOption & FieldDefineExtends} options
131
+ * @returns {FieldDefine<T, A, N>}
132
+ */
133
+ /**
134
+ * @template {MainFieldType} T
135
+ * @overload
136
+ * @param {T} type
137
+ * @param {{
138
+ * nullable?: boolean;
139
+ * array?: boolean;
140
+ * default?: ToType<T, boolean, boolean> | symbol;
141
+ * } & FieldDefineOption & FieldDefineExtends} options
142
+ * @returns {FieldDefine<T, boolean, boolean>}
143
+ */
144
+ /**
145
+ * @param {MainFieldType} type
146
+ * @param {any} [options]
147
+ * @returns {any}
148
+ */
149
+ function createField(type, options) {
150
+ return define(type, options);
151
+ }
152
+
153
+ //#endregion
154
+ //#region packages/model/metadata.mjs
155
+ /** @import { ModelOptions } from './createModel.mjs' */
156
+ const KEY = Symbol();
157
+ /**
158
+ *
159
+ * @param {any} metadata
160
+ * @returns {Omit<ModelOptions, 'pseudo' | 'indexes' | 'hooks' | 'databaseId'>}
161
+ */
162
+ function getMetadataExpand(metadata) {
163
+ return metadata[KEY] ||= {};
164
+ }
165
+ /**
166
+ *
167
+ * @param {any} model
168
+ * @returns {Omit<ModelOptions, 'pseudo' | 'indexes' | 'hooks' | 'databaseId'>}
169
+ */
170
+ function getExpandMetadata(model) {
171
+ if (!model) return {};
172
+ if (typeof model !== "function" && typeof model !== "object") return {};
173
+ return getMetadataExpand(model[Symbol.metadata] ||= {});
174
+ }
175
+ /**
176
+ * @template T
177
+ * @param {T} model
178
+ * @param {any} options
179
+ * @returns {T}
180
+ */
181
+ function setExpandMetadata(model, options) {
182
+ if (!model) return model;
183
+ if (typeof model !== "function" && typeof model !== "object") return model;
184
+ const metadata = model[Symbol.metadata] ||= {};
185
+ metadata[KEY] ||= options;
186
+ return model;
187
+ }
188
+
189
+ //#endregion
190
+ //#region packages/model/createModel.mjs
191
+ /** @import { Fields, Hooks, IndexInfo, VirtualTable, TableDefine } from 'imodel' */
192
+ /** @import { Permission } from '@yongdall/types' */
193
+ /**
194
+ * 表定义配置接口
195
+ * @typedef {Object} ModelOptions
196
+ * @property {string} [pseudo] - 是否启用软删除
197
+ * @property {IndexInfo[]} [indexes] - 索引信息
198
+ * @property {Partial<Hooks>} [hooks] - 钩子函数集合
199
+ * @property {string?} [databaseId] 权限配置
200
+ * @property {string?} [label]
201
+ * @property {string?} [iconField] 图标字段
202
+ * @property {string?} [imageField] 图像字段
203
+ * @property {string?} [labelField] 标签字段
204
+ * @property {string?} [labelPattern] 标签命名规则
205
+ * @property {Permission[]} [permissions] 权限配置
206
+ * @property {(string | [string, object])[] | null} [scripts] 关联前端脚本
207
+ */
208
+ /**
209
+ * @template {Fields} [T=Fields]
210
+ * @template {string | VirtualTable | undefined} [TT=string | VirtualTable | undefined]
211
+ * @typedef {TableDefine<T, TT> & {databaseId?: string?}} ModelTable
212
+ */
213
+ /**
214
+ *
215
+ * @template {string | VirtualTable} [TT=string | VirtualTable]
216
+ * @template {Fields} [TF=Fields]
217
+ * @param {TT} table
218
+ * @param {TF} fields
219
+ * @param {ModelOptions} [options]
220
+ * @returns {ModelTable<TF, TT>}
221
+ */
222
+ function createModel(table, fields, { pseudo, indexes, hooks, databaseId, ...options } = {}) {
223
+ return setExpandMetadata({
224
+ table,
225
+ fields,
226
+ pseudo,
227
+ indexes,
228
+ hooks,
229
+ databaseId
230
+ }, options);
231
+ }
232
+
233
+ //#endregion
234
+ //#region packages/model/decorators.mjs
235
+ /** @import { ClassDecorator, FieldDecorator } from 'imodel' */
236
+ /** @import { Permission } from '@yongdall/types' */
237
+ /** @import { Field } from '@yongdall/types' */
238
+ /** @import { ModelOptions } from './createModel.mjs' */
239
+ /**
240
+ * @template {Exclude<keyof ModelOptions, "pseudo" | "indexes" | "hooks">} T
241
+ * @param {T} key
242
+ * @param {ModelOptions[T]} value
243
+ * @returns {ClassDecorator}
244
+ */
245
+ function modelOption(key, value) {
246
+ return (v, c) => {
247
+ if (c.kind === "class") getMetadataExpand(c.metadata)[key] = value;
248
+ };
249
+ }
250
+ /** @param {string} value */
251
+ function imageField(value) {
252
+ return modelOption("imageField", value);
253
+ }
254
+ /** @param {string} value */
255
+ function iconField(value) {
256
+ return modelOption("iconField", value);
257
+ }
258
+ /** @param {string} value */
259
+ function labelField(value) {
260
+ return modelOption("labelField", value);
261
+ }
262
+ /** @param {string} value */
263
+ function labelPattern(value) {
264
+ return modelOption("labelPattern", value);
265
+ }
266
+ /**
267
+ *
268
+ * @param {...Permission | Permission[]} permissions
269
+ * @returns {ClassDecorator}
270
+ */
271
+ function permission(...permissions) {
272
+ const allPermissions = permissions.flat();
273
+ return (Model, ctx) => {
274
+ if (!allPermissions.length) return;
275
+ const list = getMetadataExpand(ctx.metadata).permissions ||= [];
276
+ for (const p of allPermissions) list.push(p);
277
+ };
278
+ }
279
+ /**
280
+ *
281
+ * @param {string} label
282
+ * @returns {FieldDecorator<any> & ClassDecorator}
283
+ */
284
+ function label(label) {
285
+ return (v, c) => {
286
+ if (c.kind === "class") getMetadataExpand(c.metadata).label = label;
287
+ else return prop("label", label)(v, c);
288
+ };
289
+ }
290
+ /**
291
+ *
292
+ * @param {string} script
293
+ * @param {Record<string, any>} [options]
294
+ * @returns {FieldDecorator<any> & ClassDecorator}
295
+ */
296
+ function script(script, options) {
297
+ /** @type {string | [string, object]} */
298
+ const item = options && typeof options === "object" ? [script, options] : script;
299
+ return (Model, ctx) => {
300
+ if (ctx.kind === "class") (getMetadataExpand(ctx.metadata).scripts ||= []).push(item);
301
+ else return prop("scripts", item, true)(Model, ctx);
302
+ };
303
+ }
304
+ /**
305
+ *
306
+ * @param {string} component
307
+ * @param {Record<string, any> | any[]} [options]
308
+ * @returns {FieldDecorator<any>}
309
+ */
310
+ function renderer(component, options) {
311
+ if (component && typeof component === "string") if (Array.isArray(options)) return prop("renderer", {
312
+ values: options,
313
+ component
314
+ }, true);
315
+ else if (options && typeof options === "object") return prop("renderer", {
316
+ ...options,
317
+ component
318
+ }, true);
319
+ else return prop("renderer", { component }, true);
320
+ throw new Error(`无效的渲染组件名: ${component}`);
321
+ }
322
+ /**
323
+ *
324
+ * @param {Field.Layout} layout
325
+ * @returns {FieldDecorator<any>}
326
+ */
327
+ function layout(layout) {
328
+ return prop("layout", layout);
329
+ }
330
+ /**
331
+ *
332
+ * @param {string} group
333
+ * @returns {FieldDecorator<any>}
334
+ */
335
+ function group(group) {
336
+ return prop("group", group);
337
+ }
338
+ /**
339
+ *
340
+ * @param {string} description
341
+ * @returns {FieldDecorator<any>}
342
+ */
343
+ function description(description) {
344
+ return prop("description", description);
345
+ }
346
+ /**
347
+ *
348
+ * @param {string} placeholder
349
+ * @returns {FieldDecorator<any>}
350
+ */
351
+ function placeholder(placeholder) {
352
+ return prop("placeholder", placeholder);
353
+ }
354
+ /**
355
+ *
356
+ * @param {number} step
357
+ * @returns {FieldDecorator<any>}
358
+ */
359
+ function step(step) {
360
+ return prop("step", step);
361
+ }
362
+ /**
363
+ *
364
+ * @param {number} max
365
+ * @returns {FieldDecorator<any>}
366
+ */
367
+ function max(max) {
368
+ return prop("max", max);
369
+ }
370
+ /**
371
+ *
372
+ * @param {number} min
373
+ * @returns {FieldDecorator<any>}
374
+ */
375
+ function min(min) {
376
+ return prop("min", min);
377
+ }
378
+ /**
379
+ *
380
+ * @param {boolean} [readonly]
381
+ * @returns {FieldDecorator<any>}
382
+ */
383
+ function readonly(readonly) {
384
+ return prop("readonly", typeof readonly === "boolean" ? readonly : true);
385
+ }
386
+ /**
387
+ *
388
+ * @param {boolean} [required]
389
+ * @returns {FieldDecorator<any>}
390
+ */
391
+ function required(required) {
392
+ return prop("required", typeof required === "boolean" ? required : true);
393
+ }
394
+ /**
395
+ *
396
+ * @param {boolean} [clearable]
397
+ * @returns {FieldDecorator<any>}
398
+ */
399
+ function clearable(clearable) {
400
+ return prop("clearable", typeof clearable === "boolean" ? clearable : true);
401
+ }
402
+ /**
403
+ *
404
+ * @param {boolean} [disabled]
405
+ * @returns {FieldDecorator<any>}
406
+ */
407
+ function disabled(disabled) {
408
+ return prop("disabled", typeof disabled === "boolean" ? disabled : true);
409
+ }
410
+
411
+ //#endregion
412
+ //#region packages/model/expandModel.mjs
413
+ /** @import { Fields, TableDefine } from 'imodel' */
414
+ /** @import { ModelTable } from './createModel.mjs' */
415
+ /**
416
+ *
417
+ * @template {Fields<TableDefine>} [TF=Fields<TableDefine>]
418
+ * @param {ModelTable} model
419
+ * @param {TF} fields
420
+ * @returns {ModelTable}
421
+ */
422
+ function expandModel(model, fields) {
423
+ const expands = Object.entries(fields).filter(([k, v]) => {
424
+ if (!v || typeof v !== "object") return;
425
+ const type = v.type;
426
+ if (!type || typeof type !== "object") return;
427
+ return type.table;
428
+ });
429
+ if (!expands.length) return model;
430
+ return {
431
+ ...model,
432
+ databaseId: model.databaseId,
433
+ fields: {
434
+ ...model.fields,
435
+ ...Object.fromEntries(expands.map(([k, v]) => [`$${k}`, v]))
436
+ },
437
+ pseudo: model.pseudo,
438
+ indexes: model.indexes,
439
+ hooks: model.hooks,
440
+ table: model.table,
441
+ [Symbol.metadata]: model[Symbol.metadata]
442
+ };
443
+ }
444
+
445
+ //#endregion
446
+ //#region packages/model/get.mjs
447
+ /**
448
+ *
449
+ * @param {any} v
450
+ */
451
+ function getModelOptions(v) {
452
+ const metadata = getExpandMetadata(v);
453
+ return {
454
+ get label() {
455
+ return getExpandMetadata(v).label || "";
456
+ },
457
+ get iconField() {
458
+ return getExpandMetadata(v).iconField || "";
459
+ },
460
+ get imageField() {
461
+ return getExpandMetadata(v).imageField || "";
462
+ },
463
+ get labelPattern() {
464
+ const labelPattern = metadata.labelPattern || v.labelPattern;
465
+ if (labelPattern) return labelPattern;
466
+ const labelField = metadata.labelField || v.labelField;
467
+ if (labelField) return `{${labelField}}`;
468
+ return "";
469
+ },
470
+ get permissions() {
471
+ return getExpandMetadata(v).permissions || [];
472
+ },
473
+ get scripts() {
474
+ return getExpandMetadata(v).scripts || [];
475
+ }
476
+ };
477
+ }
478
+ /**
479
+ *
480
+ * @param {any} v
481
+ */
482
+ function getDefinePermission(v) {
483
+ return getModelOptions(v).permissions;
484
+ }
485
+ /**
486
+ *
487
+ * @param {any} v
488
+ */
489
+ function getLabelPattern(v) {
490
+ return getModelOptions(v).labelPattern;
491
+ }
492
+
493
+ //#endregion
494
+ export { clearable, createField, createModel, description, disabled, expandModel, getDefinePermission, getLabelPattern, getModelOptions, group, iconField, imageField, label, labelField, labelPattern, layout, max, min, permission, placeholder, readonly, renderer, required, script, step };
495
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../packages/model/createField.mjs","../../packages/model/metadata.mjs","../../packages/model/createModel.mjs","../../packages/model/decorators.mjs","../../packages/model/expandModel.mjs","../../packages/model/get.mjs"],"sourcesContent":["/** @import { FieldDefine, FieldDefineOption, MainFieldType, ToType } from 'imodel' */\n/** @import { Field } from '@yongdall/types' */\nimport { define } from 'imodel';\n\n\n/**\n * @typedef {Object} FieldDefineExtends\n * @property {number} [no] - 字段序号\n * @property {string} [label] - 字段的显示标签。\n * @property {string} [description] - 字段的详细描述信息,可用于提示或帮助文本。\n * @property {string} [placeholder] - 输入框等控件的占位提示文字。\n * @property {number} [step] - 数值输入时的步长(如用于 number 类型 input 的 step 属性)。\n * @property {number} [max] - 字段允许的最大值(常用于数值或日期类型校验)。\n * @property {number} [min] - 字段允许的最小值(常用于数值或日期类型校验)。\n * @property {boolean} [readonly] - 是否只读,用户可聚焦但不可修改内容。\n * @property {boolean} [required] - 是否为必填项,用于表单验证。\n * @property {boolean} [clearable] - 是否支持清空操作(如带“×”按钮的输入框或选择器)。\n * @property {boolean} [disabled] - 是否禁用,禁用状态下用户无法交互且通常视觉上置灰。\n * @property {string} [group] - 字段所属的逻辑分组名称,用于权限分组。\n * @property {number} [layoutOrder] - 布局顺序\n * @property {({component: string; values?: any[]; [k: string]: any} | string)[] | {component: string; values?: any[]; [k: string]: any} | string} [renderer] - 渲染器配置数组\n * @property {(string | [string, object])[]} [scripts] - 脚本列表,可以是字符串或 [脚本名, 配置对象] 的元组\n * @property {Field.Layout} [layout] - 布局信息\n * @property {string} [model] - 关联模型\n */\n\n/**\n * @template {MainFieldType} T\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable?: false;\n * \tarray?: false;\n * \tdefault?: ToType<T, false, false> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} [options]\n * @returns {FieldDefine<T, false, false>}\n */\n/**\n * @template {MainFieldType} T\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable?: false;\n * \tarray: true;\n * \tdefault?: ToType<T, true, false> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, true, false>}\n */\n\n/**\n * @template {MainFieldType} T\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: true;\n * \tarray?: false;\n * \tdefault?: ToType<T, false, true> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, false, true>}\n */\n/**\n * @template {MainFieldType} T\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: true;\n * \tarray: true;\n * \tdefault?: ToType<T, true, true> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, true, true>}\n */\n\n/**\n * @template {MainFieldType} T\n * @template {boolean} A\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: true;\n * \tarray: A;\n * \tdefault?: ToType<T, A, true> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, A, true>}\n */\n/**\n * @template {MainFieldType} T\n * @template {boolean} A\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable?: false;\n * \tarray: A;\n * \tdefault?: ToType<T, A, false> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, A, false>}\n */\n\n/**\n * @template {MainFieldType} T\n * @template {boolean} N\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: N;\n * \tarray?: false;\n * \tdefault?: ToType<T, false, N> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, false, N>}\n */\n/**\n * @template {MainFieldType} T\n * @template {boolean} N\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: N;\n * \tarray: true;\n * \tdefault?: ToType<T, true, N> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, true, N>}\n */\n\n/**\n * @template {MainFieldType} T\n * @template {boolean} A\n * @template {boolean} N\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable: N;\n * \tarray: A;\n * \tdefault?: ToType<T, A, N> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, A, N>}\n */\n\n/**\n * @template {MainFieldType} T\n * @overload\n * @param {T} type\n * @param {{\n * \tnullable?: boolean;\n * \tarray?: boolean;\n * \tdefault?: ToType<T, boolean, boolean> | symbol;\n * } & FieldDefineOption & FieldDefineExtends} options\n * @returns {FieldDefine<T, boolean, boolean>}\n */\n\n/**\n * @param {MainFieldType} type\n * @param {any} [options]\n * @returns {any}\n */\nexport function createField(type, options) {\n\treturn define(type, options)\n}\n","/** @import { ModelOptions } from './createModel.mjs' */\nconst KEY = Symbol();\n/**\n * \n * @param {any} metadata \n * @returns {Omit<ModelOptions, 'pseudo' | 'indexes' | 'hooks' | 'databaseId'>}\n */\nexport function getMetadataExpand(metadata) {\n\treturn metadata[KEY] ||= {};\n}\n/**\n * \n * @param {any} model \n * @returns {Omit<ModelOptions, 'pseudo' | 'indexes' | 'hooks' | 'databaseId'>}\n */\nexport function getExpandMetadata(model) {\n\tif (!model) { return {}; }\n\tif (typeof model !== 'function' && typeof model !== 'object') { return {}; }\n\treturn getMetadataExpand(model[Symbol.metadata] ||= {});\n}\n/**\n * @template T\n * @param {T} model \n * @param {any} options \n * @returns {T}\n */\nexport function setExpandMetadata(model, options) {\n\tif (!model) { return model; }\n\tif (typeof model !== 'function' && typeof model !== 'object') { return model; }\n\t// @ts-ignore\n\tconst metadata = model[Symbol.metadata] ||= {};\n\tmetadata[KEY] ||= options;\n\treturn model;\n}\n","/** @import { Fields, Hooks, IndexInfo, VirtualTable, TableDefine } from 'imodel' */\n/** @import { Permission } from '@yongdall/types' */\n\n/**\n * 表定义配置接口\n * @typedef {Object} ModelOptions\n * @property {string} [pseudo] - 是否启用软删除\n * @property {IndexInfo[]} [indexes] - 索引信息\n * @property {Partial<Hooks>} [hooks] - 钩子函数集合\n * @property {string?} [databaseId] 权限配置\n * @property {string?} [label] \n * @property {string?} [iconField] 图标字段\n * @property {string?} [imageField] 图像字段\n * @property {string?} [labelField] 标签字段\n * @property {string?} [labelPattern] 标签命名规则\n * @property {Permission[]} [permissions] 权限配置\n * @property {(string | [string, object])[] | null} [scripts] 关联前端脚本\n */\n/**\n * @template {Fields} [T=Fields]\n * @template {string | VirtualTable | undefined} [TT=string | VirtualTable | undefined]\n * @typedef {TableDefine<T, TT> & {databaseId?: string?}} ModelTable\n */\nimport { setExpandMetadata } from './metadata.mjs';\n\n/**\n * \n * @template {string | VirtualTable} [TT=string | VirtualTable]\n * @template {Fields} [TF=Fields]\n * @param {TT} table \n * @param {TF} fields \n * @param {ModelOptions} [options] \n * @returns {ModelTable<TF, TT>}\n */\nexport function createModel(table, fields, {pseudo, indexes, hooks, databaseId, ...options} = {}) {\n\treturn setExpandMetadata({\n\t\ttable, fields, pseudo, indexes, hooks, databaseId,\n\t}, options);\n}\n","/** @import { ClassDecorator, FieldDecorator } from 'imodel' */\n/** @import { Permission } from '@yongdall/types' */\n/** @import { Field } from '@yongdall/types' */\n/** @import { ModelOptions } from './createModel.mjs' */\nimport { prop } from 'imodel';\nimport { getMetadataExpand } from './metadata.mjs';\n\n/**\n * @template {Exclude<keyof ModelOptions, \"pseudo\" | \"indexes\" | \"hooks\">} T\n * @param {T} key\n * @param {ModelOptions[T]} value\n * @returns {ClassDecorator}\n */\nfunction modelOption(key, value) {\n\treturn (v, c) => {\n\t\tif (c.kind === 'class') {\n\t\t\tgetMetadataExpand(c.metadata)[key] = value;\n\t\t}\n\t};\n\n}\n\n/** @param {string} value */\nexport function imageField(value) {\n\treturn modelOption('imageField', value);\n}\n\n/** @param {string} value */\nexport function iconField(value) {\n\treturn modelOption('iconField', value);\n}\n\n/** @param {string} value */\nexport function labelField(value) {\n\treturn modelOption('labelField', value);\n}\n/** @param {string} value */\nexport function labelPattern(value) {\n\treturn modelOption('labelPattern', value);\n}\n\n/**\n * \n * @param {...Permission | Permission[]} permissions \n * @returns {ClassDecorator}\n */\nexport function permission(...permissions) {\n\tconst allPermissions = permissions.flat();\n\treturn (Model, ctx) => {\n\t\tif (!allPermissions.length) { return; }\n\n\t\tconst list = getMetadataExpand(ctx.metadata).permissions ||= [];\n\t\tfor (const p of allPermissions) {\n\t\t\tlist.push(p);\n\t\t}\n\t};\n}\n\n\n\n/**\n * \n * @param {string} label \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\nexport function label(label) {\n\treturn (v, c) => {\n\t\tif (c.kind === 'class') {\n\t\t\tgetMetadataExpand(c.metadata).label = label;\n\t\t} else {\n\t\t\t// @ts-ignore\n\t\t\treturn prop('label', label)(v, c);\n\t\t}\n\t};\n}\n\n/**\n * \n * @param {string} script \n * @param {Record<string, any>} [options] \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\nexport function script(script, options) {\n\t/** @type {string | [string, object]} */\n\tconst item = options && typeof options === 'object' ? [script, options] : script;\n\treturn (Model, ctx) => {\n\t\tif (ctx.kind === 'class') {\n\t\t\tconst list = getMetadataExpand(ctx.metadata).scripts ||= [];\n\t\t\tlist.push(item);\n\t\t} else {\n\t\t\t// @ts-ignore\n\t\t\treturn prop('scripts', item, true)(Model, ctx);\n\t\t}\n\t};\n}\n\n\n/**\n * \n * @param {string} component\n * @param {Record<string, any> | any[]} [options] \n * @returns {FieldDecorator<any>}\n */\nexport function renderer(component, options) {\n\tif (component && typeof component === 'string') {\n\t\tif (Array.isArray(options)) {\n\t\t\treturn prop('renderer', { values: options, component }, true);\n\t\t} else if (options && typeof options === 'object') {\n\t\t\treturn prop('renderer', { ...options, component }, true);\n\t\t} else {\n\t\t\treturn prop('renderer', { component }, true);\n\t\t}\n\t}\n\tthrow new Error(`无效的渲染组件名: ${component}`);\n}\n\n/**\n * \n * @param {Field.Layout} layout\n * @returns {FieldDecorator<any>}\n */\nexport function layout(layout) {\n\treturn prop('layout', layout);\n}\n\n/**\n * \n * @param {string} group\n * @returns {FieldDecorator<any>}\n */\nexport function group(group) {\n\treturn prop('group', group);\n}\n\n/**\n * \n * @param {string} description\n * @returns {FieldDecorator<any>}\n */\nexport function description(description) {\n\treturn prop('description', description);\n}\n\n/**\n * \n * @param {string} placeholder\n * @returns {FieldDecorator<any>}\n */\nexport function placeholder(placeholder) {\n\treturn prop('placeholder', placeholder);\n}\n\n/**\n * \n * @param {number} step\n * @returns {FieldDecorator<any>}\n */\nexport function step(step) {\n\treturn prop('step', step);\n}\n\n/**\n * \n * @param {number} max\n * @returns {FieldDecorator<any>}\n */\nexport function max(max) {\n\treturn prop('max', max);\n}\n\n/**\n * \n * @param {number} min\n * @returns {FieldDecorator<any>}\n */\nexport function min(min) {\n\treturn prop('min', min);\n}\n\n\n/**\n * \n * @param {boolean} [readonly]\n * @returns {FieldDecorator<any>}\n */\nexport function readonly(readonly) {\n\treturn prop('readonly', typeof readonly === 'boolean' ? readonly : true);\n}\n\n/**\n * \n * @param {boolean} [required]\n * @returns {FieldDecorator<any>}\n */\nexport function required(required) {\n\treturn prop('required', typeof required === 'boolean' ? required : true);\n}\n\n/**\n * \n * @param {boolean} [clearable]\n * @returns {FieldDecorator<any>}\n */\nexport function clearable(clearable) {\n\treturn prop('clearable', typeof clearable === 'boolean' ? clearable : true);\n}\n\n/**\n * \n * @param {boolean} [disabled]\n * @returns {FieldDecorator<any>}\n */\nexport function disabled(disabled) {\n\treturn prop('disabled', typeof disabled === 'boolean' ? disabled : true);\n}\n","/** @import { Fields, TableDefine } from 'imodel' */\n/** @import { ModelTable } from './createModel.mjs' */\n\n\n\n/**\n * \n * @template {Fields<TableDefine>} [TF=Fields<TableDefine>]\n * @param {ModelTable} model \n * @param {TF} fields \n * @returns {ModelTable}\n */\nexport function expandModel(model, fields) {\n\tconst expands = Object.entries(fields).filter(([k, v]) => {\n\t\tif (!v || typeof v !== 'object') { return; }\n\t\tconst type = v.type;\n\t\tif (!type || typeof type !== 'object') { return; }\n\t\treturn type.table;\n\t})\n\tif (!expands.length) { return model; }\n\treturn {\n\t\t...model,\n\t\tdatabaseId: model.databaseId,\n\t\tfields: {\n\t\t\t...model.fields,\n\t\t\t...Object.fromEntries(expands.map(([k,v]) => [`$${k}`, v])),\n\t\t},\n\t\tpseudo: model.pseudo,\n\t\tindexes: model.indexes,\n\t\thooks: model.hooks,\n\t\ttable: model.table,\n\t\t// @ts-ignore\n\t\t[Symbol.metadata]: model[Symbol.metadata],\n\t}\n}\n","import { getExpandMetadata } from './metadata.mjs';\n\n/**\n * \n * @param {any} v \n */\nexport function getModelOptions(v) {\n\tconst metadata = getExpandMetadata(v);\n\treturn {\n\t\tget label() {\n\t\t\treturn getExpandMetadata(v).label || '';\n\t\t},\n\t\tget iconField() {\n\t\t\treturn getExpandMetadata(v).iconField || '';\n\t\t},\n\t\tget imageField() {\n\t\t\treturn getExpandMetadata(v).imageField || '';\n\t\t},\n\t\tget labelPattern() {\n\t\t\tconst labelPattern = metadata.labelPattern || v.labelPattern;\n\t\t\tif (labelPattern) { return labelPattern; }\n\t\t\tconst labelField = metadata.labelField || v.labelField;\n\t\t\tif (labelField) {\n\t\t\t\treturn `{${labelField}}`;\n\t\t\t}\n\t\t\treturn '';\n\t\t},\n\t\tget permissions() {\n\t\t\treturn getExpandMetadata(v).permissions || [];\n\t\t},\n\t\tget scripts() {\n\t\t\treturn getExpandMetadata(v).scripts || [];\n\t\t},\n\t\t\n\t};\n\n}\n\n\n/**\n * \n * @param {any} v \n */\nexport function getDefinePermission(v) {\n\treturn getModelOptions(v).permissions;\n}\n\n/**\n * \n * @param {any} v \n */\nexport function getLabelPattern(v) {\n\treturn getModelOptions(v).labelPattern;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyJA,SAAgB,YAAY,MAAM,SAAS;AAC1C,QAAO,OAAO,MAAM,QAAQ;;;;;;ACzJ7B,MAAM,MAAM,QAAQ;;;;;;AAMpB,SAAgB,kBAAkB,UAAU;AAC3C,QAAO,SAAS,SAAS,EAAE;;;;;;;AAO5B,SAAgB,kBAAkB,OAAO;AACxC,KAAI,CAAC,MAAS,QAAO,EAAE;AACvB,KAAI,OAAO,UAAU,cAAc,OAAO,UAAU,SAAY,QAAO,EAAE;AACzE,QAAO,kBAAkB,MAAM,OAAO,cAAc,EAAE,CAAC;;;;;;;;AAQxD,SAAgB,kBAAkB,OAAO,SAAS;AACjD,KAAI,CAAC,MAAS,QAAO;AACrB,KAAI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AAG;AACtC,QAAO,gBAAgB,EAAE,CAAC;;;;;;AAO3B,SAAgB,gBAAgB,GAAG;AAClC,QAAO,gBAAgB,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@yongdall/model",
3
+ "type": "module",
4
+ "main": "./index.mjs",
5
+ "exports": {
6
+ ".": "./index.mjs"
7
+ },
8
+ "version": "0.1.0",
9
+ "description": "",
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "imodel": "^0.13.0"
15
+ },
16
+ "devDependencies": {
17
+ "@yongdall/types": "^0.1.0"
18
+ }
19
+ }