@yongdall/model 0.1.0 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +34 -1
- package/index.mjs +63 -2
- package/index.mjs.map +1 -1
- package/package.json +2 -2
package/index.d.mts
CHANGED
|
@@ -312,6 +312,10 @@ type ModelOptions = {
|
|
|
312
312
|
* 关联前端脚本
|
|
313
313
|
*/
|
|
314
314
|
scripts?: (string | [string, object])[] | null | undefined;
|
|
315
|
+
/**
|
|
316
|
+
* 关联默认页面
|
|
317
|
+
*/
|
|
318
|
+
pages?: Record<string, string | object | null> | null | undefined;
|
|
315
319
|
};
|
|
316
320
|
type ModelTable<T extends Fields = Fields, TT extends string | VirtualTable | undefined = string | VirtualTable<object> | undefined> = TableDefine<T, TT> & {
|
|
317
321
|
databaseId?: string | null;
|
|
@@ -326,6 +330,34 @@ declare function iconField(value: string): ClassDecorator;
|
|
|
326
330
|
declare function labelField(value: string): ClassDecorator;
|
|
327
331
|
/** @param {string} value */
|
|
328
332
|
declare function labelPattern(value: string): ClassDecorator;
|
|
333
|
+
/**
|
|
334
|
+
* @param {string?} value
|
|
335
|
+
* @returns {ClassDecorator}
|
|
336
|
+
*/
|
|
337
|
+
declare function database(value: string | null): ClassDecorator;
|
|
338
|
+
/**
|
|
339
|
+
*
|
|
340
|
+
* @overload
|
|
341
|
+
* @param {Record<string, string | object | boolean>} pages
|
|
342
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
343
|
+
*/
|
|
344
|
+
declare function page(pages: Record<string, string | object | boolean>): FieldDecorator<any> & ClassDecorator;
|
|
345
|
+
/**
|
|
346
|
+
*
|
|
347
|
+
* @overload
|
|
348
|
+
* @param {string} page
|
|
349
|
+
* @param {string | object | null} widget
|
|
350
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
351
|
+
*/
|
|
352
|
+
declare function page(page: string, widget: string | object | null): FieldDecorator<any> & ClassDecorator;
|
|
353
|
+
/**
|
|
354
|
+
*
|
|
355
|
+
* @overload
|
|
356
|
+
* @param {string | Record<string, string | object | boolean>} page
|
|
357
|
+
* @param {string | object | null} [widget]
|
|
358
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
359
|
+
*/
|
|
360
|
+
declare function page(page: string | Record<string, string | object | boolean>, widget?: string | object | null | undefined): FieldDecorator<any> & ClassDecorator;
|
|
329
361
|
/**
|
|
330
362
|
*
|
|
331
363
|
* @param {...Permission | Permission[]} permissions
|
|
@@ -437,6 +469,7 @@ declare function expandModel<TF extends Fields<TableDefine> = Fields<TableDefine
|
|
|
437
469
|
* @param {any} v
|
|
438
470
|
*/
|
|
439
471
|
declare function getModelOptions(v: any): {
|
|
472
|
+
readonly pages: Record<string, string | object | null> | null;
|
|
440
473
|
readonly label: string;
|
|
441
474
|
readonly iconField: string;
|
|
442
475
|
readonly imageField: string;
|
|
@@ -455,4 +488,4 @@ declare function getDefinePermission(v: any): _yongdall_types0.Permission[];
|
|
|
455
488
|
*/
|
|
456
489
|
declare function getLabelPattern(v: any): any;
|
|
457
490
|
//#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 };
|
|
491
|
+
export { FieldDefineExtends, ModelOptions, ModelTable, clearable, createField, createModel, database, description, disabled, expandModel, getDefinePermission, getLabelPattern, getModelOptions, group, iconField, imageField, label, labelField, labelPattern, layout, max, min, page, permission, placeholder, readonly, renderer, required, script, step };
|
package/index.mjs
CHANGED
|
@@ -204,6 +204,7 @@ function setExpandMetadata(model, options) {
|
|
|
204
204
|
* @property {string?} [labelPattern] 标签命名规则
|
|
205
205
|
* @property {Permission[]} [permissions] 权限配置
|
|
206
206
|
* @property {(string | [string, object])[] | null} [scripts] 关联前端脚本
|
|
207
|
+
* @property {Record<string, string | object | null> | null} [pages] 关联默认页面
|
|
207
208
|
*/
|
|
208
209
|
/**
|
|
209
210
|
* @template {Fields} [T=Fields]
|
|
@@ -237,7 +238,7 @@ function createModel(table, fields, { pseudo, indexes, hooks, databaseId, ...opt
|
|
|
237
238
|
/** @import { Field } from '@yongdall/types' */
|
|
238
239
|
/** @import { ModelOptions } from './createModel.mjs' */
|
|
239
240
|
/**
|
|
240
|
-
* @template {Exclude<keyof ModelOptions, "pseudo" | "indexes" | "hooks">} T
|
|
241
|
+
* @template {Exclude<keyof ModelOptions, "pseudo" | "indexes" | "hooks" | 'databaseId'>} T
|
|
241
242
|
* @param {T} key
|
|
242
243
|
* @param {ModelOptions[T]} value
|
|
243
244
|
* @returns {ClassDecorator}
|
|
@@ -264,6 +265,63 @@ function labelPattern(value) {
|
|
|
264
265
|
return modelOption("labelPattern", value);
|
|
265
266
|
}
|
|
266
267
|
/**
|
|
268
|
+
* @param {string?} value
|
|
269
|
+
* @returns {ClassDecorator}
|
|
270
|
+
*/
|
|
271
|
+
function database(value) {
|
|
272
|
+
return (Model, ctx) => {
|
|
273
|
+
if (ctx.kind !== "class") return;
|
|
274
|
+
ctx.addInitializer(function() {
|
|
275
|
+
Object.defineProperty(this, "databaseId", {
|
|
276
|
+
configurable: true,
|
|
277
|
+
enumerable: true,
|
|
278
|
+
value
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
*
|
|
285
|
+
* @overload
|
|
286
|
+
* @param {Record<string, string | object | boolean>} pages
|
|
287
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
*
|
|
291
|
+
* @overload
|
|
292
|
+
* @param {string} page
|
|
293
|
+
* @param {string | object | null} widget
|
|
294
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
295
|
+
*/
|
|
296
|
+
/**
|
|
297
|
+
*
|
|
298
|
+
* @overload
|
|
299
|
+
* @param {string | Record<string, string | object | boolean>} page
|
|
300
|
+
* @param {string | object | null} [widget]
|
|
301
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
302
|
+
*/
|
|
303
|
+
/**
|
|
304
|
+
*
|
|
305
|
+
* @param {string | Record<string, string | object | boolean>} page
|
|
306
|
+
* @param {string | object | null} [widget]
|
|
307
|
+
* @returns {FieldDecorator<any> & ClassDecorator}
|
|
308
|
+
*/
|
|
309
|
+
function page(page, widget) {
|
|
310
|
+
if (page && typeof page === "object")
|
|
311
|
+
/** @type {string | [string, object]} */
|
|
312
|
+
return (Model, ctx) => {
|
|
313
|
+
if (ctx.kind !== "class") return;
|
|
314
|
+
const pages = getMetadataExpand(ctx.metadata).pages ||= {};
|
|
315
|
+
Object.assign(pages, page);
|
|
316
|
+
};
|
|
317
|
+
/** @type {string | [string, object]} */
|
|
318
|
+
return (Model, ctx) => {
|
|
319
|
+
if (ctx.kind !== "class") return;
|
|
320
|
+
const pages = getMetadataExpand(ctx.metadata).pages ||= {};
|
|
321
|
+
pages[page] = widget ?? null;
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
267
325
|
*
|
|
268
326
|
* @param {...Permission | Permission[]} permissions
|
|
269
327
|
* @returns {ClassDecorator}
|
|
@@ -451,6 +509,9 @@ function expandModel(model, fields) {
|
|
|
451
509
|
function getModelOptions(v) {
|
|
452
510
|
const metadata = getExpandMetadata(v);
|
|
453
511
|
return {
|
|
512
|
+
get pages() {
|
|
513
|
+
return getExpandMetadata(v).pages || null;
|
|
514
|
+
},
|
|
454
515
|
get label() {
|
|
455
516
|
return getExpandMetadata(v).label || "";
|
|
456
517
|
},
|
|
@@ -491,5 +552,5 @@ function getLabelPattern(v) {
|
|
|
491
552
|
}
|
|
492
553
|
|
|
493
554
|
//#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 };
|
|
555
|
+
export { clearable, createField, createModel, database, description, disabled, expandModel, getDefinePermission, getLabelPattern, getModelOptions, group, iconField, imageField, label, labelField, labelPattern, layout, max, min, page, permission, placeholder, readonly, renderer, required, script, step };
|
|
495
556
|
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AgB,gBAAgB,GAAG;CAClC,MAAM,WAAW,kBAAkB,EAAE;AACrC,QAAO;EACN,IAAI,QAAQ;AACX,UAAO,kBAAkB,EAAE,CAAC,SAAS;;EAEtC,IAAI,YAAY;AACf,UAAO,kBAAkB,EAAE,CAAC,aAAa;;EAE1C,IAAI,aAAa;AAChB,UAAO,kBAAkB,EAAE,CAAC,cAAc;;EAE3C,IAAI,eAAe;GAClB,MAAM,eAAe,SAAS,gBAAgB,EAAE;AAChD,OAAI,aAAgB,QAAO;GAC3B,MAAM,aAAa,SAAS,cAAc,EAAE;AAC5C,OAAI,WACH,QAAO,IAAI,WAAW;AAEvB,UAAO;;EAER,IAAI,cAAc;AACjB,UAAO,kBAAkB,EAAE,CAAC,eAAe,EAAE;;EAE9C,IAAI,UAAU;AACb,UAAO,kBAAkB,EAAE,CAAC,WAAW,EAAE;;EAG1C;;;;;;AASF,SAAgB,oBAAoB,GAAG;AACtC,QAAO,gBAAgB,EAAE,CAAC;;;;;;AAO3B,SAAgB,gBAAgB,GAAG;AAClC,QAAO,gBAAgB,EAAE,CAAC"}
|
|
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 * @property {Record<string, string | object | null> | null} [pages] 关联默认页面\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\" | 'databaseId'>} 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 * @param {string?} value\n * @returns {ClassDecorator}\n */\nexport function database(value) {\n\treturn (Model, ctx) => {\n\t\tif (ctx.kind !== 'class') { return; }\n\t\tctx.addInitializer(function () {\n\t\t\tObject.defineProperty(this, 'databaseId', {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue,\n\t\t\t});\n\t\t});\n\t};\n}\n\n/**\n * \n * @overload\n * @param {Record<string, string | object | boolean>} pages \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\n/**\n * \n * @overload\n * @param {string} page \n * @param {string | object | null} widget \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\n/**\n * \n * @overload\n * @param {string | Record<string, string | object | boolean>} page \n * @param {string | object | null} [widget] \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\n/**\n * \n * @param {string | Record<string, string | object | boolean>} page \n * @param {string | object | null} [widget] \n * @returns {FieldDecorator<any> & ClassDecorator}\n */\nexport function page(page, widget) {\n\tif (page && typeof page === 'object') {\n\t\t/** @type {string | [string, object]} */\n\t\treturn (Model, ctx) => {\n\t\t\tif (ctx.kind !== 'class') { return; }\n\t\t\tconst pages = getMetadataExpand(ctx.metadata).pages ||= {};\n\t\t\tObject.assign(pages, page);\n\t\t};\n\t}\n\t/** @type {string | [string, object]} */\n\treturn (Model, ctx) => {\n\t\tif (ctx.kind !== 'class') { return; }\n\t\tconst pages = getMetadataExpand(ctx.metadata).pages ||= {};\n\t\tpages[page] = widget ?? null;\n\t};\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 pages() {\n\t\t\treturn getExpandMetadata(v).pages || null;\n\t\t},\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,OAAO,UAAU,cAAc,OAAO,UAAU,SAAY,QAAO;CAEvE,MAAM,WAAW,MAAM,OAAO,cAAc,EAAE;AAC9C,UAAS,SAAS;AAClB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACGR,SAAgB,YAAY,OAAO,QAAQ,EAAC,QAAQ,SAAS,OAAO,YAAY,GAAG,YAAW,EAAE,EAAE;AACjG,QAAO,kBAAkB;EACxB;EAAO;EAAQ;EAAQ;EAAS;EAAO;EACvC,EAAE,QAAQ;;;;;;;;;;;;;;;ACzBZ,SAAS,YAAY,KAAK,OAAO;AAChC,SAAQ,GAAG,MAAM;AAChB,MAAI,EAA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SAAS,cAAc,EAAE;AAC5C,OAAI,WACH,QAAO,IAAI,WAAW;AAEvB,UAAO;;EAER,IAAI,cAAc;AACjB,UAAO,kBAAkB,EAAE,CAAC,eAAe,EAAE;;EAE9C,IAAI,UAAU;AACb,UAAO,kBAAkB,EAAE,CAAC,WAAW,EAAE;;EAG1C;;;;;;AASF,SAAgB,oBAAoB,GAAG;AACtC,QAAO,gBAAgB,EAAE,CAAC;;;;;;AAO3B,SAAgB,gBAAgB,GAAG;AAClC,QAAO,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.mjs"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.1.
|
|
8
|
+
"version": "0.1.4",
|
|
9
9
|
"description": "",
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"imodel": "^0.
|
|
14
|
+
"imodel": "^0.16.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@yongdall/types": "^0.1.0"
|