@declaro/core 2.0.0-y.0 → 2.1.1

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 (266) hide show
  1. package/{LICENSE → LICENSE.md} +1 -1
  2. package/README.md +203 -0
  3. package/dist/browser/index.js +28 -0
  4. package/dist/browser/index.js.map +133 -0
  5. package/dist/browser/scope/index.js +3 -0
  6. package/dist/browser/scope/index.js.map +9 -0
  7. package/dist/bun/index.js +19011 -0
  8. package/dist/bun/index.js.map +132 -0
  9. package/dist/bun/scope/index.js +4 -0
  10. package/dist/bun/scope/index.js.map +9 -0
  11. package/dist/node/index.cjs +19039 -0
  12. package/dist/node/index.cjs.map +132 -0
  13. package/dist/node/index.js +19010 -0
  14. package/dist/node/index.js.map +132 -0
  15. package/dist/node/scope/index.cjs +69 -0
  16. package/dist/node/scope/index.cjs.map +9 -0
  17. package/dist/node/scope/index.js +3 -0
  18. package/dist/node/scope/index.js.map +9 -0
  19. package/dist/ts/app/app-context.d.ts +9 -0
  20. package/dist/ts/app/app-context.d.ts.map +1 -0
  21. package/dist/ts/app/app-lifecycle.d.ts +6 -0
  22. package/dist/ts/app/app-lifecycle.d.ts.map +1 -0
  23. package/dist/ts/app/app.d.ts +24 -0
  24. package/dist/ts/app/app.d.ts.map +1 -0
  25. package/dist/{app → ts/app}/index.d.ts +1 -0
  26. package/dist/ts/app/index.d.ts.map +1 -0
  27. package/dist/ts/application/create-request-context.d.ts +4 -0
  28. package/dist/ts/application/create-request-context.d.ts.map +1 -0
  29. package/dist/ts/application/create-request-context.test.d.ts +2 -0
  30. package/dist/ts/application/create-request-context.test.d.ts.map +1 -0
  31. package/dist/ts/application/use-declaro.d.ts +3 -0
  32. package/dist/ts/application/use-declaro.d.ts.map +1 -0
  33. package/dist/{auth → ts/auth}/permission-validator.d.ts +1 -0
  34. package/dist/ts/auth/permission-validator.d.ts.map +1 -0
  35. package/dist/ts/auth/permission-validator.test.d.ts +2 -0
  36. package/dist/ts/auth/permission-validator.test.d.ts.map +1 -0
  37. package/dist/ts/context/async-context.d.ts +54 -0
  38. package/dist/ts/context/async-context.d.ts.map +1 -0
  39. package/dist/ts/context/async-context.test.d.ts +2 -0
  40. package/dist/ts/context/async-context.test.d.ts.map +1 -0
  41. package/dist/{context → ts/context}/context-consumer.d.ts +4 -0
  42. package/dist/ts/context/context-consumer.d.ts.map +1 -0
  43. package/dist/ts/context/context.circular-deps.test.d.ts +2 -0
  44. package/dist/ts/context/context.circular-deps.test.d.ts.map +1 -0
  45. package/dist/ts/context/context.d.ts +452 -0
  46. package/dist/ts/context/context.d.ts.map +1 -0
  47. package/dist/ts/context/context.test.d.ts +2 -0
  48. package/dist/ts/context/context.test.d.ts.map +1 -0
  49. package/dist/ts/context/legacy-context.test.d.ts +2 -0
  50. package/dist/ts/context/legacy-context.test.d.ts.map +1 -0
  51. package/dist/{context → ts/context}/validators.d.ts +2 -1
  52. package/dist/ts/context/validators.d.ts.map +1 -0
  53. package/dist/ts/dataflow/index.d.ts +2 -0
  54. package/dist/ts/dataflow/index.d.ts.map +1 -0
  55. package/dist/ts/dataflow/objects.d.ts +7 -0
  56. package/dist/ts/dataflow/objects.d.ts.map +1 -0
  57. package/dist/ts/dataflow/objects.test.d.ts +2 -0
  58. package/dist/ts/dataflow/objects.test.d.ts.map +1 -0
  59. package/dist/{errors → ts/errors}/errors.d.ts +16 -3
  60. package/dist/ts/errors/errors.d.ts.map +1 -0
  61. package/dist/ts/events/event-manager.d.ts +19 -0
  62. package/dist/ts/events/event-manager.d.ts.map +1 -0
  63. package/dist/ts/events/event-manager.spec.d.ts +2 -0
  64. package/dist/ts/events/event-manager.spec.d.ts.map +1 -0
  65. package/dist/ts/events/index.d.ts +2 -0
  66. package/dist/ts/events/index.d.ts.map +1 -0
  67. package/dist/ts/http/headers.d.ts +21 -0
  68. package/dist/ts/http/headers.d.ts.map +1 -0
  69. package/dist/ts/http/headers.spec.d.ts +2 -0
  70. package/dist/ts/http/headers.spec.d.ts.map +1 -0
  71. package/dist/ts/http/request-context.d.ts +17 -0
  72. package/dist/ts/http/request-context.d.ts.map +1 -0
  73. package/dist/ts/http/request-context.spec.d.ts +2 -0
  74. package/dist/ts/http/request-context.spec.d.ts.map +1 -0
  75. package/dist/ts/http/request.d.ts +31 -0
  76. package/dist/ts/http/request.d.ts.map +1 -0
  77. package/dist/ts/http/request.spec.d.ts +2 -0
  78. package/dist/ts/http/request.spec.d.ts.map +1 -0
  79. package/dist/{http → ts/http}/url.d.ts +5 -4
  80. package/dist/ts/http/url.d.ts.map +1 -0
  81. package/dist/ts/http/url.spec.d.ts +2 -0
  82. package/dist/ts/http/url.spec.d.ts.map +1 -0
  83. package/dist/ts/index.d.ts +47 -0
  84. package/dist/ts/index.d.ts.map +1 -0
  85. package/dist/{pipelines → ts/pipelines}/index.d.ts +1 -0
  86. package/dist/ts/pipelines/index.d.ts.map +1 -0
  87. package/dist/{pipelines → ts/pipelines}/pipeline-action.d.ts +1 -0
  88. package/dist/ts/pipelines/pipeline-action.d.ts.map +1 -0
  89. package/dist/ts/pipelines/pipeline-action.test.d.ts +2 -0
  90. package/dist/ts/pipelines/pipeline-action.test.d.ts.map +1 -0
  91. package/dist/{pipelines → ts/pipelines}/pipeline.d.ts +3 -2
  92. package/dist/ts/pipelines/pipeline.d.ts.map +1 -0
  93. package/dist/ts/pipelines/pipeline.test.d.ts +2 -0
  94. package/dist/ts/pipelines/pipeline.test.d.ts.map +1 -0
  95. package/dist/ts/schema/json-schema.d.ts +12 -0
  96. package/dist/ts/schema/json-schema.d.ts.map +1 -0
  97. package/dist/ts/schema/labels.d.ts +14 -0
  98. package/dist/ts/schema/labels.d.ts.map +1 -0
  99. package/dist/ts/schema/model-schema.d.ts +75 -0
  100. package/dist/ts/schema/model-schema.d.ts.map +1 -0
  101. package/dist/ts/schema/model-schema.test.d.ts +2 -0
  102. package/dist/ts/schema/model-schema.test.d.ts.map +1 -0
  103. package/dist/ts/schema/model.d.ts +35 -0
  104. package/dist/ts/schema/model.d.ts.map +1 -0
  105. package/dist/ts/schema/schema-mixin.d.ts +24 -0
  106. package/dist/ts/schema/schema-mixin.d.ts.map +1 -0
  107. package/dist/ts/schema/test/mock-model.d.ts +8 -0
  108. package/dist/ts/schema/test/mock-model.d.ts.map +1 -0
  109. package/dist/ts/scope/index.d.ts +34 -0
  110. package/dist/ts/scope/index.d.ts.map +1 -0
  111. package/dist/ts/shared/utils/action-descriptor.d.ts +28 -0
  112. package/dist/ts/shared/utils/action-descriptor.d.ts.map +1 -0
  113. package/dist/ts/shared/utils/action-descriptor.test.d.ts +2 -0
  114. package/dist/ts/shared/utils/action-descriptor.test.d.ts.map +1 -0
  115. package/dist/ts/shared/utils/schema-utils.d.ts +3 -0
  116. package/dist/ts/shared/utils/schema-utils.d.ts.map +1 -0
  117. package/dist/ts/shared/utils/schema-utils.test.d.ts +2 -0
  118. package/dist/ts/shared/utils/schema-utils.test.d.ts.map +1 -0
  119. package/dist/ts/shims/async-local-storage.d.ts +36 -0
  120. package/dist/ts/shims/async-local-storage.d.ts.map +1 -0
  121. package/dist/ts/shims/async-local-storage.test.d.ts +2 -0
  122. package/dist/ts/shims/async-local-storage.test.d.ts.map +1 -0
  123. package/dist/{timing.d.ts → ts/timing.d.ts} +1 -0
  124. package/dist/ts/timing.d.ts.map +1 -0
  125. package/dist/{typescript → ts/typescript}/arrays.d.ts +1 -0
  126. package/dist/ts/typescript/arrays.d.ts.map +1 -0
  127. package/dist/{typescript → ts/typescript}/baseModel.d.ts +1 -0
  128. package/dist/ts/typescript/baseModel.d.ts.map +1 -0
  129. package/dist/{typescript → ts/typescript}/classes.d.ts +1 -0
  130. package/dist/ts/typescript/classes.d.ts.map +1 -0
  131. package/dist/{typescript → ts/typescript}/constant-manipulation/snake-case.d.ts +1 -0
  132. package/dist/ts/typescript/constant-manipulation/snake-case.d.ts.map +1 -0
  133. package/dist/{typescript → ts/typescript}/errors.d.ts +1 -0
  134. package/dist/ts/typescript/errors.d.ts.map +1 -0
  135. package/dist/ts/typescript/fetch.d.ts +3 -0
  136. package/dist/ts/typescript/fetch.d.ts.map +1 -0
  137. package/dist/{typescript → ts/typescript}/generics.d.ts +1 -0
  138. package/dist/ts/typescript/generics.d.ts.map +1 -0
  139. package/dist/{typescript → ts/typescript}/index.d.ts +1 -0
  140. package/dist/ts/typescript/index.d.ts.map +1 -0
  141. package/dist/ts/typescript/objects.d.ts +26 -0
  142. package/dist/ts/typescript/objects.d.ts.map +1 -0
  143. package/dist/{typescript → ts/typescript}/promises.d.ts +1 -0
  144. package/dist/ts/typescript/promises.d.ts.map +1 -0
  145. package/dist/{validation → ts/validation}/index.d.ts +1 -0
  146. package/dist/ts/validation/index.d.ts.map +1 -0
  147. package/dist/{validation → ts/validation}/validation.d.ts +1 -0
  148. package/dist/ts/validation/validation.d.ts.map +1 -0
  149. package/dist/{validation → ts/validation}/validator.d.ts +1 -0
  150. package/dist/ts/validation/validator.d.ts.map +1 -0
  151. package/dist/ts/validation/validator.test.d.ts +2 -0
  152. package/dist/ts/validation/validator.test.d.ts.map +1 -0
  153. package/package.json +46 -13
  154. package/src/app/app-context.ts +4 -5
  155. package/src/app/app-lifecycle.ts +4 -3
  156. package/src/app/app.ts +7 -5
  157. package/src/application/create-request-context.test.ts +345 -0
  158. package/src/application/create-request-context.ts +19 -0
  159. package/src/application/use-declaro.ts +27 -0
  160. package/src/auth/permission-validator.test.ts +238 -2
  161. package/src/auth/permission-validator.ts +3 -3
  162. package/src/context/async-context.test.ts +348 -0
  163. package/src/context/async-context.ts +129 -0
  164. package/src/context/context-consumer.ts +4 -4
  165. package/src/context/context.circular-deps.test.ts +1047 -0
  166. package/src/context/context.test.ts +420 -3
  167. package/src/context/context.ts +590 -87
  168. package/src/context/legacy-context.test.ts +9 -9
  169. package/src/dataflow/objects.test.ts +7 -7
  170. package/src/dataflow/objects.ts +10 -9
  171. package/src/errors/errors.ts +19 -3
  172. package/src/events/event-manager.spec.ts +129 -0
  173. package/src/events/event-manager.ts +25 -14
  174. package/src/http/headers.ts +17 -2
  175. package/src/http/request-context.ts +24 -15
  176. package/src/http/request.ts +27 -6
  177. package/src/http/url.ts +3 -3
  178. package/src/index.ts +34 -3
  179. package/src/pipelines/pipeline.test.ts +11 -9
  180. package/src/schema/json-schema.ts +16 -0
  181. package/src/schema/labels.ts +23 -23
  182. package/src/schema/model-schema.test.ts +282 -0
  183. package/src/schema/model-schema.ts +197 -0
  184. package/src/schema/model.ts +143 -0
  185. package/src/schema/schema-mixin.ts +51 -0
  186. package/src/schema/test/mock-model.ts +19 -0
  187. package/src/scope/index.ts +33 -0
  188. package/src/shared/utils/action-descriptor.test.ts +182 -0
  189. package/src/shared/utils/action-descriptor.ts +102 -0
  190. package/src/shared/utils/schema-utils.test.ts +33 -0
  191. package/src/shared/utils/schema-utils.ts +17 -0
  192. package/src/shims/async-local-storage.test.ts +258 -0
  193. package/src/shims/async-local-storage.ts +82 -0
  194. package/src/typescript/objects.ts +32 -1
  195. package/src/validation/validator.test.ts +12 -20
  196. package/dist/app/app-context.d.ts +0 -8
  197. package/dist/app/app-lifecycle.d.ts +0 -4
  198. package/dist/app/app.d.ts +0 -22
  199. package/dist/auth/permission-validator.test.d.ts +0 -1
  200. package/dist/context/context.d.ts +0 -161
  201. package/dist/context/context.test.d.ts +0 -1
  202. package/dist/context/legacy-context.test.d.ts +0 -1
  203. package/dist/dataflow/index.d.ts +0 -1
  204. package/dist/dataflow/objects.d.ts +0 -5
  205. package/dist/dataflow/objects.test.d.ts +0 -1
  206. package/dist/events/event-manager.d.ts +0 -16
  207. package/dist/events/event-manager.spec.d.ts +0 -1
  208. package/dist/events/index.d.ts +0 -1
  209. package/dist/helpers/index.d.ts +0 -1
  210. package/dist/helpers/ucfirst.d.ts +0 -1
  211. package/dist/http/headers.d.ts +0 -4
  212. package/dist/http/headers.spec.d.ts +0 -1
  213. package/dist/http/request-context.d.ts +0 -12
  214. package/dist/http/request-context.spec.d.ts +0 -1
  215. package/dist/http/request.d.ts +0 -8
  216. package/dist/http/request.spec.d.ts +0 -1
  217. package/dist/http/url.spec.d.ts +0 -1
  218. package/dist/index.d.ts +0 -19
  219. package/dist/pipelines/pipeline-action.test.d.ts +0 -1
  220. package/dist/pipelines/pipeline.test.d.ts +0 -1
  221. package/dist/pkg.cjs +0 -30
  222. package/dist/pkg.mjs +0 -56612
  223. package/dist/schema/application.d.ts +0 -83
  224. package/dist/schema/application.test.d.ts +0 -1
  225. package/dist/schema/define-model.d.ts +0 -10
  226. package/dist/schema/define-model.test.d.ts +0 -1
  227. package/dist/schema/formats.d.ts +0 -10
  228. package/dist/schema/index.d.ts +0 -10
  229. package/dist/schema/labels.d.ts +0 -13
  230. package/dist/schema/labels.test.d.ts +0 -1
  231. package/dist/schema/module.d.ts +0 -7
  232. package/dist/schema/module.test.d.ts +0 -1
  233. package/dist/schema/properties.d.ts +0 -19
  234. package/dist/schema/response.d.ts +0 -31
  235. package/dist/schema/response.test.d.ts +0 -1
  236. package/dist/schema/supported-types.d.ts +0 -12
  237. package/dist/schema/supported-types.test.d.ts +0 -1
  238. package/dist/schema/transform-model.d.ts +0 -4
  239. package/dist/schema/transform-model.test.d.ts +0 -1
  240. package/dist/schema/types.d.ts +0 -95
  241. package/dist/schema/types.test.d.ts +0 -1
  242. package/dist/typescript/fetch.d.ts +0 -2
  243. package/dist/typescript/objects.d.ts +0 -12
  244. package/dist/validation/validator.test.d.ts +0 -1
  245. package/src/helpers/index.ts +0 -1
  246. package/src/helpers/ucfirst.ts +0 -3
  247. package/src/schema/application.test.ts +0 -286
  248. package/src/schema/application.ts +0 -150
  249. package/src/schema/define-model.test.ts +0 -81
  250. package/src/schema/define-model.ts +0 -50
  251. package/src/schema/formats.ts +0 -23
  252. package/src/schema/index.ts +0 -10
  253. package/src/schema/labels.test.ts +0 -60
  254. package/src/schema/module.test.ts +0 -39
  255. package/src/schema/module.ts +0 -6
  256. package/src/schema/properties.ts +0 -40
  257. package/src/schema/response.test.ts +0 -101
  258. package/src/schema/response.ts +0 -93
  259. package/src/schema/supported-types.test.ts +0 -20
  260. package/src/schema/supported-types.ts +0 -15
  261. package/src/schema/transform-model.test.ts +0 -31
  262. package/src/schema/transform-model.ts +0 -24
  263. package/src/schema/types.test.ts +0 -28
  264. package/src/schema/types.ts +0 -163
  265. package/tsconfig.json +0 -11
  266. package/vite.config.ts +0 -24
@@ -1,83 +0,0 @@
1
- import { Model } from './define-model';
2
- import { Module } from './module';
3
- import { DeclaroSchema } from './types';
4
- import { Response } from './response';
5
- export type ModuleFactory = (mod: Module) => Module | undefined;
6
- export declare class Application {
7
- private _info;
8
- private _modules;
9
- private _models;
10
- private _responses;
11
- constructor(info: DeclaroSchema.InfoObject);
12
- /**
13
- * Get the application info (read-only). Application info can only be set in the constructor of the application.
14
- *
15
- * Note: This should be set by the application implementation. It would be dangerous for any one module to be able to change the application info for all of the others.
16
- */
17
- get info(): import("openapi-types").OpenAPIV3_1.InfoObject;
18
- /**
19
- * Define a module for the application.
20
- *
21
- * @param tag The tag info for the module, to be used in the OpenAPI schema
22
- * @param factory A convenience function to define the module, adding endpoints, etc.
23
- * @returns
24
- */
25
- defineModule(tag: DeclaroSchema.TagObject, factory?: ModuleFactory): Module;
26
- /**
27
- * Get a module by name.
28
- *
29
- * @param name The name of the module to get
30
- * @returns The `Module` instance for the given name
31
- */
32
- getModule(name: string): Module;
33
- /**
34
- * Add models to the application.
35
- *
36
- * @param models The models to add to the application
37
- * @example app.addModel(User)
38
- * @example app.addModel(User, Post)
39
- * @example app.addModel(...myModels)
40
- * @returns The application instance
41
- */
42
- addModel(...models: Model[]): this;
43
- /**
44
- * Get a model by name.
45
- *
46
- * @param name The name of the model to get
47
- * @returns The `Model` instance for the given name
48
- */
49
- getModel(name: string): Model;
50
- /**
51
- * Get all models.
52
- *
53
- * @returns All models in the application
54
- */
55
- getModels(): Model[];
56
- /**
57
- * Add a response to the application.
58
- *
59
- * @param code The HTTP status code for the response
60
- * @param response The response object
61
- * @returns The application instance
62
- */
63
- addResponse(...responses: Response[]): this;
64
- /**
65
- * Get a response by status code.
66
- *
67
- * @param code The HTTP status code for the response
68
- * @returns The `Response` instance for the given status code
69
- */
70
- getResponse(code: number): Response;
71
- /**
72
- * Get all responses. (read-only)
73
- *
74
- * @returns All responses in the application
75
- */
76
- get responses(): Map<number, Response>;
77
- /**
78
- * Get all responses as a hash of keys and values.
79
- *
80
- * @returns A hash of keys and values representing all responses in the application
81
- */
82
- getResponseSchema(): DeclaroSchema.ResponsesObject;
83
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import { DeclaroSchema } from './types';
2
- export type Model<T extends DeclaroSchema.AnyObjectProperties = DeclaroSchema.AnyObjectProperties, N extends Readonly<string> = string> = {
3
- name: N;
4
- schema: DeclaroSchema.SchemaObject<T>;
5
- isModel: true;
6
- };
7
- export type ModelName<T extends Model<any, string>> = T['name'];
8
- export type ModelProperties<T extends Model<any, string>> = T['schema']['properties'];
9
- export declare function initializeModel(schema: DeclaroSchema.SchemaObject<any>): DeclaroSchema.SchemaObject<any, string>;
10
- export declare function defineModel<T extends DeclaroSchema.AnyObjectProperties, N extends Readonly<string>>(name: N, doc: DeclaroSchema.SchemaObject<T>): Model<T, N>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- export declare enum RelationFormat {
2
- OneToOne = "one-to-one",
3
- OneToMany = "one-to-many",
4
- ManyToOne = "many-to-one",
5
- ManyToMany = "many-to-many",
6
- EmbeddedObject = "embedded-object",
7
- EmbeddedArray = "embedded-array"
8
- }
9
- export type RelationReferenceType = 'object' | 'array';
10
- export declare function getReferenceType(format: string): RelationReferenceType;
@@ -1,10 +0,0 @@
1
- export * from './define-model';
2
- export * from './supported-types';
3
- export * from './transform-model';
4
- export * from './labels';
5
- export * from './module';
6
- export * from './application';
7
- export * from './response';
8
- export * from './formats';
9
- export * from './properties';
10
- export * from './types';
@@ -1,13 +0,0 @@
1
- export type EntityLabels = {
2
- singularLabel?: string;
3
- pluralLabel?: string;
4
- singularParameter?: string;
5
- pluralParameter?: string;
6
- singularSlug?: string;
7
- pluralSlug?: string;
8
- singularEntityName?: string;
9
- pluralEntityName?: string;
10
- singularTableName?: string;
11
- pluralTableName?: string;
12
- };
13
- export declare function getEntityLabels(entity: string, labels?: Partial<EntityLabels>): EntityLabels;
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { Application } from './application';
2
- import { DeclaroSchema } from './types';
3
- export declare class Module {
4
- readonly application: Application;
5
- readonly tag: DeclaroSchema.TagObject;
6
- constructor(application: Application, tag: DeclaroSchema.TagObject);
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { DeclaroSchema } from './types';
2
- export declare const t: {
3
- string: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => T & {
4
- type: "string";
5
- };
6
- number: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => T & {
7
- type: "number";
8
- };
9
- boolean: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => T & {
10
- type: "boolean";
11
- };
12
- integer: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => T & {
13
- type: "integer";
14
- };
15
- object: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => T & {
16
- type: "object";
17
- };
18
- array: <T extends DeclaroSchema.NonArraySchemaObject<any, any>>(property?: T) => never;
19
- };
@@ -1,31 +0,0 @@
1
- import { DeclaroSchema } from './types';
2
- export type MediaRecord<T extends DeclaroSchema.AnyObjectProperties> = {
3
- contentType: string;
4
- media: DeclaroSchema.MediaTypeObject<T>;
5
- };
6
- export declare class Response {
7
- private _code;
8
- private _response;
9
- private _mediaTypes;
10
- constructor(code: number, response: DeclaroSchema.ResponseObject);
11
- /**
12
- *
13
- * @param contentType The HTTP content type
14
- * @param media The openapi media schema defining the response type.
15
- * @returns An instance of the response object for chaining content types.
16
- */
17
- content(contentType: string, ...media: DeclaroSchema.MediaTypeObject<any>[]): this;
18
- merge(response: Response): this;
19
- /**
20
- * The response code.
21
- *
22
- * Note: Read-only. This can only be initialized in the constructor.
23
- */
24
- get code(): number;
25
- /**
26
- * The fully composed openapi response object.
27
- */
28
- get schema(): DeclaroSchema.ResponseObject;
29
- protected getContentTypes(): string[];
30
- protected getMediaForContentType(contentType: string): DeclaroSchema.MediaTypeObject<any>[];
31
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- export declare const TypescriptMap: {
2
- string: string;
3
- text: string;
4
- integer: string;
5
- number: string;
6
- float: string;
7
- double: string;
8
- boolean: string;
9
- date: string;
10
- datetime: string;
11
- time: string;
12
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import { Model } from '.';
2
- export declare function transformModel(model: Model<any>): {
3
- toTypescript(): string;
4
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,95 +0,0 @@
1
- import { OpenAPIV3_1 } from 'openapi-types';
2
- import { ModelNames } from '$models/reference';
3
- import { EntityLabels } from './labels';
4
- export declare namespace DeclaroSchema {
5
- type Modify<T, R> = Omit<T, keyof R> & R;
6
- type NonArraySchemaObjectType = OpenAPIV3_1.NonArraySchemaObjectType;
7
- type ArraySchemaObjectType = OpenAPIV3_1.ArraySchemaObjectType;
8
- type AnySchemaObjectType = NonArraySchemaObjectType | ArraySchemaObjectType;
9
- type AnyObjectProperties = {
10
- [name: string]: SchemaObject<any> | ReferenceObject;
11
- };
12
- type AnyObjectParameters = {
13
- [name: string]: Omit<DeclaroSchema.ParameterObject, 'name'>;
14
- };
15
- interface BaseSchemaObject<T extends AnyObjectProperties, N extends ModelNames = ModelNames> extends OpenAPIV3_1.BaseSchemaObject {
16
- $schema?: N;
17
- propertyName?: string;
18
- additionalProperties?: boolean | ReferenceObject | SchemaObject<T>;
19
- properties?: T;
20
- labels?: EntityLabels;
21
- not?: ReferenceObject | SchemaObject<T>;
22
- allOf?: (ReferenceObject | SchemaObject<T>)[];
23
- anyOf?: (ReferenceObject | SchemaObject<T>)[];
24
- oneOf?: (ReferenceObject | SchemaObject<T>)[];
25
- }
26
- interface NonArraySchemaObject<T extends AnyObjectProperties, N extends ModelNames> extends BaseSchemaObject<T, N> {
27
- type?: NonArraySchemaObjectType;
28
- labels?: EntityLabels;
29
- }
30
- interface ArraySchemaObject<T extends AnyObjectProperties, N extends ModelNames> extends BaseSchemaObject<T> {
31
- type: ArraySchemaObjectType;
32
- items: ReferenceObject | SchemaObject<T, N>;
33
- }
34
- type SchemaObject<T extends AnyObjectProperties, N extends string = string> = ArraySchemaObject<T, N> | NonArraySchemaObject<T, N>;
35
- type PropertyType<T extends SchemaObject<any>> = T['type'] extends 'string' ? string : T['type'] extends 'boolean' ? boolean : T['type'] extends 'number' ? number : T['type'] extends 'integer' ? number : T['type'] extends 'object' ? ObjectPayload<T['properties']> : T['type'] extends 'array' ? ObjectPayload<T['properties']>[] : any;
36
- type OperationInput<T extends AnyObjectParameters> = {
37
- [K in keyof T]: PropertyType<T[K]['schema']>;
38
- };
39
- type ObjectPayload<T extends AnyObjectProperties> = {
40
- [K in keyof T]: PropertyType<T[K]>;
41
- };
42
- type Payload<T extends AnyObjectProperties, TSchema extends SchemaObject<T>> = any;
43
- interface ReferenceObject {
44
- $ref: ModelNames;
45
- format?: string;
46
- }
47
- type InfoObject = OpenAPIV3_1.InfoObject;
48
- type TagObject = OpenAPIV3_1.TagObject;
49
- type ExampleObject = OpenAPIV3_1.ExampleObject;
50
- type MediaTypeObject<T extends AnyObjectProperties> = Modify<OpenAPIV3_1.MediaTypeObject, {
51
- schema?: SchemaObject<T> | ReferenceObject;
52
- examples?: Record<string, ReferenceObject | ExampleObject>;
53
- }>;
54
- type ServerObject = OpenAPIV3_1.ServerObject;
55
- type LinkObject = Modify<OpenAPIV3_1.LinkObject, {
56
- server?: ServerObject;
57
- }>;
58
- type ResponseObject = Modify<OpenAPIV3_1.ResponseObject, {
59
- headers?: {
60
- [header: string]: ReferenceObject | HeaderObject;
61
- };
62
- content?: {
63
- [media: string]: MediaTypeObject<any>;
64
- };
65
- links?: {
66
- [link: string]: ReferenceObject | LinkObject;
67
- };
68
- }>;
69
- type ResponsesObject = OpenAPIV3_1.ResponsesObject;
70
- type HeaderObject = OpenAPIV3_1.HeaderObject;
71
- type HttpMethods = OpenAPIV3_1.HttpMethods;
72
- type ParameterObject = Modify<OpenAPIV3_1.ParameterObject, {
73
- in: 'query' | 'header' | 'path' | 'cookie';
74
- schema?: SchemaObject<any> | ReferenceObject;
75
- }>;
76
- type RequestBodyObject<T extends AnyObjectProperties> = Modify<OpenAPIV3_1.RequestBodyObject, {
77
- content: {
78
- [media: string]: MediaTypeObject<T>;
79
- };
80
- }>;
81
- type CallbackObject = Record<string, PathItemObject | ReferenceObject>;
82
- type PathItemObject<T extends {} = {}> = Modify<OpenAPIV3_1.PathItemObject<T>, {
83
- servers?: ServerObject[];
84
- parameters?: (ReferenceObject | ParameterObject)[];
85
- }> & {
86
- [method in HttpMethods]?: OperationObject<T>;
87
- };
88
- type OperationObject<T extends {} = {}> = Modify<OpenAPIV3_1.OperationObject<T>, {
89
- parameters?: ParameterObject[];
90
- requestBody?: ReferenceObject | RequestBodyObject<T>;
91
- responses?: ResponsesObject;
92
- callbacks?: Record<string, ReferenceObject | CallbackObject>;
93
- servers?: ServerObject[];
94
- }> & T;
95
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { default as fetch } from 'node-fetch';
2
- export type FetchFunc = typeof fetch;
@@ -1,12 +0,0 @@
1
- export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
2
- declare const _default: {};
3
- export default _default;
4
- export type DeepPartial<T> = T extends object ? {
5
- [P in keyof T]?: DeepPartial<T[P]>;
6
- } : T;
7
- /**
8
- * Merge two object types without using an intersection type. Intersection types preserve the original types of the objects causing confusion, while this type will merge the types of the objects.
9
- */
10
- export type Merge<A, B> = {
11
- [key in keyof A | keyof B]: key extends keyof B ? B[key] : key extends keyof A ? A[key] : never;
12
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from './ucfirst'
@@ -1,3 +0,0 @@
1
- export function ucfirst(s) {
2
- return s.substring(0, 1).toUpperCase() + s.substring(1);
3
- }
@@ -1,286 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { Application } from './application'
3
- import { Module } from './module'
4
- import { defineModel } from './define-model'
5
- import type { OpenAPIV3_1 } from 'openapi-types'
6
- import { Response } from './response'
7
-
8
- describe('Application schema', () => {
9
- it('should define an application schema', () => {
10
- const app = new Application({
11
- title: 'My API',
12
- version: '1.0.0',
13
- description: 'My API description',
14
- termsOfService: 'https://example.com/terms',
15
- contact: {
16
- name: 'API Support',
17
- url: 'https://example.com/support',
18
- email: 'test@test.com',
19
- },
20
- })
21
-
22
- expect(app.info.title).toBe('My API')
23
- expect(app.info.version).toBe('1.0.0')
24
- expect(app.info.description).toBe('My API description')
25
- expect(app.info.termsOfService).toBe('https://example.com/terms')
26
- expect(app.info.contact.name).toBe('API Support')
27
- expect(app.info.contact.url).toBe('https://example.com/support')
28
- expect(app.info.contact.email).toBe('test@test.com')
29
- })
30
-
31
- it('should be able to add a module', () => {
32
- const app = new Application({
33
- title: 'My API',
34
- version: '1.0.0',
35
- description: 'My API description',
36
- termsOfService: 'https://example.com/terms',
37
- contact: {
38
- name: 'API Support',
39
- url: 'https://example.com/support',
40
- email: 'test@test.com',
41
- },
42
- })
43
-
44
- const result = app.defineModule({
45
- name: 'Module',
46
- description: 'Module description',
47
- externalDocs: {
48
- description: 'External documentation',
49
- url: 'https://example.com/docs',
50
- },
51
- })
52
-
53
- expect(result).toBeInstanceOf(Module)
54
-
55
- const module = app.getModule('Module')
56
-
57
- expect(module).toBeInstanceOf(Module)
58
-
59
- expect(module.application).toBeInstanceOf(Application)
60
- expect(module.application.info.title).toBe('My API')
61
- expect(module.application.info.version).toBe('1.0.0')
62
-
63
- expect(module).toBeInstanceOf(Module)
64
- expect(module.tag.name).toBe('Module')
65
- expect(module.tag.description).toBe('Module description')
66
- expect(module.tag.externalDocs.description).toBe('External documentation')
67
- })
68
-
69
- it('Should allow multiple module definitions to be chained', () => {
70
- const app = new Application({
71
- title: 'My API',
72
- version: '1.0.0',
73
- description: 'My API description',
74
- termsOfService: 'https://example.com/terms',
75
- contact: {
76
- name: 'API Support',
77
- url: 'https://example.com/support',
78
- email: 'test@test.com',
79
- },
80
- })
81
-
82
- app.defineModule({
83
- name: 'Module1',
84
- description: 'Module 1 description',
85
- externalDocs: {
86
- description: 'External documentation 1',
87
- url: 'https://example.com/docs1',
88
- },
89
- })
90
- app.defineModule({
91
- name: 'Module2',
92
- description: 'Module 2 description',
93
- externalDocs: {
94
- description: 'External documentation 2',
95
- url: 'https://example.com/docs2',
96
- },
97
- })
98
-
99
- const module1 = app.getModule('Module1')
100
- const module2 = app.getModule('Module2')
101
-
102
- expect(module1.tag.name).toBe('Module1')
103
- expect(module1.tag.description).toBe('Module 1 description')
104
- expect(module1.tag.externalDocs.description).toBe('External documentation 1')
105
- expect(module1.tag.externalDocs.url).toBe('https://example.com/docs1')
106
-
107
- expect(module2.tag.name).toBe('Module2')
108
- expect(module2.tag.description).toBe('Module 2 description')
109
- expect(module2.tag.externalDocs.description).toBe('External documentation 2')
110
- expect(module2.tag.externalDocs.url).toBe('https://example.com/docs2')
111
- })
112
-
113
- it('Should allow models to be added to the application', () => {
114
- const app = new Application({
115
- title: 'My API',
116
- version: '1.0.0',
117
- description: 'My API description',
118
- termsOfService: 'https://example.com/terms',
119
- contact: {
120
- name: 'API Support',
121
- url: 'https://example.com/support',
122
- email: 'test@test.com',
123
- },
124
- })
125
-
126
- const model1 = defineModel('Model1', {
127
- type: 'object',
128
- properties: {
129
- name: {
130
- type: 'string',
131
- },
132
- },
133
- })
134
-
135
- const model2 = defineModel('Model2', {
136
- type: 'object',
137
- properties: {
138
- number: {
139
- type: 'integer',
140
- },
141
- },
142
- })
143
-
144
- app.addModel(model1, model2)
145
-
146
- const allModels = app.getModels()
147
-
148
- expect(allModels).toHaveLength(2)
149
-
150
- expect(allModels[0].name).toBe('Model1')
151
- expect(allModels[1].name).toBe('Model2')
152
- })
153
-
154
- it('Should allow responses to be added to the application', () => {
155
- const app = new Application({
156
- title: 'My API',
157
- version: '1.0.0',
158
- description: 'My API description',
159
- termsOfService: 'https://example.com/terms',
160
- contact: {
161
- name: 'API Support',
162
- url: 'https://example.com/support',
163
- email: 'test@test.com',
164
- },
165
- })
166
-
167
- const error500 = new Response(500, {
168
- description: 'Internal server error',
169
- }).content('application/json', {
170
- schema: {
171
- type: 'object',
172
- properties: {
173
- message: {
174
- type: 'string',
175
- },
176
- },
177
- },
178
- })
179
-
180
- const error404 = new Response(404, {
181
- description: 'Not found',
182
- }).content('application/json', {
183
- schema: {
184
- type: 'object',
185
- properties: {
186
- message: {
187
- type: 'string',
188
- },
189
- },
190
- },
191
- })
192
-
193
- const error400 = new Response(400, {
194
- description: 'Bad request',
195
- }).content('application/json', {
196
- schema: {
197
- type: 'object',
198
- properties: {
199
- message: {
200
- type: 'string',
201
- },
202
- },
203
- },
204
- })
205
-
206
- app.addResponse(error500, error404, error400)
207
-
208
- const response500 = app.getResponse(500)
209
- const response404 = app.getResponse(404)
210
- const response400 = app.getResponse(400)
211
-
212
- const allResponses = app.getResponseSchema()
213
-
214
- expect(response500.code).toBe(500)
215
- expect(response500.schema.description).toBe('Internal server error')
216
-
217
- expect(response404.code).toBe(404)
218
- expect(response404.schema.description).toBe('Not found')
219
-
220
- expect(response400.code).toBe(400)
221
- expect(response400.schema.description).toBe('Bad request')
222
-
223
- expect(allResponses[500].description).toBe('Internal server error')
224
- expect((allResponses[500] as any).content['application/json'].schema.type).toBe('object')
225
- expect((allResponses[500] as any).content['application/json'].schema.properties.message.type).toBe('string')
226
-
227
- expect(allResponses[404].description).toBe('Not found')
228
- expect((allResponses[404] as any).content['application/json'].schema.type).toBe('object')
229
- expect((allResponses[404] as any).content['application/json'].schema.properties.message.type).toBe('string')
230
-
231
- expect(allResponses[400].description).toBe('Bad request')
232
- expect((allResponses[400] as any).content['application/json'].schema.type).toBe('object')
233
- expect((allResponses[400] as any).content['application/json'].schema.properties.message.type).toBe('string')
234
- })
235
-
236
- it('Should allow paths to be added to the application', () => {
237
- function test(doc: OpenAPIV3_1.Document) {}
238
-
239
- test({
240
- openapi: '3.0.0',
241
- info: {
242
- title: 'My API',
243
- version: '1.0.0',
244
- },
245
- paths: {
246
- '/test': {
247
- get: {
248
- description: 'Test endpoint',
249
- responses: {
250
- 200: {
251
- description: 'Successful response',
252
- content: {
253
- 'application/json': {
254
- schema: {
255
- oneOf: [
256
- {
257
- type: 'object',
258
- properties: {
259
- message: {
260
- type: 'string',
261
- },
262
- },
263
- },
264
- {
265
- type: 'object',
266
- properties: {
267
- error: {
268
- type: 'string',
269
- },
270
- },
271
- },
272
- ],
273
- },
274
- },
275
- },
276
- },
277
- 500: {
278
- description: 'Internal server error',
279
- },
280
- },
281
- },
282
- },
283
- },
284
- })
285
- })
286
- })