@scalar/cli 2.0.1 → 2.5.1

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 (83) hide show
  1. package/README.md +68 -24
  2. package/chunks/action-37EV4UHW.js +125 -0
  3. package/chunks/action-4XI7XJR4.js +204 -0
  4. package/chunks/action-5IU77OII.js +60 -0
  5. package/chunks/action-B3KKREWQ.js +64 -0
  6. package/chunks/action-CH24QGTE.js +86 -0
  7. package/chunks/action-F3UX5E3M.js +522 -0
  8. package/chunks/action-FDB7NEOK.js +81 -0
  9. package/chunks/action-FIXBOJEW.js +244 -0
  10. package/chunks/action-G26LSVZ7.js +40 -0
  11. package/chunks/action-H3RTILLM.js +46 -0
  12. package/chunks/action-HGBBV353.js +86 -0
  13. package/chunks/action-IUE4IOWO.js +2142 -0
  14. package/chunks/action-JZLZ7ZAD.js +110 -0
  15. package/chunks/action-LA6KVAXQ.js +374 -0
  16. package/chunks/action-M7RQKBSB.js +169 -0
  17. package/chunks/action-MSLBC2SO.js +92 -0
  18. package/chunks/action-NVSZT2ZD.js +37 -0
  19. package/chunks/action-OGQSTRMX.js +37 -0
  20. package/chunks/action-PAGJ5PWC.js +60 -0
  21. package/chunks/action-QE2ZQQX7.js +250 -0
  22. package/chunks/action-QPUSPD5M.js +54 -0
  23. package/chunks/action-R7IMFHQ5.js +147 -0
  24. package/chunks/action-SH4UUXPL.js +60 -0
  25. package/chunks/action-SNLCIBQC.js +84 -0
  26. package/chunks/action-SQG3JAII.js +150 -0
  27. package/chunks/action-UZQJNYK4.js +18 -0
  28. package/chunks/action-VC4DCVST.js +68 -0
  29. package/chunks/action-VTVFY2MP.js +181 -0
  30. package/chunks/action-WFWYGY7O.js +67 -0
  31. package/chunks/action-XMNX5ZYT.js +197 -0
  32. package/chunks/agent-HCQRMHQ5.js +132 -0
  33. package/chunks/asyncapi-QM76O55R.js +105 -0
  34. package/chunks/build.action-P7FCIMYU.js +108 -0
  35. package/chunks/chunk-24WAOKGG.js +105 -0
  36. package/chunks/chunk-3L6DLIXJ.js +25530 -0
  37. package/chunks/chunk-3MZYUBJ6.js +49 -0
  38. package/chunks/chunk-3ZJYGGAA.js +30 -0
  39. package/chunks/chunk-4NHMAG6F.js +21 -0
  40. package/chunks/chunk-4ORL4MST.js +16 -0
  41. package/chunks/chunk-4ZDQXWBT.js +26 -0
  42. package/chunks/chunk-6ZMT63IV.js +19 -0
  43. package/chunks/chunk-7AGLC7WV.js +107 -0
  44. package/chunks/chunk-AEFPCC4U.js +16 -0
  45. package/chunks/chunk-AO3F5XWR.js +3147 -0
  46. package/chunks/chunk-B2MHTD3R.js +90 -0
  47. package/chunks/chunk-CISTON3A.js +153 -0
  48. package/chunks/chunk-COBPBRQF.js +25 -0
  49. package/chunks/chunk-F467BYYR.js +568 -0
  50. package/chunks/chunk-GSGZHE26.js +352 -0
  51. package/chunks/chunk-HCPN3KNF.js +637 -0
  52. package/chunks/chunk-HPL3ZZ2P.js +1726 -0
  53. package/chunks/chunk-IKT5F47M.js +17344 -0
  54. package/chunks/chunk-JFIXNSPP.js +26 -0
  55. package/chunks/chunk-K4DTP5TV.js +32 -0
  56. package/chunks/chunk-K74E42RV.js +7311 -0
  57. package/chunks/chunk-KHDYYVYF.js +16 -0
  58. package/chunks/chunk-LFU5ZUAP.js +350 -0
  59. package/chunks/chunk-M37TP6U2.js +445 -0
  60. package/chunks/chunk-OQKDBLOZ.js +741 -0
  61. package/chunks/chunk-P7H7GY5A.js +14 -0
  62. package/chunks/chunk-PBXZN65A.js +63911 -0
  63. package/chunks/chunk-PT5TI77I.js +34 -0
  64. package/chunks/chunk-Q7DOQHZN.js +404 -0
  65. package/chunks/chunk-T5HJUAWB.js +242 -0
  66. package/chunks/chunk-T7B6WNZC.js +18 -0
  67. package/chunks/chunk-UGGNHILG.js +38 -0
  68. package/chunks/chunk-VNYE4R7N.js +499 -0
  69. package/chunks/chunk-X5T526CE.js +23 -0
  70. package/chunks/chunk-XCSR4RIT.js +210 -0
  71. package/chunks/chunk-Z2KMGFE6.js +295 -0
  72. package/chunks/create.action-HDD2WUON.js +108 -0
  73. package/chunks/delete.action-7GOZY7ID.js +88 -0
  74. package/chunks/delete.action-VE66JFDS.js +96 -0
  75. package/chunks/get.action-2745EB4N.js +86 -0
  76. package/chunks/list.action-3VTXQJRA.js +116 -0
  77. package/chunks/list.action-4QDCZLSZ.js +95 -0
  78. package/chunks/publish.action-ULQLZKWU.js +190 -0
  79. package/chunks/update.action-6QEFP7NA.js +95 -0
  80. package/chunks/update.action-OROQSP2S.js +101 -0
  81. package/docs.html +352 -250
  82. package/index.js +664 -99064
  83. package/package.json +17 -11
@@ -0,0 +1,210 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ RegistryAsset
4
+ } from "./chunk-CISTON3A.js";
5
+ import {
6
+ contentShaSchema
7
+ } from "./chunk-Q7DOQHZN.js";
8
+ import {
9
+ docVersionSchema,
10
+ external_exports,
11
+ namespaceSchema
12
+ } from "./chunk-IKT5F47M.js";
13
+
14
+ // ../../packages/urls/dist/registry/path-generators.js
15
+ function versionFormat(version) {
16
+ if (!version || version === "latest")
17
+ return "latest";
18
+ return docVersionSchema.parse(version);
19
+ }
20
+ function filetypeFormat(filetype) {
21
+ return filetype ? external_exports.enum(["yaml", "json", "zip"]).parse(filetype) : "yaml";
22
+ }
23
+ function registryFormat(format) {
24
+ return external_exports.enum(["yaml", "json", "preview"]).parse(format);
25
+ }
26
+ var pagesSha = (sha) => contentShaSchema.parse(sha);
27
+ var pageChunkFile = (entryId) => {
28
+ const id = external_exports.string().min(1, "Page chunk entry id must not be empty").parse(entryId);
29
+ return `${encodeURIComponent(id)}.json`;
30
+ };
31
+ var MAX_OBJECT_NAME_BYTES = 1024;
32
+ var withinObjectNameLimit = (key, entryId) => {
33
+ const bytes = new TextEncoder().encode(key).length;
34
+ if (bytes > MAX_OBJECT_NAME_BYTES) {
35
+ throw new Error(`Page chunk key is ${bytes} bytes, over the ${MAX_OBJECT_NAME_BYTES}-byte object name limit, for entry id "${entryId}"`);
36
+ }
37
+ return key;
38
+ };
39
+ function buildAsset(namespace, asset, slug) {
40
+ return {
41
+ /**
42
+ * Get registry record path.
43
+ *
44
+ * Registry collection records have a base resource path
45
+ * with the primary registry item metadata: namespace,
46
+ * asset type and slug.
47
+ *
48
+ * @example scalar/apis/scalar-galaxy
49
+ */
50
+ path: () => {
51
+ return `${namespace}/${asset}/${slug}`;
52
+ },
53
+ /**
54
+ * Get registry GCS file storage path
55
+ *
56
+ * Unlike registry record paths, storage paths contain the version
57
+ * of a registry item, and the respective file type.
58
+ *
59
+ * @example scalar/apis/scalar-galaxy/1.0.0.json
60
+ */
61
+ file: (opts) => {
62
+ return `${namespace}/${asset}/${slug}/${opts?.build || versionFormat(opts?.version)}${opts?.upgraded ? "_upgraded" : ""}${opts?.variant === "processed" ? "_processed" : ""}.${filetypeFormat(opts?.type)}`;
63
+ },
64
+ /**
65
+ * Get registry GCS folder storage path
66
+ *
67
+ * @example scalar/apis/scalar-galaxy
68
+ */
69
+ folder: (opts) => {
70
+ return `${namespace}/${asset}/${slug}${opts?.version ? `/${opts.version}` : ""}`;
71
+ },
72
+ /**
73
+ * Content-addressed blob path for an immutable content instance. Blobs are
74
+ * write-once — the sha in the key is the SHA-256 of the exact bytes stored,
75
+ * so identical content dedupes to the same object and nothing at this path
76
+ * is ever overwritten.
77
+ *
78
+ * The optional `variant` keys derived artifacts next to the content they
79
+ * derive from: `_processed` (SDK overlay output) and `_upgraded`
80
+ * (normalized OpenAPI) share the source content's json sha, so a variant
81
+ * object is immutable for the same reason the content blob is.
82
+ *
83
+ * @example scalar/apis/scalar-galaxy/blobs/2f7a...c9.json
84
+ * @example scalar/apis/scalar-galaxy/blobs/2f7a...c9_processed.json
85
+ */
86
+ blob: (opts) => {
87
+ const sha = external_exports.string().regex(/^[a-f0-9]{64}$/, "Blob sha must be a sha-256 hex digest").parse(opts.sha);
88
+ const variant = opts.variant ? `_${opts.variant}` : "";
89
+ return `${namespace}/${asset}/${slug}/blobs/${sha}${variant}.${filetypeFormat(opts.type)}`;
90
+ },
91
+ /**
92
+ * Prefix holding the per-page sidecar derived from one content instance:
93
+ * a manifest, a models bundle and one chunk per navigation entry.
94
+ *
95
+ * Deliberately beside `blobs/`, not inside it. {@link copyBlobsFolder}
96
+ * copies the whole `blobs/` prefix on every resource rename, twice and with
97
+ * unbounded concurrency; a sidecar contributes roughly ten thousand objects
98
+ * per sha, which would turn a rename into tens of thousands of concurrent
99
+ * copies. `pages/` is instead deleted with the resource and regenerated
100
+ * lazily under the new path, where the cost is one rebuild rather than a
101
+ * rename that may not finish.
102
+ *
103
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/
104
+ */
105
+ pagesPrefix: (opts) => {
106
+ return `${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/`;
107
+ },
108
+ /**
109
+ * The sidecar's index: the stripped base document, the navigation tree and
110
+ * the entry table. Written last, so its presence is what marks a sidecar
111
+ * complete.
112
+ *
113
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/manifest.json
114
+ */
115
+ pagesManifest: (opts) => {
116
+ return `${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/manifest.json`;
117
+ },
118
+ /**
119
+ * Every component schema of the sidecar, in one object. Split out of the
120
+ * manifest because the sidebar only needs it once a reader opens Models.
121
+ *
122
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/models.json
123
+ */
124
+ pagesModels: (opts) => {
125
+ return `${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/models.json`;
126
+ },
127
+ /**
128
+ * One navigation entry's chunk — the slice of the document that entry's
129
+ * page renders, merged onto the manifest's stripped base document.
130
+ *
131
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/chunks/tag%2Fplanets%2Fget%2Fplanets.json
132
+ */
133
+ pageChunk: (opts) => {
134
+ return withinObjectNameLimit(`${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/chunks/${pageChunkFile(opts.entryId)}`, opts.entryId);
135
+ },
136
+ /**
137
+ * Claim marker for a sidecar being built. Created with
138
+ * `ifGenerationMatch: 0` so exactly one producer wins across the fleet, and
139
+ * deleted when the job settles.
140
+ *
141
+ * Mutable, unlike everything else under the prefix: it is written, read for
142
+ * its age and removed within one build. See {@link planPagesCacheControl}
143
+ * in `@scalar-org/entities/registry` for what that means for serving.
144
+ *
145
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/preparing.json
146
+ */
147
+ pagesPreparing: (opts) => {
148
+ return `${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/preparing.json`;
149
+ },
150
+ /**
151
+ * Records that building this sha's sidecar failed, so a reader is told so
152
+ * instead of polling a job that will not finish. Cleared by a rebuild, so
153
+ * it is mutable in the same way the claim marker is.
154
+ *
155
+ * @example scalar/apis/scalar-galaxy/pages/2f7a...c9/failed.json
156
+ */
157
+ pagesFailed: (opts) => {
158
+ return `${namespace}/${asset}/${slug}/pages/${pagesSha(opts.sha)}/failed.json`;
159
+ },
160
+ /**
161
+ * Get a full standardized registry url path
162
+ *
163
+ * Our registry resolver understands a few path formats.
164
+ * However, this is our primary registry format to use across
165
+ * internal products.
166
+ *
167
+ * @example @scalar/apis/scalar-galaxy/1.0.0?format=preview
168
+ */
169
+ url: (opts) => {
170
+ const query = [
171
+ opts?.format ? `format=${registryFormat(opts.format)}` : "",
172
+ opts?.variant === "processed" ? "variant=processed" : "",
173
+ opts?.lang ? `lang=${opts.lang}` : ""
174
+ ].filter(Boolean).join("&");
175
+ return `@${namespace}/${asset}/${slug}@${versionFormat(opts?.version)}${query ? `?${query}` : ""}`;
176
+ }
177
+ };
178
+ }
179
+ function registry(teamNamespace) {
180
+ const namespace = namespaceSchema.parse(teamNamespace);
181
+ return {
182
+ apis: (slug) => buildAsset(namespace, RegistryAsset.Apis, slug),
183
+ rules: (slug) => buildAsset(namespace, RegistryAsset.Rules, slug),
184
+ sdks: (slug) => buildAsset(namespace, RegistryAsset.Sdks, slug),
185
+ schemas: (slug) => buildAsset(namespace, RegistryAsset.Schemas, slug),
186
+ workspaces: (slug) => buildAsset(namespace, RegistryAsset.Workspaces, slug)
187
+ };
188
+ }
189
+
190
+ // ../../packages/urls/dist/publish/full.js
191
+ function getPublishUrl(domain, subpath) {
192
+ const url = `https://${domain}${subpath ?? ""}`;
193
+ return new URL(url).toString();
194
+ }
195
+
196
+ // ../../packages/urls/dist/publish/previews.js
197
+ function getPublishPreviewUrl(publishUid, domain, subpath = "") {
198
+ const url = `https://${getPublishPreviewDomain(publishUid, domain)}${subpath ?? ""}`;
199
+ new URL(url);
200
+ return url;
201
+ }
202
+ function getPublishPreviewDomain(publishUid, domain) {
203
+ return `${publishUid}--${domain}`;
204
+ }
205
+
206
+ export {
207
+ getPublishUrl,
208
+ getPublishPreviewUrl,
209
+ registry
210
+ };
@@ -0,0 +1,295 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getAuthData
4
+ } from "./chunk-M37TP6U2.js";
5
+ import {
6
+ config
7
+ } from "./chunk-4ZDQXWBT.js";
8
+ import {
9
+ external_exports,
10
+ objectSchema,
11
+ schemaModel
12
+ } from "./chunk-IKT5F47M.js";
13
+
14
+ // ../../packages/mongobase-client/dist/auth/tokens.js
15
+ var tokenResponseSchema = external_exports.object({
16
+ accessToken: external_exports.string(),
17
+ refreshToken: external_exports.string()
18
+ });
19
+
20
+ // ../../packages/mongobase-client/dist/auth/utility.js
21
+ var ErrorCode;
22
+ (function(ErrorCode2) {
23
+ ErrorCode2["AuthFail"] = "auth-fail";
24
+ })(ErrorCode || (ErrorCode = {}));
25
+
26
+ // ../../packages/mongobase-client/dist/database/access.js
27
+ var primitiveSchema = external_exports.union([
28
+ external_exports.string(),
29
+ external_exports.number(),
30
+ external_exports.boolean(),
31
+ external_exports.null()
32
+ ]);
33
+ var $filterSchema = external_exports.object({
34
+ $in: external_exports.string().array().optional(),
35
+ $nin: external_exports.string().array().optional(),
36
+ $eq: primitiveSchema.optional(),
37
+ $ne: primitiveSchema.optional(),
38
+ $lt: external_exports.number().optional(),
39
+ $gt: external_exports.number().optional(),
40
+ $gte: external_exports.number().optional(),
41
+ $lte: external_exports.number().optional(),
42
+ $or: external_exports.lazy(() => $filterSchema.array()).optional()
43
+ });
44
+ var querySchema = external_exports.record(external_exports.string(), external_exports.union([primitiveSchema, $filterSchema]));
45
+ var getRecordRequestSchema = external_exports.object({
46
+ collectionPath: external_exports.string(),
47
+ query: querySchema
48
+ });
49
+ var addRecordRequestSchema = external_exports.object({
50
+ collectionPath: external_exports.string(),
51
+ data: objectSchema
52
+ });
53
+ var addMultipleRecordsRequestSchema = external_exports.object({
54
+ collectionPath: external_exports.string(),
55
+ data: objectSchema.array()
56
+ });
57
+ var updateRecordRequestSchema = external_exports.object({
58
+ collectionPath: external_exports.string(),
59
+ data: objectSchema,
60
+ query: querySchema
61
+ });
62
+ var deleteRecordRequestSchema = external_exports.object({
63
+ collectionPath: external_exports.string(),
64
+ query: querySchema
65
+ });
66
+ var dropCollectionRequestSchema = external_exports.object({
67
+ collectionPath: external_exports.string()
68
+ });
69
+ function formatResponse(response, schema) {
70
+ return {
71
+ status: response.status,
72
+ data: schemaModel(response.data, schema),
73
+ error: false
74
+ };
75
+ }
76
+ var statusMessages = {
77
+ 401: "Unauthorized. Please check that an access token was provided to the instance. "
78
+ };
79
+ function formatError(error, message) {
80
+ return {
81
+ status: error.status ?? 500,
82
+ message: statusMessages[error.response?.status] ?? error.message ?? message,
83
+ error: true,
84
+ originalError: error
85
+ };
86
+ }
87
+ var addResponseSchema = external_exports.object({
88
+ insertedId: external_exports.string()
89
+ });
90
+ var addMultiResponseSchema = external_exports.object({
91
+ insertedCount: external_exports.number(),
92
+ insertedIds: external_exports.preprocess((s) => Array.isArray(s) ? s : Object.values(s), external_exports.string().array())
93
+ });
94
+ var updateResponseSchema = external_exports.object({
95
+ matchedCount: external_exports.number(),
96
+ modifiedCount: external_exports.number(),
97
+ upsertedCount: external_exports.number(),
98
+ upsertedId: external_exports.string().nullable()
99
+ });
100
+ var deletedResponseSchema = external_exports.object({
101
+ deletedCount: external_exports.number()
102
+ });
103
+ function createAccess(baseURL) {
104
+ const state = {
105
+ accessToken: ""
106
+ };
107
+ function makeRequest(options) {
108
+ return fetch(`${baseURL}${options.url}`, {
109
+ method: options.method,
110
+ headers: {
111
+ ...options.headers,
112
+ // An empty bearer token is always rejected — omit the header so the
113
+ // server returns a clean 401 instead of parsing a malformed value
114
+ ...state.accessToken ? { Authorization: `Bearer ${state.accessToken}` } : {},
115
+ "Content-Type": "application/json"
116
+ },
117
+ body: JSON.stringify(options.data)
118
+ }).then(async (res) => {
119
+ if (!res.ok) {
120
+ return formatError({ status: res.status, message: await res.text() }, "Unknown Error");
121
+ }
122
+ return formatResponse({ data: await res.json(), status: res.status }, options.schema);
123
+ }).catch((err) => formatError(err));
124
+ }
125
+ function get({ collectionPath, query, schema, type }) {
126
+ const data = schemaModel({ collectionPath, query }, getRecordRequestSchema);
127
+ return makeRequest({
128
+ url: `/database/get-${type}`,
129
+ method: "POST",
130
+ data,
131
+ schema
132
+ });
133
+ }
134
+ function addOne({ collectionPath, data, schema, responseSchema }) {
135
+ const sanitizedData = schemaModel({ collectionPath, data: schemaModel(data, schema) }, addRecordRequestSchema);
136
+ return makeRequest({
137
+ url: "/database/add-one",
138
+ method: "POST",
139
+ data: sanitizedData,
140
+ schema: responseSchema
141
+ });
142
+ }
143
+ function addMultiple({ collectionPath, data, schema, responseSchema }) {
144
+ const sanitizedData = schemaModel({ collectionPath, data: schemaModel(data, schema) }, addMultipleRecordsRequestSchema);
145
+ return makeRequest({
146
+ url: "/database/add-many",
147
+ method: "POST",
148
+ data: sanitizedData,
149
+ schema: responseSchema
150
+ });
151
+ }
152
+ function remove({ collectionPath, query, type }) {
153
+ const data = schemaModel({ collectionPath, query }, deleteRecordRequestSchema);
154
+ return makeRequest({
155
+ url: `/database/delete-${type}`,
156
+ method: "POST",
157
+ data,
158
+ schema: deletedResponseSchema
159
+ });
160
+ }
161
+ function update({ collectionPath, data, query, schema }) {
162
+ const updateData = schemaModel({
163
+ collectionPath,
164
+ query,
165
+ data: schemaModel(data, schema)
166
+ }, updateRecordRequestSchema);
167
+ return makeRequest({
168
+ url: "/database/update-one",
169
+ method: "POST",
170
+ data: updateData,
171
+ schema: updateResponseSchema
172
+ });
173
+ }
174
+ function dropCollection({ collectionPath }) {
175
+ const data = schemaModel({ collectionPath }, dropCollectionRequestSchema);
176
+ return makeRequest({
177
+ url: "/database/drop-collection",
178
+ method: "POST",
179
+ data,
180
+ schema: external_exports.any()
181
+ });
182
+ }
183
+ return {
184
+ /** Update the access token */
185
+ updateAccessToken(accessToken) {
186
+ state.accessToken = accessToken;
187
+ },
188
+ async checkHealth(url) {
189
+ if (!state.accessToken) {
190
+ return {
191
+ status: 511,
192
+ message: "No Access Token",
193
+ error: true,
194
+ originalError: null
195
+ };
196
+ }
197
+ return await makeRequest({
198
+ url,
199
+ method: "GET",
200
+ schema: external_exports.any()
201
+ });
202
+ },
203
+ /** Get a single record */
204
+ getOne(options) {
205
+ return get({ ...options, type: "one" });
206
+ },
207
+ /** Get multiple records */
208
+ getMany(options) {
209
+ return get({ ...options, type: "many" });
210
+ },
211
+ /** Add a single record */
212
+ addOne(options) {
213
+ return addOne({ ...options, responseSchema: addResponseSchema });
214
+ },
215
+ /** Add multiple records */
216
+ addMany(options) {
217
+ return addMultiple({ ...options, responseSchema: addMultiResponseSchema });
218
+ },
219
+ updateOne(options) {
220
+ return update({ ...options });
221
+ },
222
+ /** Delete a single record */
223
+ deleteOne(options) {
224
+ return remove({ ...options, type: "one" });
225
+ },
226
+ /** Delete multiple records */
227
+ deleteMany(options) {
228
+ return remove({ ...options, type: "many" });
229
+ },
230
+ dropCollection
231
+ };
232
+ }
233
+
234
+ // ../../packages/mongobase-client/dist/database/offline.js
235
+ var DiffOp;
236
+ (function(DiffOp2) {
237
+ DiffOp2["Remove"] = "remove";
238
+ DiffOp2["Replace"] = "replace";
239
+ DiffOp2["Add"] = "add";
240
+ })(DiffOp || (DiffOp = {}));
241
+ var diffRecordSchema = external_exports.object({
242
+ op: external_exports.enum(DiffOp),
243
+ path: external_exports.union([external_exports.string(), external_exports.number()]).array(),
244
+ value: external_exports.any()
245
+ });
246
+ var MutationOp;
247
+ (function(MutationOp2) {
248
+ MutationOp2["Add"] = "add";
249
+ MutationOp2["Update"] = "update";
250
+ MutationOp2["Delete"] = "delete";
251
+ })(MutationOp || (MutationOp = {}));
252
+ var collectionChangeRecordSchema = external_exports.record(external_exports.string(), external_exports.object({
253
+ action: external_exports.enum(MutationOp),
254
+ value: external_exports.any()
255
+ }));
256
+ var changelogSchema = external_exports.record(external_exports.string(), collectionChangeRecordSchema);
257
+
258
+ // ../../packages/mongobase-client/dist/database/socket.js
259
+ var SubscriptionTypes;
260
+ (function(SubscriptionTypes2) {
261
+ SubscriptionTypes2["Collection"] = "collection";
262
+ SubscriptionTypes2["Document"] = "document";
263
+ })(SubscriptionTypes || (SubscriptionTypes = {}));
264
+ var MAX_RECONNECT_INTERVAL = 60 * 1e3;
265
+
266
+ // ../../packages/mongobase-client/dist/database/subscribe.js
267
+ var SubscriptionAction;
268
+ (function(SubscriptionAction2) {
269
+ SubscriptionAction2["Add"] = "insert";
270
+ SubscriptionAction2["Update"] = "update";
271
+ SubscriptionAction2["Remove"] = "delete";
272
+ })(SubscriptionAction || (SubscriptionAction = {}));
273
+
274
+ // ../../packages/mongobase-client/dist/database/index.js
275
+ function initDatabase(baseUrl) {
276
+ if (!baseUrl)
277
+ throw new Error("Invalid URL provided to initDatabase");
278
+ return createAccess(baseUrl);
279
+ }
280
+
281
+ // src/helpers/database.ts
282
+ var getDatabaseClient = async () => {
283
+ const client = initDatabase(`${config.services.api}/rtdb`);
284
+ const auth = await getAuthData();
285
+ auth.addEventListener((state) => {
286
+ Object.assign(auth, state);
287
+ client.updateAccessToken(state.accessToken);
288
+ });
289
+ client.updateAccessToken(auth.accessToken);
290
+ return client;
291
+ };
292
+
293
+ export {
294
+ getDatabaseClient
295
+ };
@@ -0,0 +1,108 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ apiService
4
+ } from "./chunk-AO3F5XWR.js";
5
+ import {
6
+ BaseCollections
7
+ } from "./chunk-F467BYYR.js";
8
+ import {
9
+ getDatabaseClient
10
+ } from "./chunk-Z2KMGFE6.js";
11
+ import "./chunk-HCPN3KNF.js";
12
+ import "./chunk-B2MHTD3R.js";
13
+ import {
14
+ SdkLanguage
15
+ } from "./chunk-3L6DLIXJ.js";
16
+ import "./chunk-P7H7GY5A.js";
17
+ import "./chunk-HPL3ZZ2P.js";
18
+ import {
19
+ getAuthData
20
+ } from "./chunk-M37TP6U2.js";
21
+ import {
22
+ config
23
+ } from "./chunk-4ZDQXWBT.js";
24
+ import {
25
+ teamSchema
26
+ } from "./chunk-VNYE4R7N.js";
27
+ import "./chunk-OQKDBLOZ.js";
28
+ import "./chunk-K74E42RV.js";
29
+ import "./chunk-CISTON3A.js";
30
+ import "./chunk-Q7DOQHZN.js";
31
+ import "./chunk-4ORL4MST.js";
32
+ import {
33
+ output
34
+ } from "./chunk-T5HJUAWB.js";
35
+ import "./chunk-GSGZHE26.js";
36
+ import {
37
+ external_exports,
38
+ namespaceSchema,
39
+ slugSchema
40
+ } from "./chunk-IKT5F47M.js";
41
+ import "./chunk-3MZYUBJ6.js";
42
+
43
+ // src/domains/sdk/create.action.ts
44
+ import { select, text } from "@clack/prompts";
45
+ import as from "ansis";
46
+ async function createAction(opts) {
47
+ const { error, data } = external_exports.object({
48
+ namespace: namespaceSchema.optional(),
49
+ language: external_exports.enum(SdkLanguage).optional(),
50
+ api: slugSchema.optional()
51
+ }).safeParse(opts);
52
+ if (error)
53
+ return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
54
+ const auth = await getAuthData();
55
+ auth.addEventListener((state) => Object.assign(auth, state));
56
+ const db = await getDatabaseClient();
57
+ const client = await apiService();
58
+ const language = opts.language || await text({
59
+ message: "Please choose a language for your SDK",
60
+ placeholder: "typescript",
61
+ validate: (v) => {
62
+ return external_exports.enum(SdkLanguage).safeParse(v)?.error ? "Please select a valid language" : void 0;
63
+ },
64
+ defaultValue: void 0
65
+ });
66
+ const team = await db.getOne({
67
+ collectionPath: BaseCollections.Teams,
68
+ query: {
69
+ uid: auth.teamUid
70
+ },
71
+ schema: teamSchema
72
+ });
73
+ if (team.error)
74
+ return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
75
+ const namespace = data.namespace || team.data.namespaces.at(0);
76
+ if (!namespace) {
77
+ return output.error().title("Missing namespace").message(
78
+ "Could not find a valid namespace for your API. Please specify a namespace or contact support."
79
+ ).exit("error");
80
+ }
81
+ const namespaceApisRes = await client.managedDocs.getApiDocs(namespace);
82
+ if (namespaceApisRes.error)
83
+ return output.error().title(namespaceApisRes.message).exit("error");
84
+ const apiUid = namespaceApisRes.data.find((api) => api.slug === data.api)?.uid || await select({
85
+ message: "Please select an API",
86
+ options: namespaceApisRes.data.map((api) => ({
87
+ value: api.uid,
88
+ label: api.slug
89
+ }))
90
+ });
91
+ if (!apiUid) {
92
+ return output.error().title("No API found").message("Please provide a valid API slug").exit("error");
93
+ }
94
+ const logger = output.info().loader("Creating the SDK");
95
+ const response = await client.sdks.create({
96
+ apiUid,
97
+ languages: [language]
98
+ });
99
+ if (response.error) {
100
+ return output.error().title("Something went wrong").message(response.message).exit("error");
101
+ }
102
+ logger.update("loader", 0, { content: "SDK created successfully!" });
103
+ const dashboardUrl = `${config.projects.dashboard}/sdk/${response.data}`;
104
+ logger.message(`View your SDK in the Scalar dashboard: ${as.cyan(dashboardUrl)}`).exit("success");
105
+ }
106
+ export {
107
+ createAction
108
+ };
@@ -0,0 +1,88 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ apiService
4
+ } from "./chunk-AO3F5XWR.js";
5
+ import {
6
+ BaseCollections
7
+ } from "./chunk-F467BYYR.js";
8
+ import {
9
+ getDatabaseClient
10
+ } from "./chunk-Z2KMGFE6.js";
11
+ import "./chunk-HCPN3KNF.js";
12
+ import "./chunk-B2MHTD3R.js";
13
+ import "./chunk-3L6DLIXJ.js";
14
+ import "./chunk-P7H7GY5A.js";
15
+ import "./chunk-HPL3ZZ2P.js";
16
+ import {
17
+ getAuthData
18
+ } from "./chunk-M37TP6U2.js";
19
+ import "./chunk-4ZDQXWBT.js";
20
+ import {
21
+ teamSchema
22
+ } from "./chunk-VNYE4R7N.js";
23
+ import "./chunk-OQKDBLOZ.js";
24
+ import "./chunk-K74E42RV.js";
25
+ import "./chunk-CISTON3A.js";
26
+ import "./chunk-Q7DOQHZN.js";
27
+ import "./chunk-4ORL4MST.js";
28
+ import {
29
+ output
30
+ } from "./chunk-T5HJUAWB.js";
31
+ import "./chunk-GSGZHE26.js";
32
+ import {
33
+ external_exports,
34
+ namespaceSchema,
35
+ slugSchema
36
+ } from "./chunk-IKT5F47M.js";
37
+ import "./chunk-3MZYUBJ6.js";
38
+
39
+ // src/domains/schema/delete.action.ts
40
+ import { select } from "@clack/prompts";
41
+ async function deleteAction(opts) {
42
+ const { error, data } = external_exports.object({
43
+ slug: slugSchema.optional(),
44
+ namespace: namespaceSchema.optional()
45
+ }).safeParse(opts);
46
+ if (error)
47
+ return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
48
+ const auth = await getAuthData();
49
+ auth.addEventListener((state) => Object.assign(auth, state));
50
+ const db = await getDatabaseClient();
51
+ const client = await apiService();
52
+ const team = await db.getOne({
53
+ collectionPath: BaseCollections.Teams,
54
+ query: {
55
+ uid: auth.teamUid
56
+ },
57
+ schema: teamSchema
58
+ });
59
+ if (team.error)
60
+ return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
61
+ const namespace = data.namespace || team.data.namespaces.at(0);
62
+ if (!namespace) {
63
+ return output.error().title("Missing namespace").message(
64
+ "Could not find a valid namespace for your schema. Please specify a namespace or contact support."
65
+ ).exit("error");
66
+ }
67
+ const schemas = await client.managedSchemas.getSchemas(namespace);
68
+ if (schemas.error) return output.error().title(schemas.message).exit("error");
69
+ const schemaSlug = schemas.data.find((schema) => schema.slug === data.slug)?.slug || await select({
70
+ message: "Please select a schema to delete",
71
+ options: schemas.data.map((schema) => ({
72
+ value: schema.slug,
73
+ label: schema.slug
74
+ }))
75
+ });
76
+ if (!schemaSlug) {
77
+ return output.error().title("No schema found").message("Please provide a valid schema slug").exit("error");
78
+ }
79
+ const logger = output.info().loader("Deleting the schema");
80
+ const response = await client.managedSchemas.delete(namespace, schemaSlug);
81
+ if (response.error) {
82
+ return output.error().title("Something went wrong").message(response.message).exit("error");
83
+ }
84
+ logger.update("loader", 0, { content: "Schema deleted successfully!" }).exit("success");
85
+ }
86
+ export {
87
+ deleteAction
88
+ };