@scalar/oas-utils 0.2.43 → 0.2.44

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 (188) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/diff/diff.d.ts +13 -0
  3. package/dist/diff/diff.d.ts.map +1 -0
  4. package/dist/diff/index.d.ts +1 -0
  5. package/dist/diff/index.d.ts.map +1 -0
  6. package/dist/diff/index.js +1 -0
  7. package/dist/entities/{workspace/cookie → cookie}/cookie.d.ts +1 -17
  8. package/dist/entities/cookie/cookie.d.ts.map +1 -0
  9. package/dist/entities/{workspace/cookie → cookie}/cookie.js +1 -4
  10. package/dist/entities/cookie/index.d.ts.map +1 -0
  11. package/dist/entities/cookie/index.js +1 -0
  12. package/dist/entities/environment/environment.d.ts +24 -0
  13. package/dist/entities/environment/environment.d.ts.map +1 -0
  14. package/dist/entities/environment/environment.js +12 -0
  15. package/dist/entities/environment/index.d.ts.map +1 -0
  16. package/dist/entities/environment/index.js +1 -0
  17. package/dist/entities/{workspace/consts/hot-keys.d.ts → hotkeys/hotkeys.d.ts} +2 -2
  18. package/dist/entities/hotkeys/hotkeys.d.ts.map +1 -0
  19. package/dist/entities/{workspace/consts/hot-keys.js → hotkeys/hotkeys.js} +1 -0
  20. package/dist/entities/hotkeys/index.d.ts +2 -0
  21. package/dist/entities/hotkeys/index.d.ts.map +1 -0
  22. package/dist/entities/hotkeys/index.js +1 -0
  23. package/dist/entities/index.d.ts +1 -1
  24. package/dist/entities/index.d.ts.map +1 -1
  25. package/dist/entities/index.js +1 -1
  26. package/dist/entities/shared/index.d.ts.map +1 -0
  27. package/dist/entities/shared/utility.d.ts.map +1 -0
  28. package/dist/entities/spec/collection.d.ts +489 -0
  29. package/dist/entities/spec/collection.d.ts.map +1 -0
  30. package/dist/entities/spec/collection.js +63 -0
  31. package/dist/entities/spec/index.d.ts +10 -0
  32. package/dist/entities/spec/index.d.ts.map +1 -0
  33. package/dist/entities/spec/index.js +7 -0
  34. package/dist/entities/spec/parameters.d.ts +42 -0
  35. package/dist/entities/spec/parameters.d.ts.map +1 -0
  36. package/dist/entities/spec/parameters.js +30 -0
  37. package/dist/entities/spec/request-examples.d.ts +915 -0
  38. package/dist/entities/spec/request-examples.d.ts.map +1 -0
  39. package/dist/entities/spec/request-examples.js +168 -0
  40. package/dist/entities/spec/requests.d.ts +317 -0
  41. package/dist/entities/spec/requests.d.ts.map +1 -0
  42. package/dist/entities/{workspace/spec → spec}/requests.js +56 -32
  43. package/dist/entities/spec/security.d.ts +964 -0
  44. package/dist/entities/spec/security.d.ts.map +1 -0
  45. package/dist/entities/spec/security.js +222 -0
  46. package/dist/entities/spec/server.d.ts +82 -0
  47. package/dist/entities/spec/server.d.ts.map +1 -0
  48. package/dist/entities/{workspace/server → spec}/server.js +11 -13
  49. package/dist/entities/spec/spec-objects.d.ts +279 -0
  50. package/dist/entities/spec/spec-objects.d.ts.map +1 -0
  51. package/dist/entities/{workspace/collection/collection.js → spec/spec-objects.js} +21 -45
  52. package/dist/entities/workspace/index.js +1 -1
  53. package/dist/entities/workspace/workspace.d.ts +24 -43
  54. package/dist/entities/workspace/workspace.d.ts.map +1 -1
  55. package/dist/entities/workspace/workspace.js +6 -7
  56. package/dist/helpers/httpMethods.d.ts +16 -82
  57. package/dist/helpers/httpMethods.d.ts.map +1 -1
  58. package/dist/helpers/httpMethods.js +45 -41
  59. package/dist/helpers/index.d.ts +2 -0
  60. package/dist/helpers/index.d.ts.map +1 -1
  61. package/dist/helpers/index.js +4 -2
  62. package/dist/helpers/local-storage.d.ts +16 -0
  63. package/dist/helpers/local-storage.d.ts.map +1 -0
  64. package/dist/helpers/local-storage.js +17 -0
  65. package/dist/helpers/redirectToProxy.d.ts +2 -0
  66. package/dist/helpers/redirectToProxy.d.ts.map +1 -1
  67. package/dist/helpers/redirectToProxy.js +6 -7
  68. package/dist/helpers/regexHelpers.d.ts +2 -0
  69. package/dist/helpers/regexHelpers.d.ts.map +1 -0
  70. package/dist/helpers/regexHelpers.js +3 -0
  71. package/dist/helpers/schema-model.d.ts +2 -2
  72. package/dist/helpers/schema-model.d.ts.map +1 -1
  73. package/dist/helpers/schema-model.js +11 -17
  74. package/dist/migrations/data-version.d.ts +12 -0
  75. package/dist/migrations/data-version.d.ts.map +1 -0
  76. package/dist/migrations/data-version.js +13 -0
  77. package/dist/migrations/generate-types.d.ts +2 -0
  78. package/dist/migrations/generate-types.d.ts.map +1 -0
  79. package/dist/migrations/index.d.ts +4 -0
  80. package/dist/migrations/index.d.ts.map +1 -0
  81. package/dist/migrations/index.js +3 -0
  82. package/dist/migrations/local-storage.d.ts +8 -0
  83. package/dist/migrations/local-storage.d.ts.map +1 -0
  84. package/dist/migrations/local-storage.js +36 -0
  85. package/dist/migrations/migrator.d.ts +4 -0
  86. package/dist/migrations/migrator.d.ts.map +1 -0
  87. package/dist/migrations/migrator.js +40 -0
  88. package/dist/migrations/semver.d.ts +5 -0
  89. package/dist/migrations/semver.d.ts.map +1 -0
  90. package/dist/migrations/semver.js +25 -0
  91. package/dist/migrations/v-0.0.0/index.d.ts +2 -0
  92. package/dist/migrations/v-0.0.0/index.d.ts.map +1 -0
  93. package/dist/migrations/v-0.0.0/index.js +1 -0
  94. package/dist/migrations/v-0.0.0/types.generated.d.ts +347 -0
  95. package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -0
  96. package/dist/migrations/v-2.1.0/index.d.ts +3 -0
  97. package/dist/migrations/v-2.1.0/index.d.ts.map +1 -0
  98. package/dist/migrations/v-2.1.0/index.js +1 -0
  99. package/dist/migrations/v-2.1.0/migration.d.ts +334 -0
  100. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -0
  101. package/dist/migrations/v-2.1.0/migration.js +249 -0
  102. package/dist/migrations/v-2.1.0/types.generated.d.ts +42 -0
  103. package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -0
  104. package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
  105. package/dist/spec-getters/getExampleFromSchema.js +21 -8
  106. package/dist/spec-getters/getParametersFromOperation.d.ts +1 -1
  107. package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
  108. package/dist/spec-getters/getParametersFromOperation.js +8 -7
  109. package/dist/spec-getters/getRequestBodyFromOperation.d.ts +12 -40
  110. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  111. package/dist/spec-getters/getRequestBodyFromOperation.js +34 -23
  112. package/dist/spec-getters/getRequestFromOperation.d.ts.map +1 -1
  113. package/dist/spec-getters/getRequestFromOperation.js +1 -2
  114. package/dist/spec-getters/getServerVariableExamples.d.ts +4 -0
  115. package/dist/spec-getters/getServerVariableExamples.d.ts.map +1 -0
  116. package/dist/spec-getters/getServerVariableExamples.js +12 -0
  117. package/dist/spec-getters/index.d.ts +1 -0
  118. package/dist/spec-getters/index.d.ts.map +1 -1
  119. package/dist/spec-getters/index.js +1 -0
  120. package/dist/transforms/export-spec.d.ts +68 -0
  121. package/dist/transforms/export-spec.d.ts.map +1 -0
  122. package/dist/transforms/import-spec.d.ts +20 -68
  123. package/dist/transforms/import-spec.d.ts.map +1 -1
  124. package/dist/transforms/import-spec.js +209 -126
  125. package/package.json +42 -36
  126. package/dist/entities/workspace/collection/collection.d.ts +0 -330
  127. package/dist/entities/workspace/collection/collection.d.ts.map +0 -1
  128. package/dist/entities/workspace/collection/index.d.ts +0 -2
  129. package/dist/entities/workspace/collection/index.d.ts.map +0 -1
  130. package/dist/entities/workspace/collection/index.js +0 -1
  131. package/dist/entities/workspace/consts/hot-keys.d.ts.map +0 -1
  132. package/dist/entities/workspace/consts/index.d.ts +0 -2
  133. package/dist/entities/workspace/consts/index.d.ts.map +0 -1
  134. package/dist/entities/workspace/consts/index.js +0 -1
  135. package/dist/entities/workspace/cookie/cookie.d.ts.map +0 -1
  136. package/dist/entities/workspace/cookie/index.d.ts.map +0 -1
  137. package/dist/entities/workspace/cookie/index.js +0 -1
  138. package/dist/entities/workspace/environment/environment.d.ts +0 -55
  139. package/dist/entities/workspace/environment/environment.d.ts.map +0 -1
  140. package/dist/entities/workspace/environment/environment.js +0 -23
  141. package/dist/entities/workspace/environment/index.d.ts.map +0 -1
  142. package/dist/entities/workspace/environment/index.js +0 -1
  143. package/dist/entities/workspace/folder/folder.d.ts +0 -36
  144. package/dist/entities/workspace/folder/folder.d.ts.map +0 -1
  145. package/dist/entities/workspace/folder/folder.js +0 -21
  146. package/dist/entities/workspace/folder/index.d.ts +0 -2
  147. package/dist/entities/workspace/folder/index.d.ts.map +0 -1
  148. package/dist/entities/workspace/folder/index.js +0 -1
  149. package/dist/entities/workspace/security/index.d.ts +0 -3
  150. package/dist/entities/workspace/security/index.d.ts.map +0 -1
  151. package/dist/entities/workspace/security/index.js +0 -2
  152. package/dist/entities/workspace/security/security-requirement.d.ts +0 -13
  153. package/dist/entities/workspace/security/security-requirement.d.ts.map +0 -1
  154. package/dist/entities/workspace/security/security-requirement.js +0 -15
  155. package/dist/entities/workspace/security/security-schemes.d.ts +0 -696
  156. package/dist/entities/workspace/security/security-schemes.d.ts.map +0 -1
  157. package/dist/entities/workspace/security/security-schemes.js +0 -139
  158. package/dist/entities/workspace/server/index.d.ts +0 -2
  159. package/dist/entities/workspace/server/index.d.ts.map +0 -1
  160. package/dist/entities/workspace/server/index.js +0 -1
  161. package/dist/entities/workspace/server/server.d.ts +0 -91
  162. package/dist/entities/workspace/server/server.d.ts.map +0 -1
  163. package/dist/entities/workspace/shared/index.d.ts.map +0 -1
  164. package/dist/entities/workspace/shared/utility.d.ts.map +0 -1
  165. package/dist/entities/workspace/spec/components.d.ts +0 -3
  166. package/dist/entities/workspace/spec/components.d.ts.map +0 -1
  167. package/dist/entities/workspace/spec/index.d.ts +0 -5
  168. package/dist/entities/workspace/spec/index.d.ts.map +0 -1
  169. package/dist/entities/workspace/spec/index.js +0 -2
  170. package/dist/entities/workspace/spec/parameters.d.ts +0 -16
  171. package/dist/entities/workspace/spec/parameters.d.ts.map +0 -1
  172. package/dist/entities/workspace/spec/refs.d.ts +0 -30
  173. package/dist/entities/workspace/spec/refs.d.ts.map +0 -1
  174. package/dist/entities/workspace/spec/refs.js +0 -9
  175. package/dist/entities/workspace/spec/request-examples.d.ts +0 -1573
  176. package/dist/entities/workspace/spec/request-examples.d.ts.map +0 -1
  177. package/dist/entities/workspace/spec/request-examples.js +0 -96
  178. package/dist/entities/workspace/spec/requests.d.ts +0 -181
  179. package/dist/entities/workspace/spec/requests.d.ts.map +0 -1
  180. package/dist/entities/workspace/spec/spec.d.ts +0 -18
  181. package/dist/entities/workspace/spec/spec.d.ts.map +0 -1
  182. package/dist/entities/workspace/spec/spec.js +0 -8
  183. /package/dist/entities/{workspace/cookie → cookie}/index.d.ts +0 -0
  184. /package/dist/entities/{workspace/environment → environment}/index.d.ts +0 -0
  185. /package/dist/entities/{workspace/shared → shared}/index.d.ts +0 -0
  186. /package/dist/entities/{workspace/shared → shared}/index.js +0 -0
  187. /package/dist/entities/{workspace/shared → shared}/utility.d.ts +0 -0
  188. /package/dist/entities/{workspace/shared → shared}/utility.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC,eAAO,MAAM,8BAA8B;;;;;;IAMzC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUlF,CAAA;AAEF,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,8BAA8B,CACtC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,uEAQ7B,CAAA;AAEV,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;YAhCnC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDlF,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEzE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;gBAvD/B,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAlF,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAlF,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAlF,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAlF,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuElF,CAAA;AAEF,qDAAqD;AACrD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AACjE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAKxE,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;;EAoB1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CAiFhB"}
@@ -0,0 +1,168 @@
1
+ import { z } from 'zod';
2
+ import { getRequestBodyFromOperation } from '../../spec-getters/getRequestBodyFromOperation.js';
3
+ import { getServerVariableExamples } from '../../spec-getters/getServerVariableExamples.js';
4
+ import { nanoidSchema } from '../shared/utility.js';
5
+
6
+ const requestExampleParametersSchema = z.object({
7
+ key: z.string().default(''),
8
+ value: z.coerce.string().default(''),
9
+ enabled: z.boolean().default(true),
10
+ file: z.any().optional(),
11
+ description: z.string().optional(),
12
+ /** Params are linked to parents such as path params and global headers/cookies */
13
+ refUid: nanoidSchema.optional(),
14
+ required: z.boolean().optional(),
15
+ enum: z.array(z.string()).optional(),
16
+ type: z.string().optional(),
17
+ format: z.string().optional(),
18
+ minimum: z.number().optional(),
19
+ maximum: z.number().optional(),
20
+ default: z.any().optional(),
21
+ nullable: z.boolean().optional(),
22
+ });
23
+ /**
24
+ * Possible encodings for example request bodies when using text formats
25
+ *
26
+ * TODO: This list may not be comprehensive enough
27
+ */
28
+ const exampleRequestBodyEncoding = [
29
+ 'json',
30
+ 'text',
31
+ 'html',
32
+ 'javascript',
33
+ 'xml',
34
+ 'yaml',
35
+ 'edn',
36
+ ];
37
+ const exampleRequestBodySchema = z.object({
38
+ raw: z
39
+ .object({
40
+ encoding: z.enum(exampleRequestBodyEncoding).default('json'),
41
+ value: z.string().default(''),
42
+ })
43
+ .optional(),
44
+ formData: z
45
+ .object({
46
+ encoding: z
47
+ .union([z.literal('form-data'), z.literal('urlencoded')])
48
+ .default('form-data'),
49
+ value: requestExampleParametersSchema.array().default([]),
50
+ })
51
+ .optional(),
52
+ binary: z.instanceof(Blob).optional(),
53
+ activeBody: z
54
+ .union([z.literal('raw'), z.literal('formData'), z.literal('binary')])
55
+ .default('raw'),
56
+ });
57
+ const requestExampleSchema = z.object({
58
+ type: z.literal('requestExample').optional().default('requestExample'),
59
+ uid: nanoidSchema,
60
+ requestUid: nanoidSchema,
61
+ name: z.string().optional().default('Name'),
62
+ body: exampleRequestBodySchema.optional().default({}),
63
+ parameters: z
64
+ .object({
65
+ path: requestExampleParametersSchema.array().default([]),
66
+ query: requestExampleParametersSchema.array().default([]),
67
+ headers: requestExampleParametersSchema.array().default([]),
68
+ cookies: requestExampleParametersSchema.array().default([]),
69
+ })
70
+ .optional()
71
+ .default({}),
72
+ serverVariables: z.record(z.string(), z.array(z.string())).optional(),
73
+ });
74
+ // ---------------------------------------------------------------------------
75
+ // Example Helpers
76
+ /** Create new instance parameter from a request parameter */
77
+ function createParamInstance(param) {
78
+ const schema = param.schema;
79
+ /**
80
+ * TODO:
81
+ * - Need better value defaulting here
82
+ * - Need to handle non-string parameters much better
83
+ * - Need to handle unions/array values for schema
84
+ */
85
+ const value = String(schema?.default ?? schema?.examples?.[0] ?? '');
86
+ return requestExampleParametersSchema.parse({
87
+ ...schema,
88
+ key: param.name,
89
+ value,
90
+ description: param.description,
91
+ required: param.required,
92
+ /** Initialized all required properties to enabled */
93
+ enabled: !!param.required,
94
+ });
95
+ }
96
+ /**
97
+ * Create new request example from a request
98
+ * Iterates the name of the example if provided
99
+ */
100
+ function createExampleFromRequest(request, name, server) {
101
+ // ---------------------------------------------------------------------------
102
+ // Populate all parameters with an example value
103
+ const parameters = {
104
+ path: [],
105
+ query: [],
106
+ cookie: [],
107
+ header: [],
108
+ };
109
+ // Populated the separated params
110
+ request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)));
111
+ // ---------------------------------------------------------------------------
112
+ // Handle request body defaulting for various content type encodings
113
+ const body = {
114
+ activeBody: 'raw',
115
+ raw: {
116
+ encoding: 'json',
117
+ value: '',
118
+ },
119
+ };
120
+ if (request.requestBody) {
121
+ const requestBody = getRequestBodyFromOperation({
122
+ path: request.path,
123
+ information: {
124
+ requestBody: request.requestBody,
125
+ },
126
+ });
127
+ if (requestBody?.body?.mimeType === 'application/json') {
128
+ body.activeBody = 'raw';
129
+ body.raw = {
130
+ encoding: 'json',
131
+ value: requestBody.body.text ?? JSON.stringify({}),
132
+ };
133
+ }
134
+ if (requestBody?.body?.mimeType === 'application/xml') {
135
+ body.activeBody = 'raw';
136
+ body.raw = {
137
+ encoding: 'xml',
138
+ value: requestBody.body.text ?? '',
139
+ };
140
+ }
141
+ /**
142
+ * TODO: Are we loading example files from somewhere based on the spec?
143
+ * How are we handling the body values
144
+ */
145
+ if (requestBody?.body?.mimeType === 'application/octet-stream') {
146
+ body.activeBody = 'binary';
147
+ body.binary = undefined;
148
+ }
149
+ /**
150
+ * TODO: How are handling form data examples from the spec
151
+ */
152
+ if (requestBody?.body?.mimeType === 'application/x-www-form-urlencoded') {
153
+ body.activeBody = 'formData';
154
+ body.formData = undefined;
155
+ }
156
+ }
157
+ const serverVariables = server ? getServerVariableExamples(server) : {};
158
+ const example = requestExampleSchema.parse({
159
+ requestUid: request.uid,
160
+ parameters,
161
+ name,
162
+ body,
163
+ serverVariables,
164
+ });
165
+ return example;
166
+ }
167
+
168
+ export { createExampleFromRequest, createParamInstance, exampleRequestBodyEncoding, exampleRequestBodySchema, requestExampleParametersSchema, requestExampleSchema };
@@ -0,0 +1,317 @@
1
+ import { z } from 'zod';
2
+ import type { RequestExample } from './request-examples.js';
3
+ export declare const requestMethods: readonly ["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"];
4
+ export type RequestMethod = (typeof requestMethods)[number];
5
+ /** A single set of populated values for a sent request */
6
+ export type ResponseInstance<ResponseDataType = unknown> = Omit<Response, 'headers'> & {
7
+ /** Store headers as an object to match what we had with axios */
8
+ headers: Record<string, string>;
9
+ /** Keys of headers which set cookies */
10
+ cookieHeaderKeys: string[];
11
+ /** Time in ms the request took */
12
+ duration: number;
13
+ /** The response data */
14
+ data: ResponseDataType;
15
+ /** The response status */
16
+ status: number;
17
+ /** The response method */
18
+ method: RequestMethod;
19
+ /** The request path */
20
+ path: string;
21
+ };
22
+ /** A single request/response set to save to the history stack */
23
+ export type RequestEvent = {
24
+ request: RequestExample;
25
+ response: ResponseInstance;
26
+ timestamp: number;
27
+ };
28
+ /** Open API Compliant Request Validator */
29
+ export declare const oasRequestSchema: z.ZodObject<{
30
+ /**
31
+ * A list of tags for API documentation control. Tags can be used for logical
32
+ * grouping of operations by resources or any other qualifier.
33
+ *
34
+ * These tags are the openapi spec tag names, not uids
35
+ */
36
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
37
+ /** A short summary of what the operation does. */
38
+ summary: z.ZodOptional<z.ZodString>;
39
+ /** A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. */
40
+ description: z.ZodOptional<z.ZodString>;
41
+ /**
42
+ * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.
43
+ * The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an
44
+ * operation, therefore, it is RECOMMENDED to follow bin common programming naming conventions./
45
+ */
46
+ operationId: z.ZodOptional<z.ZodString>;
47
+ /**
48
+ * A declaration of which security mechanisms can be used across the API. The list of
49
+ * values includes alternative security requirement objects that can be used. Only
50
+ * one of the security requirement objects need to be satisfied to authorize a request.
51
+ * Individual operations can override this definition. To make security optional, an empty
52
+ * security requirement ({}) can be included in the array.
53
+ */
54
+ security: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>>, "many">>;
55
+ /**
56
+ * The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the
57
+ * HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the
58
+ * HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined
59
+ * semantics and SHOULD be avoided if possible.
60
+ */
61
+ requestBody: z.ZodOptional<z.ZodAny>;
62
+ /**
63
+ * Request parameters
64
+ */
65
+ parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
66
+ in: z.ZodEnum<["path", "query", "header", "cookie"]>;
67
+ name: z.ZodString;
68
+ description: z.ZodOptional<z.ZodString>;
69
+ required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
70
+ deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
71
+ schema: z.ZodOptional<z.ZodUnknown>;
72
+ content: z.ZodOptional<z.ZodUnknown>;
73
+ style: z.ZodOptional<z.ZodEnum<["matrix", "simple", "form", "label", "spaceDelimited", "pipeDelimited", "deepObject"]>>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ required: boolean;
76
+ name: string;
77
+ in: "path" | "query" | "header" | "cookie";
78
+ deprecated: boolean;
79
+ description?: string | undefined;
80
+ schema?: unknown;
81
+ content?: unknown;
82
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
83
+ }, {
84
+ name: string;
85
+ in: "path" | "query" | "header" | "cookie";
86
+ required?: boolean | undefined;
87
+ description?: string | undefined;
88
+ deprecated?: boolean | undefined;
89
+ schema?: unknown;
90
+ content?: unknown;
91
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
92
+ }>, "many">>;
93
+ /**
94
+ * External documentation object
95
+ */
96
+ externalDocs: z.ZodOptional<z.ZodObject<{
97
+ description: z.ZodOptional<z.ZodString>;
98
+ url: z.ZodDefault<z.ZodString>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ url: string;
101
+ description?: string | undefined;
102
+ }, {
103
+ description?: string | undefined;
104
+ url?: string | undefined;
105
+ }>>;
106
+ deprecated: z.ZodOptional<z.ZodBoolean>;
107
+ /** Response formats */
108
+ responses: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ description?: string | undefined;
111
+ summary?: string | undefined;
112
+ externalDocs?: {
113
+ url: string;
114
+ description?: string | undefined;
115
+ } | undefined;
116
+ security?: Record<string, string[]>[] | undefined;
117
+ tags?: string[] | undefined;
118
+ deprecated?: boolean | undefined;
119
+ operationId?: string | undefined;
120
+ parameters?: {
121
+ required: boolean;
122
+ name: string;
123
+ in: "path" | "query" | "header" | "cookie";
124
+ deprecated: boolean;
125
+ description?: string | undefined;
126
+ schema?: unknown;
127
+ content?: unknown;
128
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
129
+ }[] | undefined;
130
+ requestBody?: any;
131
+ responses?: Record<string, any> | undefined;
132
+ }, {
133
+ description?: string | undefined;
134
+ summary?: string | undefined;
135
+ externalDocs?: {
136
+ description?: string | undefined;
137
+ url?: string | undefined;
138
+ } | undefined;
139
+ security?: Record<string, string[] | undefined>[] | undefined;
140
+ tags?: string[] | undefined;
141
+ deprecated?: boolean | undefined;
142
+ operationId?: string | undefined;
143
+ parameters?: {
144
+ name: string;
145
+ in: "path" | "query" | "header" | "cookie";
146
+ required?: boolean | undefined;
147
+ description?: string | undefined;
148
+ deprecated?: boolean | undefined;
149
+ schema?: unknown;
150
+ content?: unknown;
151
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
152
+ }[] | undefined;
153
+ requestBody?: any;
154
+ responses?: Record<string, any> | undefined;
155
+ }>;
156
+ /** Unified request schema for client usage */
157
+ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<{
158
+ /**
159
+ * A list of tags for API documentation control. Tags can be used for logical
160
+ * grouping of operations by resources or any other qualifier.
161
+ *
162
+ * These tags are the openapi spec tag names, not uids
163
+ */
164
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
165
+ /** A short summary of what the operation does. */
166
+ summary: z.ZodOptional<z.ZodString>;
167
+ /** A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. */
168
+ description: z.ZodOptional<z.ZodString>;
169
+ /**
170
+ * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.
171
+ * The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an
172
+ * operation, therefore, it is RECOMMENDED to follow bin common programming naming conventions./
173
+ */
174
+ operationId: z.ZodOptional<z.ZodString>;
175
+ /**
176
+ * A declaration of which security mechanisms can be used across the API. The list of
177
+ * values includes alternative security requirement objects that can be used. Only
178
+ * one of the security requirement objects need to be satisfied to authorize a request.
179
+ * Individual operations can override this definition. To make security optional, an empty
180
+ * security requirement ({}) can be included in the array.
181
+ */
182
+ security: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>>, "many">>;
183
+ /**
184
+ * The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the
185
+ * HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the
186
+ * HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined
187
+ * semantics and SHOULD be avoided if possible.
188
+ */
189
+ requestBody: z.ZodOptional<z.ZodAny>;
190
+ /**
191
+ * Request parameters
192
+ */
193
+ parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
194
+ in: z.ZodEnum<["path", "query", "header", "cookie"]>;
195
+ name: z.ZodString;
196
+ description: z.ZodOptional<z.ZodString>;
197
+ required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
198
+ deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
199
+ schema: z.ZodOptional<z.ZodUnknown>;
200
+ content: z.ZodOptional<z.ZodUnknown>;
201
+ style: z.ZodOptional<z.ZodEnum<["matrix", "simple", "form", "label", "spaceDelimited", "pipeDelimited", "deepObject"]>>;
202
+ }, "strip", z.ZodTypeAny, {
203
+ required: boolean;
204
+ name: string;
205
+ in: "path" | "query" | "header" | "cookie";
206
+ deprecated: boolean;
207
+ description?: string | undefined;
208
+ schema?: unknown;
209
+ content?: unknown;
210
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
211
+ }, {
212
+ name: string;
213
+ in: "path" | "query" | "header" | "cookie";
214
+ required?: boolean | undefined;
215
+ description?: string | undefined;
216
+ deprecated?: boolean | undefined;
217
+ schema?: unknown;
218
+ content?: unknown;
219
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
220
+ }>, "many">>;
221
+ /**
222
+ * External documentation object
223
+ */
224
+ externalDocs: z.ZodOptional<z.ZodObject<{
225
+ description: z.ZodOptional<z.ZodString>;
226
+ url: z.ZodDefault<z.ZodString>;
227
+ }, "strip", z.ZodTypeAny, {
228
+ url: string;
229
+ description?: string | undefined;
230
+ }, {
231
+ description?: string | undefined;
232
+ url?: string | undefined;
233
+ }>>;
234
+ deprecated: z.ZodOptional<z.ZodBoolean>;
235
+ /** Response formats */
236
+ responses: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
237
+ }, {
238
+ type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"request">>>;
239
+ uid: z.ZodDefault<z.ZodOptional<z.ZodString>>;
240
+ /** Path Key */
241
+ path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
242
+ /** Request Method */
243
+ method: z.ZodDefault<z.ZodEnum<["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"]>>;
244
+ /** List of server UIDs specific to the request */
245
+ servers: z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodOptional<z.ZodString>>, "many">>;
246
+ /** The currently selected server */
247
+ selectedServerUid: z.ZodDefault<z.ZodString>;
248
+ /** List of example UIDs associated with the request */
249
+ examples: z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodOptional<z.ZodString>>, "many">>;
250
+ /** List of security scheme UIDs associated with the request */
251
+ selectedSecuritySchemeUids: z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodOptional<z.ZodString>>, "many">>;
252
+ }>, "strip", z.ZodTypeAny, {
253
+ path: string;
254
+ type: "request";
255
+ uid: string;
256
+ selectedServerUid: string;
257
+ servers: string[];
258
+ examples: string[];
259
+ method: "options" | "delete" | "get" | "connect" | "head" | "patch" | "post" | "put" | "trace";
260
+ selectedSecuritySchemeUids: string[];
261
+ description?: string | undefined;
262
+ summary?: string | undefined;
263
+ externalDocs?: {
264
+ url: string;
265
+ description?: string | undefined;
266
+ } | undefined;
267
+ security?: Record<string, string[]>[] | undefined;
268
+ tags?: string[] | undefined;
269
+ deprecated?: boolean | undefined;
270
+ operationId?: string | undefined;
271
+ parameters?: {
272
+ required: boolean;
273
+ name: string;
274
+ in: "path" | "query" | "header" | "cookie";
275
+ deprecated: boolean;
276
+ description?: string | undefined;
277
+ schema?: unknown;
278
+ content?: unknown;
279
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
280
+ }[] | undefined;
281
+ requestBody?: any;
282
+ responses?: Record<string, any> | undefined;
283
+ }, {
284
+ path?: string | undefined;
285
+ type?: "request" | undefined;
286
+ uid?: string | undefined;
287
+ description?: string | undefined;
288
+ summary?: string | undefined;
289
+ externalDocs?: {
290
+ description?: string | undefined;
291
+ url?: string | undefined;
292
+ } | undefined;
293
+ security?: Record<string, string[] | undefined>[] | undefined;
294
+ selectedServerUid?: string | undefined;
295
+ servers?: (string | undefined)[] | undefined;
296
+ tags?: string[] | undefined;
297
+ deprecated?: boolean | undefined;
298
+ examples?: (string | undefined)[] | undefined;
299
+ operationId?: string | undefined;
300
+ method?: "options" | "delete" | "get" | "connect" | "head" | "patch" | "post" | "put" | "trace" | undefined;
301
+ parameters?: {
302
+ name: string;
303
+ in: "path" | "query" | "header" | "cookie";
304
+ required?: boolean | undefined;
305
+ description?: string | undefined;
306
+ deprecated?: boolean | undefined;
307
+ schema?: unknown;
308
+ content?: unknown;
309
+ style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
310
+ }[] | undefined;
311
+ requestBody?: any;
312
+ responses?: Record<string, any> | undefined;
313
+ selectedSecuritySchemeUids?: (string | undefined)[] | undefined;
314
+ }>;
315
+ export type Request = z.infer<typeof requestSchema>;
316
+ export type RequestPayload = z.input<typeof requestSchema>;
317
+ //# sourceMappingURL=requests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAIxD,eAAO,MAAM,cAAc,2FAUjB,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3D,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,CAAC,gBAAgB,GAAG,OAAO,IAAI,IAAI,CAC7D,QAAQ,EACR,SAAS,CACV,GAAG;IACF,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,wBAAwB;IACxB,IAAI,EAAE,gBAAgB,CAAA;IACtB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,0BAA0B;IAC1B,MAAM,EAAE,aAAa,CAAA;IACrB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,cAAc,CAAA;IACvB,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAMD,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB;IAC3B;;;;;OAKG;;IAEH,kDAAkD;;IAElD,mHAAmH;;IAEnH;;;;OAIG;;IAEH;;;;;;OAMG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;OAEG;;;;;;;;;;;;IAGH,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE0B,CAAA;AA0BnD,8CAA8C;AAC9C,eAAO,MAAM,aAAa;IAtExB;;;;;OAKG;;IAEH,kDAAkD;;IAElD,mHAAmH;;IAEnH;;;;OAIG;;IAEH;;;;;;OAMG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;OAEG;;;;;;;;;;;;IAGH,uBAAuB;;;;;IAcvB,eAAe;;IAEf,qBAAqB;;IAErB,kDAAkD;;IAElD,oCAAoC;;IAEpC,uDAAuD;;IAEvD,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKS,CAAA;AAC1E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA"}
@@ -1,23 +1,28 @@
1
- import { deepMerge } from '@scalar/object-utils/merge';
2
1
  import { z } from 'zod';
3
- import { $refSchema } from './refs.js';
4
- import { REQUEST_METHODS } from '../../../helpers/httpMethods.js';
2
+ import { oasParameterSchema } from './parameters.js';
3
+ import { oasSecurityRequirementSchema } from './security.js';
4
+ import { oasExternalDocumentationSchema } from './spec-objects.js';
5
5
  import { nanoidSchema } from '../shared/utility.js';
6
- import { securityRequirement } from '../security/security-requirement.js';
7
6
 
7
+ const requestMethods = [
8
+ 'connect',
9
+ 'delete',
10
+ 'get',
11
+ 'head',
12
+ 'options',
13
+ 'patch',
14
+ 'post',
15
+ 'put',
16
+ 'trace',
17
+ ];
8
18
  const requestBodySchema = z.any();
9
- const parametersSchema = z.record(z.string(), z.any());
10
- const requestSchema = z.object({
11
- path: z.string().optional().default(''),
12
- method: z
13
- .enum(Object.keys(REQUEST_METHODS))
14
- .optional()
15
- .default('GET'),
16
- uid: nanoidSchema,
17
- ref: $refSchema.nullable().default(null),
19
+ /** Open API Compliant Request Validator */
20
+ const oasRequestSchema = z.object({
18
21
  /**
19
22
  * A list of tags for API documentation control. Tags can be used for logical
20
23
  * grouping of operations by resources or any other qualifier.
24
+ *
25
+ * These tags are the openapi spec tag names, not uids
21
26
  */
22
27
  tags: z.string().array().optional(),
23
28
  /** A short summary of what the operation does. */
@@ -30,14 +35,6 @@ const requestSchema = z.object({
30
35
  * operation, therefore, it is RECOMMENDED to follow bin common programming naming conventions./
31
36
  */
32
37
  operationId: z.string().optional(),
33
- parameters: z
34
- .object({
35
- path: parametersSchema,
36
- query: parametersSchema,
37
- headers: parametersSchema,
38
- cookies: parametersSchema,
39
- })
40
- .default({ path: {}, query: {}, headers: {}, cookies: {} }),
41
38
  /**
42
39
  * A declaration of which security mechanisms can be used across the API. The list of
43
40
  * values includes alternative security requirement objects that can be used. Only
@@ -45,11 +42,7 @@ const requestSchema = z.object({
45
42
  * Individual operations can override this definition. To make security optional, an empty
46
43
  * security requirement ({}) can be included in the array.
47
44
  */
48
- security: z.array(securityRequirement).optional(),
49
- /** Security schemes which have been created specifically for this request */
50
- securitySchemeUids: z.array(nanoidSchema).optional().default([]),
51
- /** The currently selected security schemes at the request level */
52
- selectedSecuritySchemeUids: z.array(nanoidSchema).default([]),
45
+ security: z.array(oasSecurityRequirementSchema).optional(),
53
46
  /**
54
47
  * The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the
55
48
  * HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the
@@ -57,11 +50,42 @@ const requestSchema = z.object({
57
50
  * semantics and SHOULD be avoided if possible.
58
51
  */
59
52
  requestBody: requestBodySchema.optional(),
60
- /** Ordered exampleUids for the sidenav */
61
- childUids: nanoidSchema.array().default([]),
62
- history: z.any().array().default([]),
53
+ /**
54
+ * Request parameters
55
+ */
56
+ parameters: oasParameterSchema.array().optional(),
57
+ /**
58
+ * External documentation object
59
+ */
60
+ externalDocs: oasExternalDocumentationSchema.optional(),
61
+ deprecated: z.boolean().optional(),
62
+ /** Response formats */
63
+ responses: z.record(z.string(), z.any()).optional(),
64
+ });
65
+ /**
66
+ * Extended properties added to the spec definition for client usage
67
+ *
68
+ * WARNING: DO NOT ADD PROPERTIES THAT SHARE A NAME WITH OAS OPERATION ENTITIES
69
+ *
70
+ * This object is directly converted to a spec operation during saving
71
+ */
72
+ const extendedRequestSchema = z.object({
73
+ type: z.literal('request').optional().default('request'),
74
+ uid: nanoidSchema,
75
+ /** Path Key */
76
+ path: z.string().optional().default(''),
77
+ /** Request Method */
78
+ method: z.enum(requestMethods).default('get'),
79
+ /** List of server UIDs specific to the request */
80
+ servers: nanoidSchema.array().default([]),
81
+ /** The currently selected server */
82
+ selectedServerUid: z.string().default(''),
83
+ /** List of example UIDs associated with the request */
84
+ examples: nanoidSchema.array().default([]),
85
+ /** List of security scheme UIDs associated with the request */
86
+ selectedSecuritySchemeUids: nanoidSchema.array().default([]),
63
87
  });
64
- /** Create request helper */
65
- const createRequest = (payload) => deepMerge(requestSchema.parse({}), payload);
88
+ /** Unified request schema for client usage */
89
+ const requestSchema = oasRequestSchema.merge(extendedRequestSchema);
66
90
 
67
- export { createRequest };
91
+ export { oasRequestSchema, requestMethods, requestSchema };