@scalar/cli 2.0.1 → 2.1.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 (80) hide show
  1. package/README.md +40 -0
  2. package/chunks/action-45OGQB2M.js +138 -0
  3. package/chunks/action-5R5FDF6S.js +2097 -0
  4. package/chunks/action-ANU5HGC4.js +34 -0
  5. package/chunks/action-BMFXENMX.js +176 -0
  6. package/chunks/action-BNEGJBUH.js +38 -0
  7. package/chunks/action-BYZUBXVB.js +82 -0
  8. package/chunks/action-C5VB4ITT.js +132 -0
  9. package/chunks/action-CCW66QJN.js +72 -0
  10. package/chunks/action-CLSD7O2R.js +60 -0
  11. package/chunks/action-CQ56FVES.js +65 -0
  12. package/chunks/action-CYP4VDK3.js +148 -0
  13. package/chunks/action-DFKHSDFV.js +36 -0
  14. package/chunks/action-F4Y6Q2VB.js +92 -0
  15. package/chunks/action-GB6DM53B.js +70 -0
  16. package/chunks/action-GEBRPNRT.js +87 -0
  17. package/chunks/action-H5OHT2GV.js +56 -0
  18. package/chunks/action-HD2T6BFJ.js +54 -0
  19. package/chunks/action-HNKM3Q65.js +65 -0
  20. package/chunks/action-JOSVV6YA.js +71 -0
  21. package/chunks/action-MENXFJH3.js +204 -0
  22. package/chunks/action-P7LN6FGY.js +13 -0
  23. package/chunks/action-PVDDRIM6.js +130 -0
  24. package/chunks/action-Q5UJ32D6.js +46 -0
  25. package/chunks/action-R6ZZO26F.js +299 -0
  26. package/chunks/action-STIEAXOE.js +53 -0
  27. package/chunks/action-TPBKPHNS.js +110 -0
  28. package/chunks/action-TWFJNQ2R.js +95 -0
  29. package/chunks/action-TZ5KGAQT.js +64 -0
  30. package/chunks/action-UDZUUJSI.js +49 -0
  31. package/chunks/action-W5BATF4Q.js +197 -0
  32. package/chunks/agent-XGLOHXNA.js +112 -0
  33. package/chunks/build.action-LKOILPA6.js +108 -0
  34. package/chunks/chunk-23I5PKZZ.js +78 -0
  35. package/chunks/chunk-2BSG2QHO.js +455 -0
  36. package/chunks/chunk-3MZYUBJ6.js +49 -0
  37. package/chunks/chunk-47Y4L5IT.js +63361 -0
  38. package/chunks/chunk-4DGQIAJX.js +359 -0
  39. package/chunks/chunk-4QS7SJTG.js +138 -0
  40. package/chunks/chunk-5BISXQX4.js +447 -0
  41. package/chunks/chunk-5BPPGTUU.js +463 -0
  42. package/chunks/chunk-AEFPCC4U.js +16 -0
  43. package/chunks/chunk-AHWWJ3MD.js +32 -0
  44. package/chunks/chunk-ASMHW5AY.js +19 -0
  45. package/chunks/chunk-B6QZJWCQ.js +92 -0
  46. package/chunks/chunk-DOVIWNKQ.js +108 -0
  47. package/chunks/chunk-H2WRMLYY.js +13780 -0
  48. package/chunks/chunk-HQKBZOYU.js +34 -0
  49. package/chunks/chunk-ISGLWBXZ.js +4265 -0
  50. package/chunks/chunk-IX7LJ3AD.js +17 -0
  51. package/chunks/chunk-JFIXNSPP.js +26 -0
  52. package/chunks/chunk-K74E42RV.js +7311 -0
  53. package/chunks/chunk-KHDYYVYF.js +16 -0
  54. package/chunks/chunk-KWOL7A6J.js +23 -0
  55. package/chunks/chunk-NUXPNUSS.js +38 -0
  56. package/chunks/chunk-OAXFCOJV.js +25 -0
  57. package/chunks/chunk-P2VH7DOC.js +107 -0
  58. package/chunks/chunk-P646T2WH.js +1608 -0
  59. package/chunks/chunk-SHSHFGA7.js +297 -0
  60. package/chunks/chunk-SXYALPYK.js +2709 -0
  61. package/chunks/chunk-T7B6WNZC.js +18 -0
  62. package/chunks/chunk-T7MDADON.js +17 -0
  63. package/chunks/chunk-TLFMATXR.js +344 -0
  64. package/chunks/chunk-TQ5XC2E3.js +284 -0
  65. package/chunks/chunk-UPUTMFD4.js +465 -0
  66. package/chunks/chunk-VTYTPSXO.js +161 -0
  67. package/chunks/chunk-X4QLDBB5.js +221 -0
  68. package/chunks/chunk-ZTVWAKNJ.js +21 -0
  69. package/chunks/create.action-FFQLBSJH.js +108 -0
  70. package/chunks/delete.action-QNN3LC2F.js +96 -0
  71. package/chunks/delete.action-STHQHP4F.js +88 -0
  72. package/chunks/get.action-OTKYOP3Z.js +87 -0
  73. package/chunks/list.action-6I5EZAVB.js +95 -0
  74. package/chunks/list.action-KDM5RHEH.js +116 -0
  75. package/chunks/publish.action-PODTVRXS.js +182 -0
  76. package/chunks/update.action-4F6STTEQ.js +101 -0
  77. package/chunks/update.action-KMD4ZM75.js +95 -0
  78. package/docs.html +310 -209
  79. package/index.js +645 -99061
  80. package/package.json +13 -11
@@ -0,0 +1,297 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getAuthData
4
+ } from "./chunk-5BISXQX4.js";
5
+ import {
6
+ config
7
+ } from "./chunk-OAXFCOJV.js";
8
+ import {
9
+ objectSchema,
10
+ schemaModel
11
+ } from "./chunk-ISGLWBXZ.js";
12
+ import {
13
+ external_exports
14
+ } from "./chunk-H2WRMLYY.js";
15
+
16
+ // ../../packages/mongobase-client/dist/auth/tokens.js
17
+ var tokenResponseSchema = external_exports.object({
18
+ accessToken: external_exports.string(),
19
+ refreshToken: external_exports.string()
20
+ });
21
+
22
+ // ../../packages/mongobase-client/dist/auth/utility.js
23
+ var ErrorCode;
24
+ (function(ErrorCode2) {
25
+ ErrorCode2["AuthFail"] = "auth-fail";
26
+ })(ErrorCode || (ErrorCode = {}));
27
+
28
+ // ../../packages/mongobase-client/dist/database/access.js
29
+ var primitiveSchema = external_exports.union([
30
+ external_exports.string(),
31
+ external_exports.number(),
32
+ external_exports.boolean(),
33
+ external_exports.null()
34
+ ]);
35
+ var $filterSchema = external_exports.object({
36
+ $in: external_exports.string().array().optional(),
37
+ $nin: external_exports.string().array().optional(),
38
+ $eq: primitiveSchema.optional(),
39
+ $ne: primitiveSchema.optional(),
40
+ $lt: external_exports.number().optional(),
41
+ $gt: external_exports.number().optional(),
42
+ $gte: external_exports.number().optional(),
43
+ $lte: external_exports.number().optional(),
44
+ $or: external_exports.lazy(() => $filterSchema.array()).optional()
45
+ });
46
+ var querySchema = external_exports.record(external_exports.string(), external_exports.union([primitiveSchema, $filterSchema]));
47
+ var getRecordRequestSchema = external_exports.object({
48
+ collectionPath: external_exports.string(),
49
+ query: querySchema
50
+ });
51
+ var addRecordRequestSchema = external_exports.object({
52
+ collectionPath: external_exports.string(),
53
+ data: objectSchema
54
+ });
55
+ var addMultipleRecordsRequestSchema = external_exports.object({
56
+ collectionPath: external_exports.string(),
57
+ data: objectSchema.array()
58
+ });
59
+ var updateRecordRequestSchema = external_exports.object({
60
+ collectionPath: external_exports.string(),
61
+ data: objectSchema,
62
+ query: querySchema
63
+ });
64
+ var deleteRecordRequestSchema = external_exports.object({
65
+ collectionPath: external_exports.string(),
66
+ query: querySchema
67
+ });
68
+ var dropCollectionRequestSchema = external_exports.object({
69
+ collectionPath: external_exports.string()
70
+ });
71
+ function formatResponse(response, schema) {
72
+ return {
73
+ status: response.status,
74
+ data: schemaModel(response.data, schema),
75
+ error: false
76
+ };
77
+ }
78
+ var statusMessages = {
79
+ 401: "Unauthorized. Please check that an access token was provided to the instance. "
80
+ };
81
+ function formatError(error, message) {
82
+ return {
83
+ status: error.status ?? 500,
84
+ message: statusMessages[error.response?.status] ?? error.message ?? message,
85
+ error: true,
86
+ originalError: error
87
+ };
88
+ }
89
+ var addResponseSchema = external_exports.object({
90
+ insertedId: external_exports.string()
91
+ });
92
+ var addMultiResponseSchema = external_exports.object({
93
+ insertedCount: external_exports.number(),
94
+ insertedIds: external_exports.preprocess((s) => Array.isArray(s) ? s : Object.values(s), external_exports.string().array())
95
+ });
96
+ var updateResponseSchema = external_exports.object({
97
+ matchedCount: external_exports.number(),
98
+ modifiedCount: external_exports.number(),
99
+ upsertedCount: external_exports.number(),
100
+ upsertedId: external_exports.string().nullable()
101
+ });
102
+ var deletedResponseSchema = external_exports.object({
103
+ deletedCount: external_exports.number()
104
+ });
105
+ function createAccess(baseURL) {
106
+ const state = {
107
+ accessToken: ""
108
+ };
109
+ function makeRequest(options) {
110
+ return fetch(`${baseURL}${options.url}`, {
111
+ method: options.method,
112
+ headers: {
113
+ ...options.headers,
114
+ // An empty bearer token is always rejected — omit the header so the
115
+ // server returns a clean 401 instead of parsing a malformed value
116
+ ...state.accessToken ? { Authorization: `Bearer ${state.accessToken}` } : {},
117
+ "Content-Type": "application/json"
118
+ },
119
+ body: JSON.stringify(options.data)
120
+ }).then(async (res) => {
121
+ if (!res.ok) {
122
+ return formatError({ status: res.status, message: await res.text() }, "Unknown Error");
123
+ }
124
+ return formatResponse({ data: await res.json(), status: res.status }, options.schema);
125
+ }).catch((err) => formatError(err));
126
+ }
127
+ function get({ collectionPath, query, schema, type }) {
128
+ const data = schemaModel({ collectionPath, query }, getRecordRequestSchema);
129
+ return makeRequest({
130
+ url: `/database/get-${type}`,
131
+ method: "POST",
132
+ data,
133
+ schema
134
+ });
135
+ }
136
+ function addOne({ collectionPath, data, schema, responseSchema }) {
137
+ const sanitizedData = schemaModel({ collectionPath, data: schemaModel(data, schema) }, addRecordRequestSchema);
138
+ return makeRequest({
139
+ url: "/database/add-one",
140
+ method: "POST",
141
+ data: sanitizedData,
142
+ schema: responseSchema
143
+ });
144
+ }
145
+ function addMultiple({ collectionPath, data, schema, responseSchema }) {
146
+ const sanitizedData = schemaModel({ collectionPath, data: schemaModel(data, schema) }, addMultipleRecordsRequestSchema);
147
+ return makeRequest({
148
+ url: "/database/add-many",
149
+ method: "POST",
150
+ data: sanitizedData,
151
+ schema: responseSchema
152
+ });
153
+ }
154
+ function remove({ collectionPath, query, type }) {
155
+ const data = schemaModel({ collectionPath, query }, deleteRecordRequestSchema);
156
+ return makeRequest({
157
+ url: `/database/delete-${type}`,
158
+ method: "POST",
159
+ data,
160
+ schema: deletedResponseSchema
161
+ });
162
+ }
163
+ function update({ collectionPath, data, query, schema }) {
164
+ const updateData = schemaModel({
165
+ collectionPath,
166
+ query,
167
+ data: schemaModel(data, schema)
168
+ }, updateRecordRequestSchema);
169
+ return makeRequest({
170
+ url: "/database/update-one",
171
+ method: "POST",
172
+ data: updateData,
173
+ schema: updateResponseSchema
174
+ });
175
+ }
176
+ function dropCollection({ collectionPath }) {
177
+ const data = schemaModel({ collectionPath }, dropCollectionRequestSchema);
178
+ return makeRequest({
179
+ url: "/database/drop-collection",
180
+ method: "POST",
181
+ data,
182
+ schema: external_exports.any()
183
+ });
184
+ }
185
+ return {
186
+ /** Update the access token */
187
+ updateAccessToken(accessToken) {
188
+ state.accessToken = accessToken;
189
+ },
190
+ async checkHealth(url) {
191
+ if (!state.accessToken) {
192
+ return {
193
+ status: 511,
194
+ message: "No Access Token",
195
+ error: true,
196
+ originalError: null
197
+ };
198
+ }
199
+ return await makeRequest({
200
+ url,
201
+ method: "GET",
202
+ schema: external_exports.any()
203
+ });
204
+ },
205
+ /** Get a single record */
206
+ getOne(options) {
207
+ return get({ ...options, type: "one" });
208
+ },
209
+ /** Get multiple records */
210
+ getMany(options) {
211
+ return get({ ...options, type: "many" });
212
+ },
213
+ /** Add a single record */
214
+ addOne(options) {
215
+ return addOne({ ...options, responseSchema: addResponseSchema });
216
+ },
217
+ /** Add multiple records */
218
+ addMany(options) {
219
+ return addMultiple({ ...options, responseSchema: addMultiResponseSchema });
220
+ },
221
+ updateOne(options) {
222
+ return update({ ...options });
223
+ },
224
+ /** Delete a single record */
225
+ deleteOne(options) {
226
+ return remove({ ...options, type: "one" });
227
+ },
228
+ /** Delete multiple records */
229
+ deleteMany(options) {
230
+ return remove({ ...options, type: "many" });
231
+ },
232
+ dropCollection
233
+ };
234
+ }
235
+
236
+ // ../../packages/mongobase-client/dist/database/offline.js
237
+ var DiffOp;
238
+ (function(DiffOp2) {
239
+ DiffOp2["Remove"] = "remove";
240
+ DiffOp2["Replace"] = "replace";
241
+ DiffOp2["Add"] = "add";
242
+ })(DiffOp || (DiffOp = {}));
243
+ var diffRecordSchema = external_exports.object({
244
+ op: external_exports.enum(DiffOp),
245
+ path: external_exports.union([external_exports.string(), external_exports.number()]).array(),
246
+ value: external_exports.any()
247
+ });
248
+ var MutationOp;
249
+ (function(MutationOp2) {
250
+ MutationOp2["Add"] = "add";
251
+ MutationOp2["Update"] = "update";
252
+ MutationOp2["Delete"] = "delete";
253
+ })(MutationOp || (MutationOp = {}));
254
+ var collectionChangeRecordSchema = external_exports.record(external_exports.string(), external_exports.object({
255
+ action: external_exports.enum(MutationOp),
256
+ value: external_exports.any()
257
+ }));
258
+ var changelogSchema = external_exports.record(external_exports.string(), collectionChangeRecordSchema);
259
+
260
+ // ../../packages/mongobase-client/dist/database/socket.js
261
+ var SubscriptionTypes;
262
+ (function(SubscriptionTypes2) {
263
+ SubscriptionTypes2["Collection"] = "collection";
264
+ SubscriptionTypes2["Document"] = "document";
265
+ })(SubscriptionTypes || (SubscriptionTypes = {}));
266
+ var MAX_RECONNECT_INTERVAL = 60 * 1e3;
267
+
268
+ // ../../packages/mongobase-client/dist/database/subscribe.js
269
+ var SubscriptionAction;
270
+ (function(SubscriptionAction2) {
271
+ SubscriptionAction2["Add"] = "insert";
272
+ SubscriptionAction2["Update"] = "update";
273
+ SubscriptionAction2["Remove"] = "delete";
274
+ })(SubscriptionAction || (SubscriptionAction = {}));
275
+
276
+ // ../../packages/mongobase-client/dist/database/index.js
277
+ function initDatabase(baseUrl) {
278
+ if (!baseUrl)
279
+ throw new Error("Invalid URL provided to initDatabase");
280
+ return createAccess(baseUrl);
281
+ }
282
+
283
+ // src/helpers/database.ts
284
+ var getDatabaseClient = async () => {
285
+ const client = initDatabase(`${config.services.api}/rtdb`);
286
+ const auth = await getAuthData();
287
+ auth.addEventListener((state) => {
288
+ Object.assign(auth, state);
289
+ client.updateAccessToken(state.accessToken);
290
+ });
291
+ client.updateAccessToken(auth.accessToken);
292
+ return client;
293
+ };
294
+
295
+ export {
296
+ getDatabaseClient
297
+ };