@scalar/workspace-store 0.5.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @scalar/workspace-store
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b97c82a: feat(workspace-store): server store input document from different sources
8
+ - 9f786d5: feat(workspace-store): preserve the original ref information
9
+
10
+ ### Patch Changes
11
+
12
+ - @scalar/code-highlight@0.1.4
13
+ - @scalar/openapi-parser@0.18.0
14
+
15
+ ## 0.5.2
16
+
17
+ ### Patch Changes
18
+
19
+ - 1703e42: fix(workspace-store): relative paths for ssg mode
20
+
21
+ ## 0.5.1
22
+
23
+ ### Patch Changes
24
+
25
+ - a567796: fix: make the workspace store reactive again
26
+ - Updated dependencies [291f09d]
27
+ - @scalar/openapi-parser@0.18.0
28
+
3
29
  ## 0.5.0
4
30
 
5
31
  ### Minor 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,21 @@ 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'])
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)
199
240
  ```