@webda/core 2.4.1 → 3.0.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.
Files changed (227) hide show
  1. package/lib/application.d.ts +171 -34
  2. package/lib/application.js +243 -47
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +44 -8
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +113 -54
  7. package/lib/core.js +222 -135
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +87 -43
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/errors.d.ts +65 -0
  12. package/lib/errors.js +113 -0
  13. package/lib/errors.js.map +1 -0
  14. package/lib/errors.spec.d.ts +1 -0
  15. package/lib/errors.spec.js +33 -0
  16. package/lib/errors.spec.js.map +1 -0
  17. package/lib/index.d.ts +3 -0
  18. package/lib/index.js +3 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/models/aclmodel.d.ts +4 -4
  21. package/lib/models/aclmodel.js +10 -6
  22. package/lib/models/aclmodel.js.map +1 -1
  23. package/lib/models/aclmodel.spec.js +33 -24
  24. package/lib/models/aclmodel.spec.js.map +1 -1
  25. package/lib/models/coremodel.d.ts +284 -92
  26. package/lib/models/coremodel.js +403 -103
  27. package/lib/models/coremodel.js.map +1 -1
  28. package/lib/models/coremodel.spec.js +162 -24
  29. package/lib/models/coremodel.spec.js.map +1 -1
  30. package/lib/models/ident.d.ts +20 -6
  31. package/lib/models/ident.js.map +1 -1
  32. package/lib/models/ownermodel.d.ts +13 -23
  33. package/lib/models/ownermodel.js +24 -51
  34. package/lib/models/ownermodel.js.map +1 -1
  35. package/lib/models/ownermodel.spec.js +23 -11
  36. package/lib/models/ownermodel.spec.js.map +1 -1
  37. package/lib/models/relations.d.ts +167 -0
  38. package/lib/models/relations.js +113 -0
  39. package/lib/models/relations.js.map +1 -0
  40. package/lib/models/rolemodel.d.ts +3 -3
  41. package/lib/models/rolemodel.js +6 -6
  42. package/lib/models/rolemodel.js.map +1 -1
  43. package/lib/models/rolemodel.spec.js +12 -12
  44. package/lib/models/rolemodel.spec.js.map +1 -1
  45. package/lib/models/user.d.ts +40 -24
  46. package/lib/models/user.js +74 -48
  47. package/lib/models/user.js.map +1 -1
  48. package/lib/models/user.spec.js +24 -4
  49. package/lib/models/user.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.spec.js +9 -5
  51. package/lib/queues/memoryqueue.spec.js.map +1 -1
  52. package/lib/queues/queueservice.js.map +1 -1
  53. package/lib/router.d.ts +17 -8
  54. package/lib/router.js +81 -9
  55. package/lib/router.js.map +1 -1
  56. package/lib/router.spec.js +89 -5
  57. package/lib/router.spec.js.map +1 -1
  58. package/lib/services/asyncevents.spec.js +4 -4
  59. package/lib/services/authentication.d.ts +21 -22
  60. package/lib/services/authentication.js +90 -109
  61. package/lib/services/authentication.js.map +1 -1
  62. package/lib/services/authentication.spec.js +51 -65
  63. package/lib/services/authentication.spec.js.map +1 -1
  64. package/lib/services/binary.d.ts +132 -31
  65. package/lib/services/binary.js +257 -72
  66. package/lib/services/binary.js.map +1 -1
  67. package/lib/services/binary.spec.d.ts +16 -6
  68. package/lib/services/binary.spec.js +44 -117
  69. package/lib/services/binary.spec.js.map +1 -1
  70. package/lib/services/cloudbinary.d.ts +9 -10
  71. package/lib/services/cloudbinary.js +14 -15
  72. package/lib/services/cloudbinary.js.map +1 -1
  73. package/lib/services/cloudbinary.spec.d.ts +2 -2
  74. package/lib/services/cloudbinary.spec.js +13 -12
  75. package/lib/services/cloudbinary.spec.js.map +1 -1
  76. package/lib/services/configuration.js +9 -9
  77. package/lib/services/configuration.js.map +1 -1
  78. package/lib/services/configuration.spec.js +5 -7
  79. package/lib/services/configuration.spec.js.map +1 -1
  80. package/lib/services/cron.spec.js +3 -4
  81. package/lib/services/cron.spec.js.map +1 -1
  82. package/lib/services/cryptoservice.d.ts +2 -2
  83. package/lib/services/cryptoservice.js +5 -2
  84. package/lib/services/cryptoservice.js.map +1 -1
  85. package/lib/services/domainservice.d.ts +113 -0
  86. package/lib/services/domainservice.js +357 -0
  87. package/lib/services/domainservice.js.map +1 -0
  88. package/lib/services/domainservice.spec.d.ts +1 -0
  89. package/lib/services/domainservice.spec.js +334 -0
  90. package/lib/services/domainservice.spec.js.map +1 -0
  91. package/lib/services/echo.d.ts +2 -2
  92. package/lib/services/echo.js.map +1 -1
  93. package/lib/services/echo.spec.js +9 -2
  94. package/lib/services/echo.spec.js.map +1 -1
  95. package/lib/services/filebinary.d.ts +13 -14
  96. package/lib/services/filebinary.js +79 -73
  97. package/lib/services/filebinary.js.map +1 -1
  98. package/lib/services/filebinary.spec.d.ts +5 -0
  99. package/lib/services/filebinary.spec.js +222 -11
  100. package/lib/services/filebinary.spec.js.map +1 -1
  101. package/lib/services/fileconfiguration.js +7 -7
  102. package/lib/services/fileconfiguration.js.map +1 -1
  103. package/lib/services/fileconfiguration.spec.js +23 -24
  104. package/lib/services/fileconfiguration.spec.js.map +1 -1
  105. package/lib/services/invitationservice.d.ts +11 -9
  106. package/lib/services/invitationservice.js +17 -23
  107. package/lib/services/invitationservice.js.map +1 -1
  108. package/lib/services/invitationservice.spec.js +43 -40
  109. package/lib/services/invitationservice.spec.js.map +1 -1
  110. package/lib/services/kubernetesconfiguration.js +12 -22
  111. package/lib/services/kubernetesconfiguration.js.map +1 -1
  112. package/lib/services/kubernetesconfiguration.spec.js +1 -6
  113. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  114. package/lib/services/mailer.js +1 -1
  115. package/lib/services/mailer.js.map +1 -1
  116. package/lib/services/mailer.spec.js +4 -1
  117. package/lib/services/mailer.spec.js.map +1 -1
  118. package/lib/services/oauth.d.ts +17 -9
  119. package/lib/services/oauth.js +30 -4
  120. package/lib/services/oauth.js.map +1 -1
  121. package/lib/services/oauth.spec.js +32 -15
  122. package/lib/services/oauth.spec.js.map +1 -1
  123. package/lib/services/prometheus.spec.js.map +1 -1
  124. package/lib/services/proxy.d.ts +9 -8
  125. package/lib/services/proxy.js +65 -36
  126. package/lib/services/proxy.js.map +1 -1
  127. package/lib/services/proxy.spec.js +28 -2
  128. package/lib/services/proxy.spec.js.map +1 -1
  129. package/lib/services/resource.d.ts +3 -3
  130. package/lib/services/resource.js +4 -3
  131. package/lib/services/resource.js.map +1 -1
  132. package/lib/services/resource.spec.js +3 -3
  133. package/lib/services/resource.spec.js.map +1 -1
  134. package/lib/services/service.d.ts +10 -13
  135. package/lib/services/service.js +29 -13
  136. package/lib/services/service.js.map +1 -1
  137. package/lib/services/service.spec.js +49 -11
  138. package/lib/services/service.spec.js.map +1 -1
  139. package/lib/services/version.d.ts +2 -2
  140. package/lib/services/version.js.map +1 -1
  141. package/lib/stores/aggregator.js +1 -0
  142. package/lib/stores/aggregator.js.map +1 -1
  143. package/lib/stores/aliasstore.d.ts +2 -2
  144. package/lib/stores/aliasstore.js +15 -4
  145. package/lib/stores/aliasstore.js.map +1 -1
  146. package/lib/stores/aliasstore.spec.js +4 -2
  147. package/lib/stores/aliasstore.spec.js.map +1 -1
  148. package/lib/stores/file.d.ts +5 -2
  149. package/lib/stores/file.js +11 -8
  150. package/lib/stores/file.js.map +1 -1
  151. package/lib/stores/file.spec.js +21 -34
  152. package/lib/stores/file.spec.js.map +1 -1
  153. package/lib/stores/mapper.d.ts +4 -2
  154. package/lib/stores/mapper.js +18 -11
  155. package/lib/stores/mapper.js.map +1 -1
  156. package/lib/stores/mapper.spec.js +6 -3
  157. package/lib/stores/mapper.spec.js.map +1 -1
  158. package/lib/stores/memory.d.ts +5 -2
  159. package/lib/stores/memory.js +11 -9
  160. package/lib/stores/memory.js.map +1 -1
  161. package/lib/stores/memory.spec.d.ts +3 -0
  162. package/lib/stores/memory.spec.js +100 -11
  163. package/lib/stores/memory.spec.js.map +1 -1
  164. package/lib/stores/store.d.ts +177 -87
  165. package/lib/stores/store.js +312 -141
  166. package/lib/stores/store.js.map +1 -1
  167. package/lib/stores/store.spec.d.ts +2 -2
  168. package/lib/stores/store.spec.js +54 -38
  169. package/lib/stores/store.spec.js.map +1 -1
  170. package/lib/stores/webdaql/WebdaQLLexer.d.ts +14 -13
  171. package/lib/stores/webdaql/WebdaQLLexer.js +121 -112
  172. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  173. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +14 -13
  174. package/lib/stores/webdaql/WebdaQLParserLexer.js +121 -112
  175. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  176. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +15 -3
  177. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +23 -13
  178. package/lib/stores/webdaql/WebdaQLParserParser.js +149 -94
  179. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  180. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +9 -2
  181. package/lib/stores/webdaql/query.d.ts +6 -2
  182. package/lib/stores/webdaql/query.js +14 -1
  183. package/lib/stores/webdaql/query.js.map +1 -1
  184. package/lib/stores/webdaql/query.spec.js +10 -1
  185. package/lib/stores/webdaql/query.spec.js.map +1 -1
  186. package/lib/test.d.ts +48 -19
  187. package/lib/test.js +171 -63
  188. package/lib/test.js.map +1 -1
  189. package/lib/unpackedapplication.d.ts +5 -0
  190. package/lib/unpackedapplication.js +58 -10
  191. package/lib/unpackedapplication.js.map +1 -1
  192. package/lib/utils/context.d.ts +76 -29
  193. package/lib/utils/context.js +91 -55
  194. package/lib/utils/context.js.map +1 -1
  195. package/lib/utils/context.spec.d.ts +9 -1
  196. package/lib/utils/context.spec.js +73 -8
  197. package/lib/utils/context.spec.js.map +1 -1
  198. package/lib/utils/cookie.d.ts +4 -5
  199. package/lib/utils/cookie.js +1 -2
  200. package/lib/utils/cookie.js.map +1 -1
  201. package/lib/utils/cookie.spec.js +5 -3
  202. package/lib/utils/cookie.spec.js.map +1 -1
  203. package/lib/utils/httpcontext.spec.js +9 -3
  204. package/lib/utils/httpcontext.spec.js.map +1 -1
  205. package/lib/utils/serializers.d.ts +46 -17
  206. package/lib/utils/serializers.js +116 -2
  207. package/lib/utils/serializers.js.map +1 -1
  208. package/lib/utils/serializers.spec.js +84 -20
  209. package/lib/utils/serializers.spec.js.map +1 -1
  210. package/lib/utils/session.d.ts +14 -8
  211. package/lib/utils/session.js +14 -3
  212. package/lib/utils/session.js.map +1 -1
  213. package/lib/utils/session.spec.js +6 -1
  214. package/lib/utils/session.spec.js.map +1 -1
  215. package/package.json +16 -10
  216. package/test/cachedapp/webda.config.json +6 -1
  217. package/test/config-cached.json +5 -0
  218. package/test/config-file-missing-file.json +5 -7
  219. package/test/config-file-no-reload.json +5 -7
  220. package/test/config-file-reload.json +5 -7
  221. package/test/config-kube-reload.json +5 -11
  222. package/test/config-reload.json +2 -4
  223. package/test/config.json +12 -2
  224. package/test/moddas/voidstore.js +1 -1
  225. package/test/models/ident.js +6 -4
  226. package/test/models/task.js +4 -4
  227. package/webda.module.json +1587 -1266
@@ -1,13 +1,38 @@
1
1
  import { WorkerLogLevel, WorkerOutput } from "@webda/workout";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  import { OpenAPIV3 } from "openapi-types";
4
- import { Constructor, Context, Core, CoreModel, CoreModelDefinition, Service } from "./index.js";
4
+ import { Constructor, Core, CoreModel, CoreModelDefinition, Service } from "./index.js";
5
5
  export type PackageDescriptorAuthor = string | {
6
6
  name?: string;
7
7
  email?: string;
8
8
  url?: string;
9
9
  };
10
10
  export type Modda = ServiceConstructor<Service>;
11
+ /**
12
+ * Defined relationship for one model
13
+ */
14
+ export type ModelGraph = {
15
+ parent?: Omit<ModelRelation, "type">;
16
+ links?: ModelRelation[];
17
+ queries?: {
18
+ attribute: string;
19
+ model: string;
20
+ targetAttribute: string;
21
+ }[];
22
+ maps?: any[];
23
+ children?: string[];
24
+ binaries?: {
25
+ attribute: string;
26
+ cardinality: "ONE" | "MANY";
27
+ metadata?: string;
28
+ }[];
29
+ };
30
+ /**
31
+ * Defined relationship for all models
32
+ */
33
+ export type ModelsGraph = {
34
+ [key: string]: ModelGraph;
35
+ };
11
36
  /**
12
37
  * Some package exists but seems pretty big for this
13
38
  * https://classic.yarnpkg.com/en/docs/package-json
@@ -74,7 +99,13 @@ export interface PackageDescriptor {
74
99
  export type ModelRelation = {
75
100
  attribute: string;
76
101
  model: string;
77
- type: "";
102
+ type: "LINK" | "LINKS_MAP" | "LINKS_ARRAY" | "LINKS_SIMPLE_ARRAY";
103
+ };
104
+ /**
105
+ * Define the model hierarchy
106
+ */
107
+ export type ModelsTree = {
108
+ [key: string]: ModelsTree;
78
109
  };
79
110
  /**
80
111
  * A Webda module is a NPM package
@@ -91,22 +122,49 @@ export interface Module {
91
122
  /**
92
123
  * Models provided by the module
93
124
  */
94
- models?: {
95
- [key: string]: string;
96
- };
97
- /**
98
- * Models graph
99
- */
100
- modelsGraph?: {
101
- [key: string]: {
102
- parent?: Omit<ModelRelation, "type">;
103
- links?: ModelRelation[];
104
- queries?: {
105
- attribute: string;
106
- model: string;
107
- targetAttribute: string;
125
+ models: {
126
+ /**
127
+ * Models provided by the module
128
+ */
129
+ list: {
130
+ [key: string]: string;
131
+ };
132
+ /**
133
+ * Models hierarchy tree
134
+ *
135
+ * Models Graph establish the relationship between models
136
+ * Models Tree establish the hierarchy between models classes
137
+ */
138
+ tree: ModelsTree;
139
+ /**
140
+ * Models graph
141
+ *
142
+ * Typescript does not have reflection, we therefore deduct the
143
+ * relations on compilation time and inject in the module
144
+ *
145
+ * The parent is define by a ModelParent type on the model
146
+ * The links are attribute of types ModelLink
147
+ */
148
+ graph: ModelsGraph;
149
+ /**
150
+ * Specific plurals for a model
151
+ */
152
+ plurals: {
153
+ [key: string]: string;
154
+ };
155
+ /**
156
+ * Contains the shortcut id for the models
157
+ */
158
+ shortIds: {
159
+ [key: string]: string;
160
+ };
161
+ /**
162
+ * Store the model attributes types
163
+ */
164
+ reflections: {
165
+ [key: string]: {
166
+ [key: string]: string;
108
167
  };
109
- maps?: any[];
110
168
  };
111
169
  };
112
170
  /**
@@ -187,12 +245,6 @@ export type UnpackedConfiguration = {
187
245
  * Define the api url
188
246
  */
189
247
  apiUrl?: string;
190
- /**
191
- * Define the model to use for Context
192
- *
193
- * @default Context
194
- */
195
- contextModel?: string;
196
248
  /**
197
249
  * Will not try to parse request bigger than this
198
250
  *
@@ -310,7 +362,6 @@ export interface ServiceConstructor<T extends Service> {
310
362
  export declare enum SectionEnum {
311
363
  Moddas = "moddas",
312
364
  Deployers = "deployers",
313
- Models = "models",
314
365
  Beans = "beans"
315
366
  }
316
367
  /**
@@ -429,7 +480,17 @@ export declare class Application {
429
480
  * Models type registry
430
481
  */
431
482
  protected models: {
432
- [key: string]: any;
483
+ [key: string]: CoreModelDefinition;
484
+ };
485
+ /**
486
+ * Models graph
487
+ */
488
+ protected graph: ModelsGraph;
489
+ /**
490
+ * Models specific plurals
491
+ */
492
+ protected plurals: {
493
+ [key: string]: string;
433
494
  };
434
495
  /**
435
496
  * Class Logger
@@ -443,6 +504,12 @@ export declare class Application {
443
504
  * When the application got initiated
444
505
  */
445
506
  protected initTime: number;
507
+ /**
508
+ * Direct parent of a model
509
+ */
510
+ protected flatHierarchy: {
511
+ [key: string]: string;
512
+ };
446
513
  /**
447
514
  * Configuration file
448
515
  */
@@ -485,6 +552,21 @@ export declare class Application {
485
552
  * @returns
486
553
  */
487
554
  getSchema(type: string): JSONSchema7;
555
+ /**
556
+ * Check if a schema exists
557
+ * @param type
558
+ * @returns schema name if it exists
559
+ */
560
+ hasSchema(type: string): boolean;
561
+ /**
562
+ * Get model graph
563
+ */
564
+ getRelations(model: string | Constructor<CoreModel> | CoreModel): ModelGraph;
565
+ /**
566
+ * Get the all graph
567
+ * @returns
568
+ */
569
+ getGraph(): ModelsGraph;
488
570
  /**
489
571
  * Check if application has cached modules
490
572
  *
@@ -527,13 +609,32 @@ export declare class Application {
527
609
  * @param service
528
610
  */
529
611
  addService(name: string, service: Modda): this;
612
+ /**
613
+ * Register a new schema in the application
614
+ * @param name
615
+ * @param schema
616
+ */
617
+ registerSchema(name: string, schema: JSONSchema7): void;
618
+ /**
619
+ * Get plural of an Id
620
+ * @param name
621
+ * @returns
622
+ */
623
+ getModelPlural(name: string): string;
624
+ /**
625
+ *
626
+ * @param section
627
+ * @param name
628
+ * @param caseSensitive
629
+ */
630
+ hasWebdaObject(section: Section, name: string, caseSensitive?: boolean): boolean;
530
631
  /**
531
632
  *
532
633
  * @param section
533
634
  * @param name
534
635
  * @returns
535
636
  */
536
- getWebdaObject(section: Section, name: string): any;
637
+ getWebdaObject(section: Section, name: string, caseSensitive?: boolean): any;
537
638
  /**
538
639
  * Get a service based on name
539
640
  *
@@ -557,13 +658,24 @@ export declare class Application {
557
658
  *
558
659
  * @param name model to retrieve
559
660
  */
560
- getModel<T extends CoreModelDefinition | Constructor<any> = CoreModelDefinition>(name: string): T;
661
+ getModel<T extends CoreModel = CoreModel>(name: string): CoreModelDefinition<T>;
561
662
  /**
562
663
  * Get all models definitions
563
664
  */
564
665
  getModels(): {
565
- [key: string]: Constructor<Context> | CoreModelDefinition;
666
+ [key: string]: CoreModelDefinition;
566
667
  };
668
+ /**
669
+ * Return models that do not have parents
670
+ * @returns
671
+ */
672
+ getRootModels(): string[];
673
+ /**
674
+ * Return models that do not have parents and are exposed
675
+ * Or specifically set as root via the Expose.root parameter
676
+ * @returns
677
+ */
678
+ getRootExposedModels(): string[];
567
679
  /**
568
680
  * Return the model name for a object
569
681
  * @param object
@@ -574,6 +686,27 @@ export declare class Application {
574
686
  * @param object
575
687
  */
576
688
  getModelFromConstructor(model: Constructor<CoreModel>): string | undefined;
689
+ /**
690
+ * Get the model name from a model or a constructor
691
+ *
692
+ * @param model
693
+ * @returns longId for a model
694
+ */
695
+ getModelName(model: CoreModel | Constructor<CoreModel>): string | undefined;
696
+ /**
697
+ * Get the model hierarchy
698
+ * @param model
699
+ */
700
+ getModelHierarchy(model: CoreModel | Constructor<CoreModel> | string): {
701
+ ancestors: string[];
702
+ children: ModelsTree;
703
+ };
704
+ /**
705
+ * Get all model types with the hierarchy
706
+ * @param model
707
+ * @returns
708
+ */
709
+ getModelTypes(model: CoreModel): string[];
577
710
  /**
578
711
  * Return all deployers
579
712
  */
@@ -586,7 +719,7 @@ export declare class Application {
586
719
  * @param name
587
720
  * @param model
588
721
  */
589
- addModel(name: string, model: any): this;
722
+ addModel(name: string, model: any, dynamic?: boolean): this;
590
723
  /**
591
724
  * Add a new deployer
592
725
  *
@@ -708,10 +841,14 @@ export declare class Application {
708
841
  */
709
842
  completeNamespace(name?: string): string;
710
843
  /**
711
- * Check if object extends a class
712
- *
713
- * @param obj
714
- * @param className
844
+ * Return current namespace
845
+ * @returns
846
+ */
847
+ getNamespace(): string;
848
+ /**
849
+ * Get short id for a name
850
+ * @param name if name is shortId return longId else return shortId
851
+ * @returns
715
852
  */
716
- extends(obj: any, className: any): boolean;
853
+ getShortId(name: string): string;
717
854
  }