@cocojs/mvc 0.1.0-beta.14 → 0.1.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -21,8 +21,8 @@ export declare class Application {
21
21
  iocComponentFactory: IocComponentFactory;
22
22
  constructor(jsonConfig?: Record<string, any>);
23
23
  /**
24
- * 在项目中,所以的组件都已经收集到coco/index里面了,所以不需要进行组件收集;
25
- * 在测试时,组件是在执行到对应的行装饰器才会执行,所以需要先收集在启动。
24
+ * 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
25
+ * 因此 start 时统一解析注册表。
26
26
  */
27
27
  start(): void;
28
28
  destructor(): void;
@@ -67,8 +67,8 @@ declare class Application_2 {
67
67
  iocComponentFactory: IocComponentFactory_2;
68
68
  constructor(jsonConfig?: Record<string, any>);
69
69
  /**
70
- * 在项目中,所以的组件都已经收集到coco/index里面了,所以不需要进行组件收集;
71
- * 在测试时,组件是在执行到对应的行装饰器才会执行,所以需要先收集在启动。
70
+ * 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
71
+ * 因此 start 时统一解析注册表。
72
72
  */
73
73
  start(): void;
74
74
  destructor(): void;
@@ -113,8 +113,8 @@ declare class Application_3 {
113
113
  iocComponentFactory: IocComponentFactory_3;
114
114
  constructor(jsonConfig?: Record<string, any>);
115
115
  /**
116
- * 在项目中,所以的组件都已经收集到coco/index里面了,所以不需要进行组件收集;
117
- * 在测试时,组件是在执行到对应的行装饰器才会执行,所以需要先收集在启动。
116
+ * 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
117
+ * 因此 start 时统一解析注册表。
118
118
  */
119
119
  start(): void;
120
120
  destructor(): void;
@@ -163,6 +163,13 @@ export declare class Bind extends Metadata_3 {
163
163
 
164
164
  export declare const bind: () => Decorator_2<ClassMethodDecoratorContext>;
165
165
 
166
+ /**
167
+ * 建立占位元数据类与真实元数据类的关联。
168
+ * 由 `@metadataFor(X)` 经 AOT 编译后调用。
169
+ * @public
170
+ */
171
+ export declare function bindPlaceholderMetadataClass(decoratorExp: PlaceholderDecoratorExp<any>, metadataClass: Class<any>): void;
172
+
166
173
  declare interface BizMetadata {
167
174
  classMetadata: Metadata[];
168
175
  fieldMetadata: Map<Field, Metadata[]>;
@@ -337,12 +344,16 @@ export declare class Cookie extends Metadata_3 {
337
344
  export declare const cookie: () => Decorator_2<ClassDecoratorContext>;
338
345
 
339
346
  /**
340
- * 使用元数据类创建一个装饰器函数
341
- * 适用于装饰器不装饰自己元数据类的场景
347
+ * 使用元数据类创建一个装饰器函数。
348
+ * 第一个参数传元数据类时直接绑定该元数据类;
349
+ * 不传元数据类时创建占位装饰器,可以直接把选项对象作为唯一参数传入,
350
+ * 之后需要在正式的元数据类上添加 @metadataFor(X) 装饰器来关联真实的元数据类。
342
351
  * @public
343
352
  */
344
353
  export declare function createDecoratorExp(metadataCls: Class<any>, option?: CreateDecoratorExpOption): DecoratorExp;
345
354
 
355
+ export declare function createDecoratorExp<T>(option?: CreateDecoratorExpOption): PlaceholderDecoratorExp<T>;
356
+
346
357
  declare interface CreateDecoratorExpOption {
347
358
  /**
348
359
  * 类实例化之后,会调用类的装饰器的componentPostConstruct做自定义的处理
@@ -354,14 +365,6 @@ declare interface CreateDecoratorExpOption {
354
365
  componentPostConstruct?: ComponentPostConstruct;
355
366
  }
356
367
 
357
- /**
358
- * 创建一个未绑定元数据的装饰器表达式
359
- * 需要在正式的元数据类上添加decorateSelf装饰器来关联真实的元数据类,装饰器到其他类的使用方式和createDecoratorExp是一致的。
360
- * 适用于装饰器装饰自己元数据类的场景
361
- * @public
362
- */
363
- export declare function createPlaceholderDecoratorExp<T>(option?: CreateDecoratorExpOption): DecoratorExpWithDecoratorSelf<T>;
364
-
365
368
  /**
366
369
  * @public
367
370
  */
@@ -379,11 +382,10 @@ declare type Decorator_3<C> = (value: any, context: C) => any;
379
382
 
380
383
  declare interface DecoratorExp {
381
384
  (userParam?: any): Decorator<DecoratorContext>;
382
- }
383
-
384
- declare interface DecoratorExpWithDecoratorSelf<T extends any> {
385
- (userParam?: T): Decorator<DecoratorContext>;
386
- decorateSelf: (userParam?: T) => Decorator<DecoratorContext>;
385
+ /** 装饰器对应的元数据类,AOT 编译产物通过 `<装饰器标识符>.$$metadataClass` 引用 */
386
+ $$metadataClass: Class<any>;
387
+ /** 是否是占位装饰器 */
388
+ $$isPlaceholderDecoratorExp: boolean;
387
389
  }
388
390
 
389
391
  export declare function definePublisher(object: Record<any, any>, field: string, getter: IGetter, setter?: ISetter): void;
@@ -423,8 +425,8 @@ declare enum DiagnoseCode {
423
425
  'CO10017' = 'CO10017', // 元数据类id属性存在重复
424
426
  'CO10018' = 'CO10018', // createDecoratorExp的第一个参数不是类,或者不是Metadata的子类
425
427
  'CO10019' = 'CO10019', // 装饰器暂时不是支持装饰 setter getter accessor 类型。
426
- 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用decorateSelf函数,但装饰器也没有被使用
427
- 'CO10021' = 'CO10021', // 占位的元数据类没有使用decorateSelf函数
428
+ 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用metadataFor关联,但装饰器也没有被使用
429
+ 'CO10021' = 'CO10021', // 占位的元数据类没有使用metadataFor关联真实元数据类
428
430
  'CO10022' = 'CO10022', // 元数据类不能有字段装饰器
429
431
  'CO10023' = 'CO10023', // 元数据类不能有方法装饰器
430
432
  'CO10024' = 'CO10024', // 元数据类存在多个组件装饰器
@@ -455,8 +457,8 @@ declare enum DiagnoseCode_2 {
455
457
  'CO10017' = 'CO10017', // 元数据类id属性存在重复
456
458
  'CO10018' = 'CO10018', // createDecoratorExp的第一个参数不是类,或者不是Metadata的子类
457
459
  'CO10019' = 'CO10019', // 装饰器暂时不是支持装饰 setter getter accessor 类型。
458
- 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用decorateSelf函数,但装饰器也没有被使用
459
- 'CO10021' = 'CO10021', // 占位的元数据类没有使用decorateSelf函数
460
+ 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用metadataFor关联,但装饰器也没有被使用
461
+ 'CO10021' = 'CO10021', // 占位的元数据类没有使用metadataFor关联真实元数据类
460
462
  'CO10022' = 'CO10022', // 元数据类不能有字段装饰器
461
463
  'CO10023' = 'CO10023', // 元数据类不能有方法装饰器
462
464
  'CO10024' = 'CO10024', // 元数据类存在多个组件装饰器
@@ -487,8 +489,8 @@ declare enum DiagnoseCode_3 {
487
489
  'CO10017' = 'CO10017', // 元数据类id属性存在重复
488
490
  'CO10018' = 'CO10018', // createDecoratorExp的第一个参数不是类,或者不是Metadata的子类
489
491
  'CO10019' = 'CO10019', // 装饰器暂时不是支持装饰 setter getter accessor 类型。
490
- 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用decorateSelf函数,但装饰器也没有被使用
491
- 'CO10021' = 'CO10021', // 占位的元数据类没有使用decorateSelf函数
492
+ 'CO10020' = 'CO10020', // [warn]占位的元数据类没有使用metadataFor关联,但装饰器也没有被使用
493
+ 'CO10021' = 'CO10021', // 占位的元数据类没有使用metadataFor关联真实元数据类
492
494
  'CO10022' = 'CO10022', // 元数据类不能有字段装饰器
493
495
  'CO10023' = 'CO10023', // 元数据类不能有方法装饰器
494
496
  'CO10024' = 'CO10024', // 元数据类存在多个组件装饰器
@@ -521,13 +523,8 @@ declare type Field_2 = string;
521
523
  */
522
524
  declare type Field_3 = string;
523
525
 
524
- /**
525
- * @public
526
- */
527
- export declare class Flow extends Metadata {
528
- }
529
-
530
- export declare const flow: () => Decorator<ClassDecoratorContext>;
526
+ /** 读取userDecoratorParams */
527
+ export declare function getRegistry(): Map<Class<any>, UserDecoratorParams[]>;
531
528
 
532
529
  /**
533
530
  * @public
@@ -679,12 +676,13 @@ declare class IocComponentDefinition {
679
676
  method: string;
680
677
  }): void;
681
678
  /**
682
- * 获取真正会实例化的类定义
679
+ * 解析组件实际需要实例化的类。
680
+ * 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
683
681
  * @param ClsOrId 想要实例化的类或类id
684
682
  * @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
685
683
  * @returns 真正会实例化的类定义
686
684
  */
687
- getInstantiateDefinition(ClsOrId: Class<any> | Id_2, qualifier?: string): IocComDef<any>;
685
+ resolve(ClsOrId: Class<any> | Id_2, qualifier?: string): IocComDef<any>;
688
686
  getDefinition(ClsOrId: Class<any> | Id_2): IocComDef<any>;
689
687
  existDefinition(ClsOrId: Class<any> | Id_2): boolean;
690
688
  destructor(): void;
@@ -699,12 +697,13 @@ declare class IocComponentDefinition_2 {
699
697
  method: string;
700
698
  }): void;
701
699
  /**
702
- * 获取真正会实例化的类定义
700
+ * 解析组件实际需要实例化的类。
701
+ * 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
703
702
  * @param ClsOrId 想要实例化的类或类id
704
703
  * @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
705
704
  * @returns 真正会实例化的类定义
706
705
  */
707
- getInstantiateDefinition(ClsOrId: Class<any> | Id_2_2, qualifier?: string): IocComDef_2<any>;
706
+ resolve(ClsOrId: Class<any> | Id_2_2, qualifier?: string): IocComDef_2<any>;
708
707
  getDefinition(ClsOrId: Class<any> | Id_2_2): IocComDef_2<any>;
709
708
  existDefinition(ClsOrId: Class<any> | Id_2_2): boolean;
710
709
  destructor(): void;
@@ -719,12 +718,13 @@ declare class IocComponentDefinition_3 {
719
718
  method: string;
720
719
  }): void;
721
720
  /**
722
- * 获取真正会实例化的类定义
721
+ * 解析组件实际需要实例化的类。
722
+ * 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
723
723
  * @param ClsOrId 想要实例化的类或类id
724
724
  * @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
725
725
  * @returns 真正会实例化的类定义
726
726
  */
727
- getInstantiateDefinition(ClsOrId: Class<any> | Id_2_3, qualifier?: string): IocComDef_3<any>;
727
+ resolve(ClsOrId: Class<any> | Id_2_3, qualifier?: string): IocComDef_3<any>;
728
728
  getDefinition(ClsOrId: Class<any> | Id_2_3): IocComDef_3<any>;
729
729
  existDefinition(ClsOrId: Class<any> | Id_2_3): boolean;
730
730
  destructor(): void;
@@ -732,7 +732,7 @@ declare class IocComponentDefinition_3 {
732
732
 
733
733
  declare class IocComponentFactory {
734
734
  singletonInstances: Map<Class<any>, any>;
735
- private createComponent;
735
+ private newComponent;
736
736
  getComponents(application: Application, userOption: ConstructOption): any;
737
737
  getViewComponent(application: Application, viewClass: Class<any>, props: any[]): any;
738
738
  destructor(): void;
@@ -740,7 +740,7 @@ declare class IocComponentFactory {
740
740
 
741
741
  declare class IocComponentFactory_2 {
742
742
  singletonInstances: Map<Class<any>, any>;
743
- private createComponent;
743
+ private newComponent;
744
744
  getComponents(application: Application_2, userOption: ConstructOption_2): any;
745
745
  getViewComponent(application: Application_2, viewClass: Class<any>, props: any[]): any;
746
746
  destructor(): void;
@@ -748,7 +748,7 @@ declare class IocComponentFactory_2 {
748
748
 
749
749
  declare class IocComponentFactory_3 {
750
750
  singletonInstances: Map<Class<any>, any>;
751
- private createComponent;
751
+ private newComponent;
752
752
  getComponents(application: Application_3, userOption: ConstructOption_3): any;
753
753
  getViewComponent(application: Application_3, viewClass: Class<any>, props: any[]): any;
754
754
  destructor(): void;
@@ -858,10 +858,17 @@ declare abstract class Metadata_3 {
858
858
  declare abstract class Metadata_4 {
859
859
  }
860
860
 
861
+ /**
862
+ * 声明被装饰类是某个装饰器表达式的元数据类。
863
+ * 由 AOT 编译器转换为 bindPlaceholderMetadataClass 调用,不应在运行时执行。
864
+ * @public
865
+ */
866
+ export declare function metadataFor(_decoratorExp: DecoratorExp): (_beDecoratedCls: any, _context: any) => never;
867
+
861
868
  declare class MetadataRepository {
862
869
  private metaMetadataMap;
863
870
  private bizMetadataMap;
864
- constructor(decoratorMap: Map<Class<any>, Params[]>);
871
+ constructor(decoratorMap: Map<Class<any>, RuntimeDecoratorParams[]>);
865
872
  getAll(): [Map<Class<Metadata>, MetaMetadata>, Map<Class<Metadata>, BizMetadata>];
866
873
  destructor(): void;
867
874
  getMetadataByClass(Cls: Class<any>): {
@@ -920,7 +927,7 @@ declare class MetadataRepository {
920
927
  declare class MetadataRepository_2 {
921
928
  private metaMetadataMap;
922
929
  private bizMetadataMap;
923
- constructor(decoratorMap: Map<Class<any>, Params_2[]>);
930
+ constructor(decoratorMap: Map<Class<any>, RuntimeDecoratorParams_2[]>);
924
931
  getAll(): [Map<Class<Metadata_2>, MetaMetadata_2>, Map<Class<Metadata_2>, BizMetadata_2>];
925
932
  destructor(): void;
926
933
  getMetadataByClass(Cls: Class<any>): {
@@ -979,7 +986,7 @@ declare class MetadataRepository_2 {
979
986
  declare class MetadataRepository_3 {
980
987
  private metaMetadataMap;
981
988
  private bizMetadataMap;
982
- constructor(decoratorMap: Map<Class<any>, Params_3[]>);
989
+ constructor(decoratorMap: Map<Class<any>, RuntimeDecoratorParams_3[]>);
983
990
  getAll(): [Map<Class<Metadata_4>, MetaMetadata_3>, Map<Class<Metadata_4>, BizMetadata_3>];
984
991
  destructor(): void;
985
992
  getMetadataByClass(Cls: Class<any>): {
@@ -1064,41 +1071,15 @@ export declare class Page extends Metadata_3 {
1064
1071
 
1065
1072
  export declare const page: () => Decorator_2<ClassDecoratorContext>;
1066
1073
 
1067
- declare type Params = {
1068
- metadataKind: Kind;
1069
- metadataClass: Class<any>;
1070
- metadataParam: any;
1071
- /**
1072
- * 如果metadataKind是'class',field是undefined
1073
- * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1074
- * TODO: 测试是否支持Symbol类型
1075
- */
1076
- field?: Field;
1077
- };
1078
-
1079
- declare type Params_2 = {
1080
- metadataKind: Kind_2;
1081
- metadataClass: Class<any>;
1082
- metadataParam: any;
1083
- /**
1084
- * 如果metadataKind是'class',field是undefined
1085
- * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1086
- * TODO: 测试是否支持Symbol类型
1087
- */
1088
- field?: Field_2;
1089
- };
1090
-
1091
- declare type Params_3 = {
1092
- metadataKind: Kind_3;
1093
- metadataClass: Class<any>;
1094
- metadataParam: any;
1095
- /**
1096
- * 如果metadataKind是'class',field是undefined
1097
- * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1098
- * TODO: 测试是否支持Symbol类型
1099
- */
1100
- field?: Field_3;
1101
- };
1074
+ export declare interface PlaceholderDecoratorExp<T extends any> {
1075
+ (userParam?: T): Decorator<DecoratorContext>;
1076
+ /** 占位元数据类,initDecoratorParamModule 据此查找真实元数据类 */
1077
+ $$metadataClass: Class<any>;
1078
+ /** 是否是占位装饰器 */
1079
+ $$isPlaceholderDecoratorExp: boolean;
1080
+ /** 占位元数据类引用,供 bindPlaceholderMetadataClass 建立映射 */
1081
+ $$placeholderMetadataClass: Class<any>;
1082
+ }
1102
1083
 
1103
1084
  /**
1104
1085
  * 动态配置操作类
@@ -1177,6 +1158,15 @@ export declare class Refs extends Metadata_3 {
1177
1158
 
1178
1159
  export declare const refs: () => Decorator_2<ClassFieldDecoratorContext>;
1179
1160
 
1161
+ /**
1162
+ * 全局静态注册函数。编译期由 coco-compiler 注入到每个源文件末尾。
1163
+ * 源码中类、字段、方法、getter 上的装饰器经 AOT 编译后统一转换为对它的调用,
1164
+ * 用于保存原始装饰器参数。
1165
+ * `@metadataFor(X)` 不产生注册参数,只额外生成 bindPlaceholderMetadataClass 调用。
1166
+ * @public
1167
+ */
1168
+ export declare function registerComponent(cls: Class<any>, params: UserDecoratorParams[]): void;
1169
+
1180
1170
  /**
1181
1171
  * @public
1182
1172
  */
@@ -1230,6 +1220,51 @@ export declare abstract class Router {
1230
1220
  export declare class RouterMeta extends Metadata_4 {
1231
1221
  }
1232
1222
 
1223
+ /**
1224
+ * AOT 注册参数解析完成后的运行时装饰器参数。
1225
+ */
1226
+ declare type RuntimeDecoratorParams = {
1227
+ metadataKind: Kind;
1228
+ metadataClass: Class<any>;
1229
+ metadataParam: any;
1230
+ /**
1231
+ * 如果metadataKind是'class',field是undefined
1232
+ * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1233
+ * TODO: 测试是否支持Symbol类型
1234
+ */
1235
+ field?: Field;
1236
+ };
1237
+
1238
+ /**
1239
+ * AOT 注册参数解析完成后的运行时装饰器参数。
1240
+ */
1241
+ declare type RuntimeDecoratorParams_2 = {
1242
+ metadataKind: Kind_2;
1243
+ metadataClass: Class<any>;
1244
+ metadataParam: any;
1245
+ /**
1246
+ * 如果metadataKind是'class',field是undefined
1247
+ * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1248
+ * TODO: 测试是否支持Symbol类型
1249
+ */
1250
+ field?: Field_2;
1251
+ };
1252
+
1253
+ /**
1254
+ * AOT 注册参数解析完成后的运行时装饰器参数。
1255
+ */
1256
+ declare type RuntimeDecoratorParams_3 = {
1257
+ metadataKind: Kind_3;
1258
+ metadataClass: Class<any>;
1259
+ metadataParam: any;
1260
+ /**
1261
+ * 如果metadataKind是'class',field是undefined
1262
+ * 如果metadataKind是'method'\'field',field就是对应的函数名或字段名
1263
+ * TODO: 测试是否支持Symbol类型
1264
+ */
1265
+ field?: Field_3;
1266
+ };
1267
+
1233
1268
  /**
1234
1269
  * @public
1235
1270
  */
@@ -1247,6 +1282,14 @@ export declare class Scope extends Metadata {
1247
1282
 
1248
1283
  export declare const scope: (scope?: SCOPE) => Decorator<ClassDecoratorContext | ClassMethodDecoratorContext>;
1249
1284
 
1285
+ /**
1286
+ * @public
1287
+ */
1288
+ export declare class Service extends Metadata {
1289
+ }
1290
+
1291
+ export declare const service: () => Decorator<ClassDecoratorContext>;
1292
+
1250
1293
  export declare class SessionStorage {
1251
1294
  setItem(key: string, value: string): void;
1252
1295
  getItem(key: string): string;
@@ -1282,7 +1325,7 @@ export declare class Target extends Metadata {
1282
1325
  /**
1283
1326
  * @public
1284
1327
  */
1285
- export declare const target: DecoratorExpWithDecoratorSelf<Type[]>;
1328
+ export declare const target: PlaceholderDecoratorExp<Type[]>;
1286
1329
 
1287
1330
  /**
1288
1331
  * @public
@@ -1294,6 +1337,21 @@ export declare enum Type {
1294
1337
  Getter = "getter"
1295
1338
  }
1296
1339
 
1340
+ /**
1341
+ * AOT 注册阶段的原始装饰器参数(userDecoratorParams)。
1342
+ * 与 RuntimeDecoratorParams 的区别:placeholder 装饰器的 metadataClass 可能是占位元数据类,
1343
+ * 需要 initDecoratorParamModule 替换后才能作为运行时参数(runtimeDecoratorParams)使用。
1344
+ */
1345
+ export declare type UserDecoratorParams = {
1346
+ metadataKind: Kind;
1347
+ /** 普通装饰器为真实元数据类;placeholder 装饰器始终为占位元数据类 */
1348
+ metadataClass: Class<any>;
1349
+ metadataParam: any;
1350
+ field?: Field;
1351
+ /** 是否是占位装饰器,即 createDecoratorExp 未传元数据类时创建的装饰器 */
1352
+ isPlaceholderDecoratorExp: boolean;
1353
+ };
1354
+
1297
1355
  /**
1298
1356
  * @public
1299
1357
  */
@@ -1315,7 +1373,6 @@ export declare const value: (path: string) => Decorator<ClassFieldDecoratorConte
1315
1373
  * @public
1316
1374
  */
1317
1375
  export declare class View extends Metadata_3 {
1318
- static classDecoratorModifyPrototype(prototype: any): void;
1319
1376
  }
1320
1377
 
1321
1378
  export declare const view: () => Decorator_2<ClassDecoratorContext>;