@classytic/arc 1.1.0 → 2.1.3

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 (200) hide show
  1. package/README.md +247 -794
  2. package/bin/arc.js +91 -52
  3. package/dist/EventTransport-BkUDYZEb.d.mts +99 -0
  4. package/dist/HookSystem-BsGV-j2l.mjs +404 -0
  5. package/dist/ResourceRegistry-7Ic20ZMw.mjs +249 -0
  6. package/dist/adapters/index.d.mts +5 -0
  7. package/dist/adapters/index.mjs +3 -0
  8. package/dist/audit/index.d.mts +81 -0
  9. package/dist/audit/index.mjs +275 -0
  10. package/dist/audit/mongodb.d.mts +5 -0
  11. package/dist/audit/mongodb.mjs +3 -0
  12. package/dist/audited-CGdLiSlE.mjs +140 -0
  13. package/dist/auth/index.d.mts +188 -0
  14. package/dist/auth/index.mjs +1096 -0
  15. package/dist/auth/redis-session.d.mts +43 -0
  16. package/dist/auth/redis-session.mjs +75 -0
  17. package/dist/betterAuthOpenApi-DjWDddNc.mjs +249 -0
  18. package/dist/cache/index.d.mts +145 -0
  19. package/dist/cache/index.mjs +91 -0
  20. package/dist/caching-GSDJcA6-.mjs +93 -0
  21. package/dist/chunk-C7Uep-_p.mjs +20 -0
  22. package/dist/circuitBreaker-DYhWBW_D.mjs +1096 -0
  23. package/dist/cli/commands/describe.d.mts +18 -0
  24. package/dist/cli/commands/describe.mjs +238 -0
  25. package/dist/cli/commands/docs.d.mts +13 -0
  26. package/dist/cli/commands/docs.mjs +52 -0
  27. package/dist/cli/commands/{generate.d.ts → generate.d.mts} +3 -2
  28. package/dist/cli/commands/generate.mjs +357 -0
  29. package/dist/cli/commands/{init.d.ts → init.d.mts} +11 -8
  30. package/dist/cli/commands/{init.js → init.mjs} +807 -617
  31. package/dist/cli/commands/introspect.d.mts +10 -0
  32. package/dist/cli/commands/introspect.mjs +75 -0
  33. package/dist/cli/index.d.mts +16 -0
  34. package/dist/cli/index.mjs +156 -0
  35. package/dist/constants-DdXFXQtN.mjs +84 -0
  36. package/dist/core/index.d.mts +5 -0
  37. package/dist/core/index.mjs +4 -0
  38. package/dist/createApp-D2D5XXaV.mjs +559 -0
  39. package/dist/defineResource-PXzSJ15_.mjs +2197 -0
  40. package/dist/discovery/index.d.mts +46 -0
  41. package/dist/discovery/index.mjs +109 -0
  42. package/dist/docs/index.d.mts +162 -0
  43. package/dist/docs/index.mjs +74 -0
  44. package/dist/elevation-DGo5shaX.d.mts +87 -0
  45. package/dist/elevation-DSTbVvYj.mjs +113 -0
  46. package/dist/errorHandler-C3GY3_ow.mjs +108 -0
  47. package/dist/errorHandler-CW3OOeYq.d.mts +72 -0
  48. package/dist/errors-DAWRdiYP.d.mts +124 -0
  49. package/dist/errors-DBANPbGr.mjs +211 -0
  50. package/dist/eventPlugin-BEOvaDqo.mjs +229 -0
  51. package/dist/eventPlugin-H6wDDjGO.d.mts +124 -0
  52. package/dist/events/index.d.mts +53 -0
  53. package/dist/events/index.mjs +51 -0
  54. package/dist/events/transports/redis-stream-entry.d.mts +2 -0
  55. package/dist/events/transports/redis-stream-entry.mjs +177 -0
  56. package/dist/events/transports/redis.d.mts +76 -0
  57. package/dist/events/transports/redis.mjs +124 -0
  58. package/dist/externalPaths-SyPF2tgK.d.mts +50 -0
  59. package/dist/factory/index.d.mts +63 -0
  60. package/dist/factory/index.mjs +3 -0
  61. package/dist/fastifyAdapter-C8DlE0YH.d.mts +216 -0
  62. package/dist/fields-Bi_AVKSo.d.mts +109 -0
  63. package/dist/fields-CTd_CrKr.mjs +114 -0
  64. package/dist/hooks/index.d.mts +4 -0
  65. package/dist/hooks/index.mjs +3 -0
  66. package/dist/idempotency/index.d.mts +96 -0
  67. package/dist/idempotency/index.mjs +319 -0
  68. package/dist/idempotency/mongodb.d.mts +2 -0
  69. package/dist/idempotency/mongodb.mjs +114 -0
  70. package/dist/idempotency/redis.d.mts +2 -0
  71. package/dist/idempotency/redis.mjs +103 -0
  72. package/dist/index.d.mts +260 -0
  73. package/dist/index.mjs +104 -0
  74. package/dist/integrations/event-gateway.d.mts +46 -0
  75. package/dist/integrations/event-gateway.mjs +43 -0
  76. package/dist/integrations/index.d.mts +5 -0
  77. package/dist/integrations/index.mjs +1 -0
  78. package/dist/integrations/jobs.d.mts +103 -0
  79. package/dist/integrations/jobs.mjs +123 -0
  80. package/dist/integrations/streamline.d.mts +60 -0
  81. package/dist/integrations/streamline.mjs +125 -0
  82. package/dist/integrations/websocket.d.mts +82 -0
  83. package/dist/integrations/websocket.mjs +288 -0
  84. package/dist/interface-CSNjltAc.d.mts +77 -0
  85. package/dist/interface-DTbsvIWe.d.mts +54 -0
  86. package/dist/interface-e9XfSsUV.d.mts +1097 -0
  87. package/dist/introspectionPlugin-B3JkrjwU.mjs +53 -0
  88. package/dist/keys-DhqDRxv3.mjs +42 -0
  89. package/dist/logger-ByrvQWZO.mjs +78 -0
  90. package/dist/memory-B2v7KrCB.mjs +143 -0
  91. package/dist/migrations/index.d.mts +156 -0
  92. package/dist/migrations/index.mjs +260 -0
  93. package/dist/mongodb-ClykrfGo.d.mts +118 -0
  94. package/dist/mongodb-DNKEExbf.mjs +93 -0
  95. package/dist/mongodb-Dg8O_gvd.d.mts +71 -0
  96. package/dist/openapi-9nB_kiuR.mjs +525 -0
  97. package/dist/org/index.d.mts +68 -0
  98. package/dist/org/index.mjs +513 -0
  99. package/dist/org/types.d.mts +82 -0
  100. package/dist/org/types.mjs +1 -0
  101. package/dist/permissions/index.d.mts +278 -0
  102. package/dist/permissions/index.mjs +579 -0
  103. package/dist/plugins/index.d.mts +172 -0
  104. package/dist/plugins/index.mjs +522 -0
  105. package/dist/plugins/response-cache.d.mts +87 -0
  106. package/dist/plugins/response-cache.mjs +283 -0
  107. package/dist/plugins/tracing-entry.d.mts +2 -0
  108. package/dist/plugins/tracing-entry.mjs +185 -0
  109. package/dist/pluralize-CM-jZg7p.mjs +86 -0
  110. package/dist/policies/{index.d.ts → index.d.mts} +204 -170
  111. package/dist/policies/index.mjs +321 -0
  112. package/dist/presets/{index.d.ts → index.d.mts} +62 -131
  113. package/dist/presets/index.mjs +143 -0
  114. package/dist/presets/multiTenant.d.mts +24 -0
  115. package/dist/presets/multiTenant.mjs +113 -0
  116. package/dist/presets-BTeYbw7h.d.mts +57 -0
  117. package/dist/presets-CeFtfDR8.mjs +119 -0
  118. package/dist/prisma-C3iornoK.d.mts +274 -0
  119. package/dist/prisma-DJbMt3yf.mjs +627 -0
  120. package/dist/queryCachePlugin-B6R0d4av.mjs +138 -0
  121. package/dist/queryCachePlugin-Q6SYuHZ6.d.mts +71 -0
  122. package/dist/redis-UwjEp8Ea.d.mts +49 -0
  123. package/dist/redis-stream-CBg0upHI.d.mts +103 -0
  124. package/dist/registry/index.d.mts +11 -0
  125. package/dist/registry/index.mjs +4 -0
  126. package/dist/requestContext-xi6OKBL-.mjs +55 -0
  127. package/dist/schemaConverter-Dtg0Kt9T.mjs +98 -0
  128. package/dist/schemas/index.d.mts +63 -0
  129. package/dist/schemas/index.mjs +82 -0
  130. package/dist/scope/index.d.mts +21 -0
  131. package/dist/scope/index.mjs +65 -0
  132. package/dist/sessionManager-D_iEHjQl.d.mts +186 -0
  133. package/dist/sse-DkqQ1uxb.mjs +123 -0
  134. package/dist/testing/index.d.mts +907 -0
  135. package/dist/testing/index.mjs +1976 -0
  136. package/dist/tracing-8CEbhF0w.d.mts +70 -0
  137. package/dist/typeGuards-DwxA1t_L.mjs +9 -0
  138. package/dist/types/index.d.mts +946 -0
  139. package/dist/types/index.mjs +14 -0
  140. package/dist/types-B0dhNrnd.d.mts +445 -0
  141. package/dist/types-Beqn1Un7.mjs +38 -0
  142. package/dist/types-DelU6kln.mjs +25 -0
  143. package/dist/types-RLkFVgaw.d.mts +101 -0
  144. package/dist/utils/index.d.mts +747 -0
  145. package/dist/utils/index.mjs +6 -0
  146. package/package.json +194 -68
  147. package/dist/BaseController-DVAiHxEQ.d.ts +0 -233
  148. package/dist/adapters/index.d.ts +0 -237
  149. package/dist/adapters/index.js +0 -668
  150. package/dist/arcCorePlugin-CsShQdyP.d.ts +0 -273
  151. package/dist/audit/index.d.ts +0 -195
  152. package/dist/audit/index.js +0 -319
  153. package/dist/auth/index.d.ts +0 -47
  154. package/dist/auth/index.js +0 -174
  155. package/dist/cli/commands/docs.d.ts +0 -11
  156. package/dist/cli/commands/docs.js +0 -474
  157. package/dist/cli/commands/generate.js +0 -334
  158. package/dist/cli/commands/introspect.d.ts +0 -8
  159. package/dist/cli/commands/introspect.js +0 -338
  160. package/dist/cli/index.d.ts +0 -4
  161. package/dist/cli/index.js +0 -3269
  162. package/dist/core/index.d.ts +0 -220
  163. package/dist/core/index.js +0 -2786
  164. package/dist/createApp-Ce9wl8W9.d.ts +0 -77
  165. package/dist/docs/index.d.ts +0 -166
  166. package/dist/docs/index.js +0 -658
  167. package/dist/errors-8WIxGS_6.d.ts +0 -122
  168. package/dist/events/index.d.ts +0 -117
  169. package/dist/events/index.js +0 -89
  170. package/dist/factory/index.d.ts +0 -38
  171. package/dist/factory/index.js +0 -1652
  172. package/dist/hooks/index.d.ts +0 -4
  173. package/dist/hooks/index.js +0 -199
  174. package/dist/idempotency/index.d.ts +0 -323
  175. package/dist/idempotency/index.js +0 -500
  176. package/dist/index-B4t03KQ0.d.ts +0 -1366
  177. package/dist/index.d.ts +0 -135
  178. package/dist/index.js +0 -4756
  179. package/dist/migrations/index.d.ts +0 -185
  180. package/dist/migrations/index.js +0 -274
  181. package/dist/org/index.d.ts +0 -129
  182. package/dist/org/index.js +0 -220
  183. package/dist/permissions/index.d.ts +0 -144
  184. package/dist/permissions/index.js +0 -103
  185. package/dist/plugins/index.d.ts +0 -46
  186. package/dist/plugins/index.js +0 -1069
  187. package/dist/policies/index.js +0 -196
  188. package/dist/presets/index.js +0 -384
  189. package/dist/presets/multiTenant.d.ts +0 -39
  190. package/dist/presets/multiTenant.js +0 -112
  191. package/dist/registry/index.d.ts +0 -16
  192. package/dist/registry/index.js +0 -253
  193. package/dist/testing/index.d.ts +0 -618
  194. package/dist/testing/index.js +0 -48020
  195. package/dist/types/index.d.ts +0 -4
  196. package/dist/types/index.js +0 -8
  197. package/dist/types-B99TBmFV.d.ts +0 -76
  198. package/dist/types-BvckRbs2.d.ts +0 -143
  199. package/dist/utils/index.d.ts +0 -679
  200. package/dist/utils/index.js +0 -931
@@ -1,474 +0,0 @@
1
- import fp from 'fastify-plugin';
2
- import { writeFileSync } from 'fs';
3
- import { join } from 'path';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
-
15
- // src/registry/ResourceRegistry.ts
16
- var ResourceRegistry, registryKey, globalScope, resourceRegistry;
17
- var init_ResourceRegistry = __esm({
18
- "src/registry/ResourceRegistry.ts"() {
19
- ResourceRegistry = class {
20
- _resources;
21
- _frozen;
22
- constructor() {
23
- this._resources = /* @__PURE__ */ new Map();
24
- this._frozen = false;
25
- }
26
- /**
27
- * Register a resource
28
- */
29
- register(resource, options = {}) {
30
- if (this._frozen) {
31
- throw new Error(
32
- `Registry frozen. Cannot register '${resource.name}' after startup.`
33
- );
34
- }
35
- if (this._resources.has(resource.name)) {
36
- throw new Error(`Resource '${resource.name}' already registered.`);
37
- }
38
- const entry = {
39
- name: resource.name,
40
- displayName: resource.displayName,
41
- tag: resource.tag,
42
- prefix: resource.prefix,
43
- module: options.module ?? void 0,
44
- adapter: resource.adapter ? {
45
- type: resource.adapter.type,
46
- name: resource.adapter.name
47
- } : null,
48
- permissions: resource.permissions,
49
- presets: resource._appliedPresets ?? [],
50
- routes: [],
51
- // Populated later by getIntrospection()
52
- additionalRoutes: resource.additionalRoutes.map((r) => ({
53
- method: r.method,
54
- path: r.path,
55
- handler: typeof r.handler === "string" ? r.handler : r.handler.name || "anonymous",
56
- summary: r.summary,
57
- description: r.description,
58
- permissions: r.permissions,
59
- wrapHandler: r.wrapHandler,
60
- schema: r.schema
61
- // Include schema for OpenAPI docs
62
- })),
63
- events: Object.keys(resource.events ?? {}),
64
- registeredAt: (/* @__PURE__ */ new Date()).toISOString(),
65
- disableDefaultRoutes: resource.disableDefaultRoutes,
66
- openApiSchemas: options.openApiSchemas,
67
- plugin: resource.toPlugin()
68
- // Store plugin factory
69
- };
70
- this._resources.set(resource.name, entry);
71
- return this;
72
- }
73
- /**
74
- * Get resource by name
75
- */
76
- get(name) {
77
- return this._resources.get(name);
78
- }
79
- /**
80
- * Get all resources
81
- */
82
- getAll() {
83
- return Array.from(this._resources.values());
84
- }
85
- /**
86
- * Get resources by module
87
- */
88
- getByModule(moduleName) {
89
- return this.getAll().filter((r) => r.module === moduleName);
90
- }
91
- /**
92
- * Get resources by preset
93
- */
94
- getByPreset(presetName) {
95
- return this.getAll().filter((r) => r.presets.includes(presetName));
96
- }
97
- /**
98
- * Check if resource exists
99
- */
100
- has(name) {
101
- return this._resources.has(name);
102
- }
103
- /**
104
- * Get registry statistics
105
- */
106
- getStats() {
107
- const resources = this.getAll();
108
- const presetCounts = {};
109
- for (const r of resources) {
110
- for (const preset of r.presets) {
111
- presetCounts[preset] = (presetCounts[preset] ?? 0) + 1;
112
- }
113
- }
114
- return {
115
- totalResources: resources.length,
116
- byModule: this._groupBy(resources, "module"),
117
- presetUsage: presetCounts,
118
- totalRoutes: resources.reduce((sum, r) => {
119
- const defaultRouteCount = r.disableDefaultRoutes ? 0 : 5;
120
- return sum + (r.additionalRoutes?.length ?? 0) + defaultRouteCount;
121
- }, 0),
122
- totalEvents: resources.reduce((sum, r) => sum + (r.events?.length ?? 0), 0)
123
- };
124
- }
125
- /**
126
- * Get full introspection data
127
- */
128
- getIntrospection() {
129
- return {
130
- resources: this.getAll().map((r) => {
131
- const defaultRoutes = r.disableDefaultRoutes ? [] : [
132
- { method: "GET", path: r.prefix, operation: "list" },
133
- { method: "GET", path: `${r.prefix}/:id`, operation: "get" },
134
- { method: "POST", path: r.prefix, operation: "create" },
135
- { method: "PATCH", path: `${r.prefix}/:id`, operation: "update" },
136
- { method: "DELETE", path: `${r.prefix}/:id`, operation: "delete" }
137
- ];
138
- return {
139
- name: r.name,
140
- displayName: r.displayName,
141
- prefix: r.prefix,
142
- module: r.module,
143
- presets: r.presets,
144
- permissions: r.permissions,
145
- routes: [
146
- ...defaultRoutes,
147
- ...r.additionalRoutes?.map((ar) => ({
148
- method: ar.method,
149
- path: `${r.prefix}${ar.path}`,
150
- operation: typeof ar.handler === "string" ? ar.handler : "custom",
151
- handler: typeof ar.handler === "string" ? ar.handler : void 0,
152
- summary: ar.summary
153
- })) ?? []
154
- ],
155
- events: r.events
156
- };
157
- }),
158
- stats: this.getStats(),
159
- generatedAt: (/* @__PURE__ */ new Date()).toISOString()
160
- };
161
- }
162
- /**
163
- * Freeze registry (prevent further registrations)
164
- */
165
- freeze() {
166
- this._frozen = true;
167
- }
168
- /**
169
- * Check if frozen
170
- */
171
- isFrozen() {
172
- return this._frozen;
173
- }
174
- /**
175
- * Unfreeze registry (for testing)
176
- */
177
- _unfreeze() {
178
- this._frozen = false;
179
- }
180
- /**
181
- * Clear all resources (for testing)
182
- */
183
- _clear() {
184
- this._resources.clear();
185
- this._frozen = false;
186
- }
187
- /**
188
- * Group by key
189
- */
190
- _groupBy(arr, key) {
191
- const result = {};
192
- for (const item of arr) {
193
- const k = String(item[key] ?? "uncategorized");
194
- result[k] = (result[k] ?? 0) + 1;
195
- }
196
- return result;
197
- }
198
- };
199
- registryKey = /* @__PURE__ */ Symbol.for("arc.resourceRegistry");
200
- globalScope = globalThis;
201
- resourceRegistry = globalScope[registryKey] ?? new ResourceRegistry();
202
- if (!globalScope[registryKey]) {
203
- globalScope[registryKey] = resourceRegistry;
204
- }
205
- }
206
- });
207
- var introspectionPlugin, introspectionPlugin_default;
208
- var init_introspectionPlugin = __esm({
209
- "src/registry/introspectionPlugin.ts"() {
210
- init_ResourceRegistry();
211
- introspectionPlugin = async (fastify, opts = {}) => {
212
- const {
213
- prefix = "/_resources",
214
- authRoles = ["superadmin"],
215
- enabled = process.env.NODE_ENV !== "production" || process.env.ENABLE_INTROSPECTION === "true"
216
- } = opts;
217
- if (!enabled) {
218
- fastify.log?.info?.("Introspection plugin disabled");
219
- return;
220
- }
221
- const typedFastify = fastify;
222
- const authMiddleware = authRoles.length > 0 && typedFastify.authenticate ? [
223
- typedFastify.authenticate,
224
- typedFastify.authorize?.(...authRoles)
225
- ].filter(Boolean) : [];
226
- await fastify.register(async (instance) => {
227
- instance.get(
228
- "/",
229
- {
230
- preHandler: authMiddleware
231
- },
232
- async (_req, _reply) => {
233
- return resourceRegistry.getIntrospection();
234
- }
235
- );
236
- instance.get(
237
- "/stats",
238
- {
239
- preHandler: authMiddleware
240
- },
241
- async (_req, _reply) => {
242
- return resourceRegistry.getStats();
243
- }
244
- );
245
- instance.get(
246
- "/:name",
247
- {
248
- schema: {
249
- params: {
250
- type: "object",
251
- properties: {
252
- name: { type: "string" }
253
- },
254
- required: ["name"]
255
- }
256
- },
257
- preHandler: authMiddleware
258
- },
259
- async (req, reply) => {
260
- const resource = resourceRegistry.get(req.params.name);
261
- if (!resource) {
262
- return reply.code(404).send({
263
- error: `Resource '${req.params.name}' not found`
264
- });
265
- }
266
- return resource;
267
- }
268
- );
269
- }, { prefix });
270
- fastify.log?.info?.(`Introspection API at ${prefix}`);
271
- };
272
- introspectionPlugin_default = fp(introspectionPlugin, { name: "arc-introspection" });
273
- }
274
- });
275
-
276
- // src/registry/index.ts
277
- var registry_exports = {};
278
- __export(registry_exports, {
279
- ResourceRegistry: () => ResourceRegistry,
280
- introspectionPlugin: () => introspectionPlugin_default,
281
- introspectionPluginFn: () => introspectionPlugin,
282
- resourceRegistry: () => resourceRegistry
283
- });
284
- var init_registry = __esm({
285
- "src/registry/index.ts"() {
286
- init_ResourceRegistry();
287
- init_introspectionPlugin();
288
- }
289
- });
290
- async function exportDocs(args) {
291
- const [outputPath = "./openapi.json"] = args;
292
- console.log("Exporting OpenAPI specification...\n");
293
- try {
294
- const { resourceRegistry: resourceRegistry2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
295
- const resources = resourceRegistry2.getAll();
296
- if (resources.length === 0) {
297
- console.warn("⚠️ No resources registered.");
298
- console.log("\nTo export docs, you need to load your resources first:");
299
- console.log(" arc docs ./openapi.json --entry ./index.js");
300
- console.log("\nWhere index.js imports all your resource definitions.");
301
- process.exit(1);
302
- }
303
- const spec = {
304
- openapi: "3.0.0",
305
- info: {
306
- title: "Arc API",
307
- version: "1.0.0",
308
- description: "Auto-generated from Arc resources"
309
- },
310
- servers: [
311
- {
312
- url: "http://localhost:8040/api/v1",
313
- description: "Development server"
314
- }
315
- ],
316
- paths: {},
317
- components: {
318
- schemas: {},
319
- securitySchemes: {
320
- bearerAuth: {
321
- type: "http",
322
- scheme: "bearer",
323
- bearerFormat: "JWT"
324
- }
325
- }
326
- }
327
- };
328
- resources.forEach((resource) => {
329
- const basePath = resource.prefix || `/${resource.name}s`;
330
- spec.paths[basePath] = {
331
- get: {
332
- tags: [resource.name],
333
- summary: `List ${resource.name}s`,
334
- security: resource.permissions?.list ? [{ bearerAuth: [] }] : [],
335
- parameters: [
336
- {
337
- name: "page",
338
- in: "query",
339
- schema: { type: "integer", default: 1 }
340
- },
341
- {
342
- name: "limit",
343
- in: "query",
344
- schema: { type: "integer", default: 20 }
345
- }
346
- ],
347
- responses: {
348
- 200: {
349
- description: "Successful response",
350
- content: {
351
- "application/json": {
352
- schema: {
353
- type: "object",
354
- properties: {
355
- success: { type: "boolean" },
356
- data: {
357
- type: "array",
358
- items: { $ref: `#/components/schemas/${resource.name}` }
359
- },
360
- total: { type: "integer" },
361
- page: { type: "integer" }
362
- }
363
- }
364
- }
365
- }
366
- }
367
- }
368
- },
369
- post: {
370
- tags: [resource.name],
371
- summary: `Create ${resource.name}`,
372
- security: resource.permissions?.create ? [{ bearerAuth: [] }] : [],
373
- requestBody: {
374
- required: true,
375
- content: {
376
- "application/json": {
377
- schema: { $ref: `#/components/schemas/${resource.name}` }
378
- }
379
- }
380
- },
381
- responses: {
382
- 201: {
383
- description: "Created successfully"
384
- }
385
- }
386
- }
387
- };
388
- spec.paths[`${basePath}/{id}`] = {
389
- get: {
390
- tags: [resource.name],
391
- summary: `Get ${resource.name} by ID`,
392
- security: resource.permissions?.get ? [{ bearerAuth: [] }] : [],
393
- parameters: [
394
- {
395
- name: "id",
396
- in: "path",
397
- required: true,
398
- schema: { type: "string" }
399
- }
400
- ],
401
- responses: {
402
- 200: {
403
- description: "Successful response"
404
- }
405
- }
406
- },
407
- patch: {
408
- tags: [resource.name],
409
- summary: `Update ${resource.name}`,
410
- security: resource.permissions?.update ? [{ bearerAuth: [] }] : [],
411
- parameters: [
412
- {
413
- name: "id",
414
- in: "path",
415
- required: true,
416
- schema: { type: "string" }
417
- }
418
- ],
419
- requestBody: {
420
- required: true,
421
- content: {
422
- "application/json": {
423
- schema: { $ref: `#/components/schemas/${resource.name}` }
424
- }
425
- }
426
- },
427
- responses: {
428
- 200: {
429
- description: "Updated successfully"
430
- }
431
- }
432
- },
433
- delete: {
434
- tags: [resource.name],
435
- summary: `Delete ${resource.name}`,
436
- security: resource.permissions?.delete ? [{ bearerAuth: [] }] : [],
437
- parameters: [
438
- {
439
- name: "id",
440
- in: "path",
441
- required: true,
442
- schema: { type: "string" }
443
- }
444
- ],
445
- responses: {
446
- 200: {
447
- description: "Deleted successfully"
448
- }
449
- }
450
- }
451
- };
452
- spec.components.schemas[resource.name] = {
453
- type: "object",
454
- properties: {
455
- _id: { type: "string" },
456
- createdAt: { type: "string", format: "date-time" },
457
- updatedAt: { type: "string", format: "date-time" }
458
- }
459
- };
460
- });
461
- const fullPath = join(process.cwd(), outputPath);
462
- writeFileSync(fullPath, JSON.stringify(spec, null, 2));
463
- console.log(`✅ OpenAPI spec exported to: ${fullPath}`);
464
- console.log(`
465
- Resources included: ${resources.length}`);
466
- console.log(`Total endpoints: ${Object.keys(spec.paths).length}`);
467
- } catch (error) {
468
- console.error("Error:", error.message);
469
- process.exit(1);
470
- }
471
- }
472
- var docs_default = { exportDocs };
473
-
474
- export { docs_default as default, exportDocs };