@noego/stitch 1.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 (60) hide show
  1. package/README-schema.md +139 -0
  2. package/bin/stitch.js +156 -0
  3. package/dist/browser/index.d.ts +4 -0
  4. package/dist/browser/index.d.ts.map +1 -0
  5. package/dist/cli/StitchCLI.d.ts +12 -0
  6. package/dist/cli/StitchCLI.d.ts.map +1 -0
  7. package/dist/client.cjs +2 -0
  8. package/dist/client.cjs.map +1 -0
  9. package/dist/client.mjs +83 -0
  10. package/dist/client.mjs.map +1 -0
  11. package/dist/core/ConfigParser.d.ts +16 -0
  12. package/dist/core/ConfigParser.d.ts.map +1 -0
  13. package/dist/core/StitchEngine.d.ts +31 -0
  14. package/dist/core/StitchEngine.d.ts.map +1 -0
  15. package/dist/core/Validator.d.ts +18 -0
  16. package/dist/core/Validator.d.ts.map +1 -0
  17. package/dist/core/ViteHelper.d.ts +33 -0
  18. package/dist/core/ViteHelper.d.ts.map +1 -0
  19. package/dist/core/YamlMerger.d.ts +29 -0
  20. package/dist/core/YamlMerger.d.ts.map +1 -0
  21. package/dist/core/YamlMergerBrowser.d.ts +18 -0
  22. package/dist/core/YamlMergerBrowser.d.ts.map +1 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/types/StitchTypes.d.ts +38 -0
  26. package/dist/types/StitchTypes.d.ts.map +1 -0
  27. package/dist-ssr/browser/index.d.ts +4 -0
  28. package/dist-ssr/browser/index.d.ts.map +1 -0
  29. package/dist-ssr/cli/StitchCLI.d.ts +12 -0
  30. package/dist-ssr/cli/StitchCLI.d.ts.map +1 -0
  31. package/dist-ssr/core/ConfigParser.d.ts +16 -0
  32. package/dist-ssr/core/ConfigParser.d.ts.map +1 -0
  33. package/dist-ssr/core/StitchEngine.d.ts +31 -0
  34. package/dist-ssr/core/StitchEngine.d.ts.map +1 -0
  35. package/dist-ssr/core/Validator.d.ts +18 -0
  36. package/dist-ssr/core/Validator.d.ts.map +1 -0
  37. package/dist-ssr/core/ViteHelper.d.ts +33 -0
  38. package/dist-ssr/core/ViteHelper.d.ts.map +1 -0
  39. package/dist-ssr/core/YamlMerger.d.ts +29 -0
  40. package/dist-ssr/core/YamlMerger.d.ts.map +1 -0
  41. package/dist-ssr/core/YamlMergerBrowser.d.ts +18 -0
  42. package/dist-ssr/core/YamlMergerBrowser.d.ts.map +1 -0
  43. package/dist-ssr/index.d.ts +15 -0
  44. package/dist-ssr/index.d.ts.map +1 -0
  45. package/dist-ssr/server.cjs +574 -0
  46. package/dist-ssr/server.cjs.map +1 -0
  47. package/dist-ssr/server.d.ts +2 -0
  48. package/dist-ssr/server.js +554 -0
  49. package/dist-ssr/server.js.map +1 -0
  50. package/dist-ssr/types/StitchTypes.d.ts +38 -0
  51. package/dist-ssr/types/StitchTypes.d.ts.map +1 -0
  52. package/docs/advanced_validation.md +188 -0
  53. package/docs/middleware.md +507 -0
  54. package/docs/modules.md +175 -0
  55. package/docs/project.md +856 -0
  56. package/docs/validation.md +77 -0
  57. package/package.json +67 -0
  58. package/readme.md +159 -0
  59. package/schemas/schema.json +360 -0
  60. package/schemas/stitch-schema.json +38 -0
@@ -0,0 +1,175 @@
1
+ # Module Support in OpenAPI Configuration
2
+
3
+ This document explains how to use the module feature in your OpenAPI configuration to organize API routes into logical groups.
4
+
5
+ ## Overview
6
+
7
+ The module feature allows you to define groups of related API endpoints with a common base path. This helps in:
8
+
9
+ 1. Better organization of your API specification
10
+ 2. Avoiding duplication of base paths
11
+ 3. Keeping related endpoints grouped together
12
+
13
+ ## Configuration
14
+
15
+ ### Adding Modules to Your OpenAPI Document
16
+
17
+ To use modules, add a top-level `module` field to your OpenAPI document:
18
+
19
+ ```yaml
20
+ openapi: 3.0.0
21
+ info:
22
+ title: My API
23
+ version: 1.0.0
24
+ paths:
25
+ # Top-level paths go here
26
+
27
+ # Module definitions
28
+ module:
29
+ user: # Module name
30
+ basePath: "/users" # Common prefix for all routes in this module
31
+ paths:
32
+ # Module-specific paths
33
+ "/":
34
+ get:
35
+ x-controller: user.controller
36
+ x-action: getAll
37
+ # Other operation properties...
38
+
39
+ "/{id}":
40
+ get:
41
+ x-controller: user.controller
42
+ x-action: get
43
+ # Other operation properties...
44
+ ```
45
+
46
+ ### Module Properties
47
+
48
+ Each module requires:
49
+
50
+ 1. `basePath`: The common URL prefix for all routes in this module
51
+ 2. `paths`: An object or array containing the module's endpoint definitions
52
+
53
+ The `basePath` will be combined with each path in the `paths` object to create the full route path.
54
+
55
+ ### Defining Paths
56
+
57
+ You can define paths in two ways:
58
+
59
+ #### Object Format (Recommended)
60
+
61
+ Use an object where keys are path suffixes and values are the path configurations:
62
+
63
+ ```yaml
64
+ module:
65
+ post:
66
+ basePath: "/posts"
67
+ paths:
68
+ "/":
69
+ get:
70
+ x-controller: post.controller
71
+ x-action: getAll
72
+ # ...
73
+
74
+ "/{id}":
75
+ get:
76
+ x-controller: post.controller
77
+ x-action: get
78
+ # ...
79
+ ```
80
+
81
+ #### Array Format (Alternative)
82
+
83
+ Define paths as an array of strings with a separate `pathObjects` property:
84
+
85
+ ```yaml
86
+ module:
87
+ post:
88
+ basePath: "/posts"
89
+ paths: ["/", "/{id}", "/create"]
90
+ pathObjects:
91
+ "/":
92
+ get:
93
+ x-controller: post.controller
94
+ x-action: getAll
95
+ # ...
96
+
97
+ "/{id}":
98
+ get:
99
+ x-controller: post.controller
100
+ x-action: get
101
+ # ...
102
+ ```
103
+
104
+ ## How It Works
105
+
106
+ When the server starts:
107
+
108
+ 1. The OpenAPI parser reads the document and processes all modules
109
+ 2. Each module path is combined with its base path to create complete paths
110
+ 3. These combined paths are added to the main `paths` object
111
+ 4. Routes are created as normal from the final paths object
112
+
113
+ ## Example
114
+
115
+ Here's a complete example:
116
+
117
+ ```yaml
118
+ openapi: 3.0.0
119
+ info:
120
+ title: Blog API
121
+ version: 1.0.0
122
+ paths:
123
+ # Global routes outside of modules
124
+ /health:
125
+ get:
126
+ x-controller: health.controller
127
+ x-action: check
128
+ summary: Health check endpoint
129
+
130
+ # Module definitions
131
+ module:
132
+ user:
133
+ basePath: "/users"
134
+ paths:
135
+ "/":
136
+ get:
137
+ x-controller: user.controller
138
+ x-action: getAll
139
+ summary: Get all users
140
+
141
+ "/{id}":
142
+ get:
143
+ x-controller: user.controller
144
+ x-action: get
145
+ summary: Get user by ID
146
+
147
+ post:
148
+ basePath: "/posts"
149
+ paths:
150
+ "/":
151
+ get:
152
+ x-controller: post.controller
153
+ x-action: getAll
154
+ summary: Get all posts
155
+
156
+ "/{id}":
157
+ get:
158
+ x-controller: post.controller
159
+ x-action: get
160
+ summary: Get post by ID
161
+ ```
162
+
163
+ This will create the following routes:
164
+ - `GET /health`
165
+ - `GET /users/`
166
+ - `GET /users/{id}`
167
+ - `GET /posts/`
168
+ - `GET /posts/{id}`
169
+
170
+ ## Best Practices
171
+
172
+ 1. Use modules to group related functionality
173
+ 2. Ensure basePath is meaningful and follows REST conventions
174
+ 3. Keep paths consistent within modules
175
+ 4. Document your module structure for other developers