@scalar/workspace-store 0.5.2 → 0.7.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 (93) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +94 -7
  3. package/dist/client.d.ts +11713 -11143
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +27 -2
  6. package/dist/client.js.map +2 -2
  7. package/dist/helpers/json-path-utils.d.ts +1 -1
  8. package/dist/helpers/json-path-utils.d.ts.map +1 -1
  9. package/dist/helpers/json-path-utils.js.map +2 -2
  10. package/dist/helpers/merge-object.d.ts +23 -0
  11. package/dist/helpers/merge-object.d.ts.map +1 -0
  12. package/dist/helpers/merge-object.js +20 -0
  13. package/dist/helpers/merge-object.js.map +7 -0
  14. package/dist/helpers/proxy.d.ts.map +1 -1
  15. package/dist/helpers/proxy.js +5 -2
  16. package/dist/helpers/proxy.js.map +2 -2
  17. package/dist/schemas/reference-config/appearance.d.ts +13 -0
  18. package/dist/schemas/reference-config/appearance.d.ts.map +1 -0
  19. package/dist/schemas/reference-config/appearance.js +26 -0
  20. package/dist/schemas/reference-config/appearance.js.map +7 -0
  21. package/dist/schemas/reference-config/features.d.ts +15 -0
  22. package/dist/schemas/reference-config/features.d.ts.map +1 -0
  23. package/dist/schemas/reference-config/features.js +30 -0
  24. package/dist/schemas/reference-config/features.js.map +7 -0
  25. package/dist/schemas/reference-config/index.d.ts +53 -0
  26. package/dist/schemas/reference-config/index.d.ts.map +1 -0
  27. package/dist/schemas/reference-config/index.js +66 -0
  28. package/dist/schemas/reference-config/index.js.map +7 -0
  29. package/dist/schemas/reference-config/meta.d.ts +12 -0
  30. package/dist/schemas/reference-config/meta.d.ts.map +1 -0
  31. package/dist/schemas/reference-config/meta.js +24 -0
  32. package/dist/schemas/reference-config/meta.js.map +7 -0
  33. package/dist/schemas/reference-config/routing.d.ts +8 -0
  34. package/dist/schemas/reference-config/routing.d.ts.map +1 -0
  35. package/dist/schemas/reference-config/routing.js +16 -0
  36. package/dist/schemas/reference-config/routing.js.map +7 -0
  37. package/dist/schemas/reference-config/settings.d.ts +8 -0
  38. package/dist/schemas/reference-config/settings.d.ts.map +1 -0
  39. package/dist/schemas/reference-config/settings.js +16 -0
  40. package/dist/schemas/reference-config/settings.js.map +7 -0
  41. package/dist/schemas/v3.1/strict/components.d.ts +167 -40
  42. package/dist/schemas/v3.1/strict/components.d.ts.map +1 -1
  43. package/dist/schemas/v3.1/strict/header.d.ts +2 -0
  44. package/dist/schemas/v3.1/strict/header.d.ts.map +1 -1
  45. package/dist/schemas/v3.1/strict/media-header-encoding.d.ts +6 -0
  46. package/dist/schemas/v3.1/strict/media-header-encoding.d.ts.map +1 -1
  47. package/dist/schemas/v3.1/strict/media-type.d.ts +1 -0
  48. package/dist/schemas/v3.1/strict/media-type.d.ts.map +1 -1
  49. package/dist/schemas/v3.1/strict/oauth-flow.d.ts +73 -2
  50. package/dist/schemas/v3.1/strict/oauth-flow.d.ts.map +1 -1
  51. package/dist/schemas/v3.1/strict/oauth-flow.js +44 -7
  52. package/dist/schemas/v3.1/strict/oauth-flow.js.map +2 -2
  53. package/dist/schemas/v3.1/strict/oauthflows.d.ts +11 -10
  54. package/dist/schemas/v3.1/strict/oauthflows.d.ts.map +1 -1
  55. package/dist/schemas/v3.1/strict/oauthflows.js +11 -8
  56. package/dist/schemas/v3.1/strict/oauthflows.js.map +2 -2
  57. package/dist/schemas/v3.1/strict/operation.d.ts +11 -2
  58. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  59. package/dist/schemas/v3.1/strict/parameter.d.ts +11 -5
  60. package/dist/schemas/v3.1/strict/parameter.d.ts.map +1 -1
  61. package/dist/schemas/v3.1/strict/parameter.js +1 -1
  62. package/dist/schemas/v3.1/strict/parameter.js.map +2 -2
  63. package/dist/schemas/v3.1/strict/path-item.d.ts +5 -2
  64. package/dist/schemas/v3.1/strict/path-item.d.ts.map +1 -1
  65. package/dist/schemas/v3.1/strict/path-operations.d.ts +158 -32
  66. package/dist/schemas/v3.1/strict/path-operations.d.ts.map +1 -1
  67. package/dist/schemas/v3.1/strict/paths.d.ts +71 -14
  68. package/dist/schemas/v3.1/strict/paths.d.ts.map +1 -1
  69. package/dist/schemas/v3.1/strict/request-body.d.ts +2 -0
  70. package/dist/schemas/v3.1/strict/request-body.d.ts.map +1 -1
  71. package/dist/schemas/v3.1/strict/response.d.ts +4 -0
  72. package/dist/schemas/v3.1/strict/response.d.ts.map +1 -1
  73. package/dist/schemas/v3.1/strict/responses.d.ts +4 -0
  74. package/dist/schemas/v3.1/strict/responses.d.ts.map +1 -1
  75. package/dist/schemas/v3.1/strict/schema.d.ts +6 -1
  76. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  77. package/dist/schemas/v3.1/strict/schema.js +7 -2
  78. package/dist/schemas/v3.1/strict/schema.js.map +2 -2
  79. package/dist/schemas/v3.1/strict/security-scheme.d.ts +22 -20
  80. package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
  81. package/dist/schemas/v3.1/type-guard.d.ts +5 -0
  82. package/dist/schemas/v3.1/type-guard.d.ts.map +1 -1
  83. package/dist/schemas/v3.1/type-guard.js +1 -3
  84. package/dist/schemas/v3.1/type-guard.js.map +2 -2
  85. package/dist/server.d.ts +687 -651
  86. package/dist/server.d.ts.map +1 -1
  87. package/dist/server.js +52 -49
  88. package/dist/server.js.map +2 -2
  89. package/dist/types.d.ts +57 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +1 -0
  92. package/dist/types.js.map +7 -0
  93. package/package.json +19 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @scalar/workspace-store
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a05d638: feat(workspace-store): create types and validator for reference config schema
8
+ - 8d8e427: feat(api-reference): load documents on the new store
9
+ - dbbdd70: feat(workspace-store) add configuration mapping to the workspace store
10
+
11
+ ### Patch Changes
12
+
13
+ - 23b150b: fix: export and fix up some types from workspace store
14
+ - Updated dependencies [533469b]
15
+ - Updated dependencies [23b150b]
16
+ - @scalar/openapi-types@0.3.4
17
+ - @scalar/helpers@0.0.5
18
+ - @scalar/openapi-parser@0.18.0
19
+ - @scalar/types@0.2.5
20
+ - @scalar/code-highlight@0.1.4
21
+
22
+ ## 0.6.0
23
+
24
+ ### Minor Changes
25
+
26
+ - b97c82a: feat(workspace-store): server store input document from different sources
27
+ - 9f786d5: feat(workspace-store): preserve the original ref information
28
+
29
+ ### Patch Changes
30
+
31
+ - @scalar/code-highlight@0.1.4
32
+ - @scalar/openapi-parser@0.18.0
33
+
3
34
  ## 0.5.2
4
35
 
5
36
  ### Patch Changes
package/README.md CHANGED
@@ -11,7 +11,7 @@ Create a new store in SSR mode
11
11
 
12
12
  ```ts
13
13
  // Create the store
14
- const store = createServerWorkspaceStore({
14
+ const store = await createServerWorkspaceStore({
15
15
  baseUrl: 'example.com',
16
16
  mode: 'ssr',
17
17
  meta: { 'x-scalar-active-document': 'document-name' },
@@ -44,7 +44,7 @@ const store = createServerWorkspaceStore({
44
44
  })
45
45
 
46
46
  // Add a new document to the store
47
- store.addDocument({
47
+ await store.addDocument({
48
48
  openapi: '3.1.1',
49
49
  info: {
50
50
  title: 'Hello World',
@@ -82,7 +82,7 @@ Create a new store in static mode
82
82
 
83
83
  ```ts
84
84
  // Create the store
85
- const store = createServerWorkspaceStore({
85
+ const store = await createServerWorkspaceStore({
86
86
  directory: 'assets',
87
87
  mode: 'static',
88
88
  meta: { 'x-scalar-active-document': 'document-name' },
@@ -115,7 +115,7 @@ const store = createServerWorkspaceStore({
115
115
  })
116
116
 
117
117
  // Add a new document to the store
118
- store.addDocument({
118
+ await store.addDocument({
119
119
  openapi: '3.1.1',
120
120
  info: {
121
121
  title: 'Hello World',
@@ -145,6 +145,30 @@ store.addDocument({
145
145
  const workspace = await store.generateWorkspaceChunks()
146
146
  ```
147
147
 
148
+ ### Load documents from external sources
149
+ ```ts
150
+ // Initialize the store with documents from external sources
151
+ const store = await createServerWorkspaceStore({
152
+ mode: 'static',
153
+ documents: [
154
+ {
155
+ name: 'remoteFile',
156
+ url: 'http://localhost/document.json'
157
+ },
158
+ {
159
+ name: 'fsFile',
160
+ path: './document.json'
161
+ }
162
+ ]
163
+ })
164
+
165
+ // Output: { openapi: 'x.x.x', ... }
166
+ console.log(store.getWorkspace().documents.remoteFile)
167
+
168
+ // Output: { openapi: 'x.x.x', ... }
169
+ console.log(store.getWorkspace().documents.fsFile)
170
+ ```
171
+
148
172
  ## Client-Side Workspace Store
149
173
 
150
174
  A reactive workspace store for managing OpenAPI documents with automatic reference resolution and chunked loading capabilities. Works seamlessly with server-side stores to handle large documents efficiently.
@@ -154,7 +178,7 @@ A reactive workspace store for managing OpenAPI documents with automatic referen
154
178
  ```ts
155
179
 
156
180
  // Initialize a new workspace store with default document
157
- const store = await createWorkspaceStore({
181
+ const store = createWorkspaceStore({
158
182
  documents: [
159
183
  {
160
184
  name: 'default',
@@ -172,7 +196,7 @@ const store = await createWorkspaceStore({
172
196
  })
173
197
 
174
198
  // Add another OpenAPI document to the workspace
175
- store.addDocument({
199
+ store.addDocumentSync({
176
200
  document: {
177
201
  info: {
178
202
  title: 'OpenApi document',
@@ -196,4 +220,67 @@ store.updateDocument('active', "x-scalar-active-auth", '<value>')
196
220
 
197
221
  // Resolve and load document chunks including any $ref references
198
222
  await store.resolve(['paths', '/users', 'get'])
199
- ```
223
+ ```
224
+
225
+ #### Load documents from external sources
226
+
227
+ You can only initialize the store with object literals but if you want to add documents from external sources you can use the addDocument function
228
+
229
+ ```ts
230
+ const store = createWorkspaceStore()
231
+
232
+ // Load a document into the store from a remote url
233
+ await store.addDocument({
234
+ name: 'default',
235
+ url: 'http://localhost/document.json'
236
+ })
237
+
238
+ // Output: { openapi: 'x.x.x', ... }
239
+ console.log(store.workspace.documents.default)
240
+ ```
241
+
242
+ #### Configuration
243
+
244
+ You can pass configuration object to the workspace store which is going to be applied to all the documents
245
+
246
+ ```ts
247
+ const store = createWorkspaceStore({
248
+ config: {
249
+ "x-scalar-reference-config": {
250
+ features: {
251
+ showModels: true,
252
+ },
253
+ appearance: {
254
+ layout: 'modern'
255
+ },
256
+ }
257
+ }
258
+ })
259
+ ```
260
+
261
+ You can override specific document configuration when you add the document to the store
262
+
263
+ ```ts
264
+ store.addDocumentSync({
265
+ name: 'example',
266
+ document: {
267
+ openapi: '3.0.0',
268
+ info: { title: 'Example API', version: '1.0.0' },
269
+ paths: {},
270
+ },
271
+ config: {
272
+ features: {
273
+ showModels: false,
274
+ },
275
+ }
276
+ })
277
+ ```
278
+
279
+ To get the active document configuration you can use config getter\
280
+
281
+ ```ts
282
+ // Get the configuration for the active document
283
+ console.log(store.config['x-scalar-reference-config'].features.showModels)
284
+ ```
285
+
286
+ When no configuration is provided it will return the default configuration