@mastra/deployer-cloudflare 0.0.1-alpha.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 ADDED
@@ -0,0 +1,9 @@
1
+ # @mastra/deployer-cloudflare
2
+
3
+ ## 0.0.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4139b43]
8
+ - Updated dependencies [a5604c4]
9
+ - @mastra/deployer@0.0.1-alpha.0
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
@@ -0,0 +1,451 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@mastra/core');
6
+ var child_process = require('child_process');
7
+ var fs = require('fs');
8
+ var path = require('path');
9
+
10
+ function _interopNamespaceDefault(e) {
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return n;
25
+ }
26
+
27
+ var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_process);
28
+
29
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
30
+ try {
31
+ var i = n[a](c),
32
+ u = i.value;
33
+ } catch (n) {
34
+ return void e(n);
35
+ }
36
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
37
+ }
38
+ function _asyncToGenerator(n) {
39
+ return function () {
40
+ var t = this,
41
+ e = arguments;
42
+ return new Promise(function (r, o) {
43
+ var a = n.apply(t, e);
44
+ function _next(n) {
45
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
46
+ }
47
+ function _throw(n) {
48
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
49
+ }
50
+ _next(void 0);
51
+ });
52
+ };
53
+ }
54
+ function _extends() {
55
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
56
+ for (var e = 1; e < arguments.length; e++) {
57
+ var t = arguments[e];
58
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
59
+ }
60
+ return n;
61
+ }, _extends.apply(null, arguments);
62
+ }
63
+ function _inheritsLoose(t, o) {
64
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
65
+ }
66
+ function _regeneratorRuntime() {
67
+ _regeneratorRuntime = function () {
68
+ return e;
69
+ };
70
+ var t,
71
+ e = {},
72
+ r = Object.prototype,
73
+ n = r.hasOwnProperty,
74
+ o = Object.defineProperty || function (t, e, r) {
75
+ t[e] = r.value;
76
+ },
77
+ i = "function" == typeof Symbol ? Symbol : {},
78
+ a = i.iterator || "@@iterator",
79
+ c = i.asyncIterator || "@@asyncIterator",
80
+ u = i.toStringTag || "@@toStringTag";
81
+ function define(t, e, r) {
82
+ return Object.defineProperty(t, e, {
83
+ value: r,
84
+ enumerable: !0,
85
+ configurable: !0,
86
+ writable: !0
87
+ }), t[e];
88
+ }
89
+ try {
90
+ define({}, "");
91
+ } catch (t) {
92
+ define = function (t, e, r) {
93
+ return t[e] = r;
94
+ };
95
+ }
96
+ function wrap(t, e, r, n) {
97
+ var i = e && e.prototype instanceof Generator ? e : Generator,
98
+ a = Object.create(i.prototype),
99
+ c = new Context(n || []);
100
+ return o(a, "_invoke", {
101
+ value: makeInvokeMethod(t, r, c)
102
+ }), a;
103
+ }
104
+ function tryCatch(t, e, r) {
105
+ try {
106
+ return {
107
+ type: "normal",
108
+ arg: t.call(e, r)
109
+ };
110
+ } catch (t) {
111
+ return {
112
+ type: "throw",
113
+ arg: t
114
+ };
115
+ }
116
+ }
117
+ e.wrap = wrap;
118
+ var h = "suspendedStart",
119
+ l = "suspendedYield",
120
+ f = "executing",
121
+ s = "completed",
122
+ y = {};
123
+ function Generator() {}
124
+ function GeneratorFunction() {}
125
+ function GeneratorFunctionPrototype() {}
126
+ var p = {};
127
+ define(p, a, function () {
128
+ return this;
129
+ });
130
+ var d = Object.getPrototypeOf,
131
+ v = d && d(d(values([])));
132
+ v && v !== r && n.call(v, a) && (p = v);
133
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
134
+ function defineIteratorMethods(t) {
135
+ ["next", "throw", "return"].forEach(function (e) {
136
+ define(t, e, function (t) {
137
+ return this._invoke(e, t);
138
+ });
139
+ });
140
+ }
141
+ function AsyncIterator(t, e) {
142
+ function invoke(r, o, i, a) {
143
+ var c = tryCatch(t[r], t, o);
144
+ if ("throw" !== c.type) {
145
+ var u = c.arg,
146
+ h = u.value;
147
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
148
+ invoke("next", t, i, a);
149
+ }, function (t) {
150
+ invoke("throw", t, i, a);
151
+ }) : e.resolve(h).then(function (t) {
152
+ u.value = t, i(u);
153
+ }, function (t) {
154
+ return invoke("throw", t, i, a);
155
+ });
156
+ }
157
+ a(c.arg);
158
+ }
159
+ var r;
160
+ o(this, "_invoke", {
161
+ value: function (t, n) {
162
+ function callInvokeWithMethodAndArg() {
163
+ return new e(function (e, r) {
164
+ invoke(t, n, e, r);
165
+ });
166
+ }
167
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
168
+ }
169
+ });
170
+ }
171
+ function makeInvokeMethod(e, r, n) {
172
+ var o = h;
173
+ return function (i, a) {
174
+ if (o === f) throw Error("Generator is already running");
175
+ if (o === s) {
176
+ if ("throw" === i) throw a;
177
+ return {
178
+ value: t,
179
+ done: !0
180
+ };
181
+ }
182
+ for (n.method = i, n.arg = a;;) {
183
+ var c = n.delegate;
184
+ if (c) {
185
+ var u = maybeInvokeDelegate(c, n);
186
+ if (u) {
187
+ if (u === y) continue;
188
+ return u;
189
+ }
190
+ }
191
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
192
+ if (o === h) throw o = s, n.arg;
193
+ n.dispatchException(n.arg);
194
+ } else "return" === n.method && n.abrupt("return", n.arg);
195
+ o = f;
196
+ var p = tryCatch(e, r, n);
197
+ if ("normal" === p.type) {
198
+ if (o = n.done ? s : l, p.arg === y) continue;
199
+ return {
200
+ value: p.arg,
201
+ done: n.done
202
+ };
203
+ }
204
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
205
+ }
206
+ };
207
+ }
208
+ function maybeInvokeDelegate(e, r) {
209
+ var n = r.method,
210
+ o = e.iterator[n];
211
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
212
+ var i = tryCatch(o, e.iterator, r.arg);
213
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
214
+ var a = i.arg;
215
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
216
+ }
217
+ function pushTryEntry(t) {
218
+ var e = {
219
+ tryLoc: t[0]
220
+ };
221
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
222
+ }
223
+ function resetTryEntry(t) {
224
+ var e = t.completion || {};
225
+ e.type = "normal", delete e.arg, t.completion = e;
226
+ }
227
+ function Context(t) {
228
+ this.tryEntries = [{
229
+ tryLoc: "root"
230
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
231
+ }
232
+ function values(e) {
233
+ if (e || "" === e) {
234
+ var r = e[a];
235
+ if (r) return r.call(e);
236
+ if ("function" == typeof e.next) return e;
237
+ if (!isNaN(e.length)) {
238
+ var o = -1,
239
+ i = function next() {
240
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
241
+ return next.value = t, next.done = !0, next;
242
+ };
243
+ return i.next = i;
244
+ }
245
+ }
246
+ throw new TypeError(typeof e + " is not iterable");
247
+ }
248
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
249
+ value: GeneratorFunctionPrototype,
250
+ configurable: !0
251
+ }), o(GeneratorFunctionPrototype, "constructor", {
252
+ value: GeneratorFunction,
253
+ configurable: !0
254
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
255
+ var e = "function" == typeof t && t.constructor;
256
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
257
+ }, e.mark = function (t) {
258
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
259
+ }, e.awrap = function (t) {
260
+ return {
261
+ __await: t
262
+ };
263
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
264
+ return this;
265
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
266
+ void 0 === i && (i = Promise);
267
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
268
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
269
+ return t.done ? t.value : a.next();
270
+ });
271
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
272
+ return this;
273
+ }), define(g, "toString", function () {
274
+ return "[object Generator]";
275
+ }), e.keys = function (t) {
276
+ var e = Object(t),
277
+ r = [];
278
+ for (var n in e) r.push(n);
279
+ return r.reverse(), function next() {
280
+ for (; r.length;) {
281
+ var t = r.pop();
282
+ if (t in e) return next.value = t, next.done = !1, next;
283
+ }
284
+ return next.done = !0, next;
285
+ };
286
+ }, e.values = values, Context.prototype = {
287
+ constructor: Context,
288
+ reset: function (e) {
289
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
290
+ },
291
+ stop: function () {
292
+ this.done = !0;
293
+ var t = this.tryEntries[0].completion;
294
+ if ("throw" === t.type) throw t.arg;
295
+ return this.rval;
296
+ },
297
+ dispatchException: function (e) {
298
+ if (this.done) throw e;
299
+ var r = this;
300
+ function handle(n, o) {
301
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
302
+ }
303
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
304
+ var i = this.tryEntries[o],
305
+ a = i.completion;
306
+ if ("root" === i.tryLoc) return handle("end");
307
+ if (i.tryLoc <= this.prev) {
308
+ var c = n.call(i, "catchLoc"),
309
+ u = n.call(i, "finallyLoc");
310
+ if (c && u) {
311
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
312
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
313
+ } else if (c) {
314
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
315
+ } else {
316
+ if (!u) throw Error("try statement without catch or finally");
317
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
318
+ }
319
+ }
320
+ }
321
+ },
322
+ abrupt: function (t, e) {
323
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
324
+ var o = this.tryEntries[r];
325
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
326
+ var i = o;
327
+ break;
328
+ }
329
+ }
330
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
331
+ var a = i ? i.completion : {};
332
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
333
+ },
334
+ complete: function (t, e) {
335
+ if ("throw" === t.type) throw t.arg;
336
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
337
+ },
338
+ finish: function (t) {
339
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
340
+ var r = this.tryEntries[e];
341
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
342
+ }
343
+ },
344
+ catch: function (t) {
345
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
346
+ var r = this.tryEntries[e];
347
+ if (r.tryLoc === t) {
348
+ var n = r.completion;
349
+ if ("throw" === n.type) {
350
+ var o = n.arg;
351
+ resetTryEntry(r);
352
+ }
353
+ return o;
354
+ }
355
+ }
356
+ throw Error("illegal catch attempt");
357
+ },
358
+ delegateYield: function (e, r, n) {
359
+ return this.delegate = {
360
+ iterator: values(e),
361
+ resultName: r,
362
+ nextLoc: n
363
+ }, "next" === this.method && (this.arg = t), y;
364
+ }
365
+ }, e;
366
+ }
367
+ function _setPrototypeOf(t, e) {
368
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
369
+ return t.__proto__ = e, t;
370
+ }, _setPrototypeOf(t, e);
371
+ }
372
+
373
+ var CloudflareDeployer = /*#__PURE__*/function (_MastraDeployer) {
374
+ function CloudflareDeployer(_ref) {
375
+ var _this;
376
+ var scope = _ref.scope,
377
+ env = _ref.env,
378
+ projectName = _ref.projectName,
379
+ routes = _ref.routes;
380
+ _this = _MastraDeployer.call(this, {
381
+ scope: scope,
382
+ env: env,
383
+ projectName: projectName
384
+ }) || this;
385
+ _this.routes = [];
386
+ _this.routes = routes;
387
+ return _this;
388
+ }
389
+ _inheritsLoose(CloudflareDeployer, _MastraDeployer);
390
+ var _proto = CloudflareDeployer.prototype;
391
+ _proto.writeFiles = function writeFiles(_ref2) {
392
+ var dir = _ref2.dir;
393
+ this.loadEnvVars();
394
+ this.writeIndex({
395
+ dir: dir
396
+ });
397
+ var cfWorkerName = this.projectName || 'mastra';
398
+ fs.writeFileSync(path.join(dir, 'wrangler.json'), JSON.stringify({
399
+ name: cfWorkerName,
400
+ main: 'index.mjs',
401
+ compatibility_date: '2024-12-02',
402
+ compatibility_flags: ['nodejs_compat'],
403
+ build: {
404
+ command: 'npm install'
405
+ },
406
+ observability: {
407
+ logs: {
408
+ enabled: true
409
+ }
410
+ },
411
+ routes: this.routes,
412
+ vars: this.env
413
+ }));
414
+ };
415
+ _proto.writeIndex = function writeIndex(_ref3) {
416
+ var dir = _ref3.dir;
417
+ fs.writeFileSync(path.join(dir, './index.mjs'), "\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n ");
418
+ };
419
+ _proto.deploy = /*#__PURE__*/function () {
420
+ var _deploy = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref4) {
421
+ var dir, token;
422
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
423
+ while (1) switch (_context.prev = _context.next) {
424
+ case 0:
425
+ dir = _ref4.dir, token = _ref4.token;
426
+ child_process__namespace.execSync("npm exec wrangler deploy", {
427
+ cwd: dir,
428
+ stdio: 'inherit',
429
+ env: _extends({
430
+ CLOUDFLARE_API_TOKEN: token,
431
+ CLOUDFLARE_ACCOUNT_ID: this.scope
432
+ }, this.env, {
433
+ PATH: process.env.PATH
434
+ })
435
+ });
436
+ case 2:
437
+ case "end":
438
+ return _context.stop();
439
+ }
440
+ }, _callee, this);
441
+ }));
442
+ function deploy(_x) {
443
+ return _deploy.apply(this, arguments);
444
+ }
445
+ return deploy;
446
+ }();
447
+ return CloudflareDeployer;
448
+ }(core.MastraDeployer);
449
+
450
+ exports.CloudflareDeployer = CloudflareDeployer;
451
+ //# sourceMappingURL=deployer-cloudflare.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployer-cloudflare.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import { MastraDeployer } from '@mastra/core';\nimport * as child_process from 'child_process';\nimport { writeFileSync } from 'fs';\nimport { join } from 'path';\n\ninterface CFRoute {\n pattern: string;\n zone_name: string;\n}\n\nexport class CloudflareDeployer extends MastraDeployer {\n routes?: CFRoute[] = [];\n constructor({\n scope,\n env,\n projectName,\n routes,\n }: {\n env?: Record<string, any>;\n scope: string;\n projectName: string;\n routes?: CFRoute[];\n }) {\n super({ scope, env, projectName });\n\n this.routes = routes;\n }\n\n writeFiles({ dir }: { dir: string }): void {\n this.loadEnvVars();\n\n this.writeIndex({ dir });\n\n const cfWorkerName = this.projectName || 'mastra';\n\n writeFileSync(\n join(dir, 'wrangler.json'),\n JSON.stringify({\n name: cfWorkerName,\n main: 'index.mjs',\n compatibility_date: '2024-12-02',\n compatibility_flags: ['nodejs_compat'],\n build: {\n command: 'npm install',\n },\n observability: {\n logs: {\n enabled: true,\n },\n },\n routes: this.routes,\n vars: this.env,\n }),\n );\n }\n\n writeIndex({ dir }: { dir: string }): void {\n writeFileSync(\n join(dir, './index.mjs'),\n `\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n `,\n );\n }\n\n async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {\n child_process.execSync(`npm exec wrangler deploy`, {\n cwd: dir,\n stdio: 'inherit',\n env: {\n CLOUDFLARE_API_TOKEN: token,\n CLOUDFLARE_ACCOUNT_ID: this.scope,\n ...this.env,\n PATH: process.env.PATH,\n },\n });\n }\n}\n"],"names":["CloudflareDeployer","_MastraDeployer","_ref","_this","scope","env","projectName","routes","call","_inheritsLoose","_proto","prototype","writeFiles","_ref2","dir","loadEnvVars","writeIndex","cfWorkerName","writeFileSync","join","JSON","stringify","name","main","compatibility_date","compatibility_flags","build","command","observability","logs","enabled","vars","_ref3","deploy","_deploy","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref4","token","wrap","_callee$","_context","prev","next","child_process","execSync","cwd","stdio","_extends","CLOUDFLARE_API_TOKEN","CLOUDFLARE_ACCOUNT_ID","PATH","process","stop","_x","apply","arguments","MastraDeployer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUaA,IAAAA,kBAAmB,0BAAAC,eAAA,EAAA;EAE9B,SAAAD,kBAAAA,CAAAE,IAAA,EAUC;AAAA,IAAA,IAAAC,KAAA,CAAA;AAAA,IAAA,IATCC,KAAK,GAAAF,IAAA,CAALE,KAAK;MACLC,GAAG,GAAAH,IAAA,CAAHG,GAAG;MACHC,WAAW,GAAAJ,IAAA,CAAXI,WAAW;MACXC,MAAM,GAAAL,IAAA,CAANK,MAAM,CAAA;AAONJ,IAAAA,KAAA,GAAAF,eAAA,CAAAO,IAAA,CAAM,IAAA,EAAA;AAAEJ,MAAAA,KAAK,EAALA,KAAK;AAAEC,MAAAA,GAAG,EAAHA,GAAG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,OAAAtB,OAAA,CAAAuB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAANzB,MAAM,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAAjC,kBAAA,CAAA;AAAA,CAAA,CA5D0B2D,mBAAc;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mastra/core"),r=require("child_process"),e=require("fs"),n=require("path");function o(t){var r=Object.create(null);return t&&Object.keys(t).forEach((function(e){if("default"!==e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}})),r.default=t,r}var i=o(r);function a(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function c(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var i=t.apply(r,e);function c(t){a(i,n,o,c,u,"next",t)}function u(t){a(i,n,o,c,u,"throw",t)}c(void 0)}))}}function u(){return u=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)({}).hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},u.apply(null,arguments)}function s(){s=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var i=Object.create((r&&r.prototype instanceof m?r:m).prototype),a=new S(n||[]);return o(i,"_invoke",{value:P(t,e,a)}),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var p="suspendedStart",y="suspendedYield",v="executing",d="completed",g={};function m(){}function w(){}function b(){}var x={};l(x,a,(function(){return this}));var j=Object.getPrototypeOf,O=j&&j(j(T([])));O&&O!==e&&n.call(O,a)&&(x=O);var L=b.prototype=m.prototype=Object.create(x);function _(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function E(t,r){function e(o,i,a,c){var u=h(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return i=i?i.then(o,o):o()}})}function P(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=N(c,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=h(r,e,n);if("normal"===s.type){if(o=n.done?d:y,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function N(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,N(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function F(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[a];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,o(L,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:w,configurable:!0}),w.displayName=l(b,u,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,u,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},_(E.prototype),l(E.prototype,c,(function(){return this})),r.AsyncIterator=E,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new E(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(L),l(L,u,"Generator"),l(L,a,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,S.prototype={constructor:S,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(F),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),g},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),F(e),g}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;F(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),g}},r}function l(t,r){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},l(t,r)}exports.CloudflareDeployer=function(t){function r(r){var e,n=r.routes;return(e=t.call(this,{scope:r.scope,env:r.env,projectName:r.projectName})||this).routes=[],e.routes=n,e}var o,a;a=t,(o=r).prototype=Object.create(a.prototype),o.prototype.constructor=o,l(o,a);var f=r.prototype;return f.writeFiles=function(t){var r=t.dir;this.loadEnvVars(),this.writeIndex({dir:r});var o=this.projectName||"mastra";e.writeFileSync(n.join(r,"wrangler.json"),JSON.stringify({name:o,main:"index.mjs",compatibility_date:"2024-12-02",compatibility_flags:["nodejs_compat"],build:{command:"npm install"},observability:{logs:{enabled:!0}},routes:this.routes,vars:this.env}))},f.writeIndex=function(t){e.writeFileSync(n.join(t.dir,"./index.mjs"),"\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n ")},f.deploy=function(){var t=c(s().mark((function t(r){return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i.execSync("npm exec wrangler deploy",{cwd:r.dir,stdio:"inherit",env:u({CLOUDFLARE_API_TOKEN:r.token,CLOUDFLARE_ACCOUNT_ID:this.scope},this.env,{PATH:process.env.PATH})});case 2:case"end":return t.stop()}}),t,this)})));return function(r){return t.apply(this,arguments)}}(),r}(t.MastraDeployer);
2
+ //# sourceMappingURL=deployer-cloudflare.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployer-cloudflare.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import { MastraDeployer } from '@mastra/core';\nimport * as child_process from 'child_process';\nimport { writeFileSync } from 'fs';\nimport { join } from 'path';\n\ninterface CFRoute {\n pattern: string;\n zone_name: string;\n}\n\nexport class CloudflareDeployer extends MastraDeployer {\n routes?: CFRoute[] = [];\n constructor({\n scope,\n env,\n projectName,\n routes,\n }: {\n env?: Record<string, any>;\n scope: string;\n projectName: string;\n routes?: CFRoute[];\n }) {\n super({ scope, env, projectName });\n\n this.routes = routes;\n }\n\n writeFiles({ dir }: { dir: string }): void {\n this.loadEnvVars();\n\n this.writeIndex({ dir });\n\n const cfWorkerName = this.projectName || 'mastra';\n\n writeFileSync(\n join(dir, 'wrangler.json'),\n JSON.stringify({\n name: cfWorkerName,\n main: 'index.mjs',\n compatibility_date: '2024-12-02',\n compatibility_flags: ['nodejs_compat'],\n build: {\n command: 'npm install',\n },\n observability: {\n logs: {\n enabled: true,\n },\n },\n routes: this.routes,\n vars: this.env,\n }),\n );\n }\n\n writeIndex({ dir }: { dir: string }): void {\n writeFileSync(\n join(dir, './index.mjs'),\n `\n export default {\n fetch: async (event, context) => {\n const { app } = await import('./hono.mjs');\n return app.fetch(event, context);\n }\n }\n `,\n );\n }\n\n async deploy({ dir, token }: { dir: string; token: string }): Promise<void> {\n child_process.execSync(`npm exec wrangler deploy`, {\n cwd: dir,\n stdio: 'inherit',\n env: {\n CLOUDFLARE_API_TOKEN: token,\n CLOUDFLARE_ACCOUNT_ID: this.scope,\n ...this.env,\n PATH: process.env.PATH,\n },\n });\n }\n}\n"],"names":["_MastraDeployer","CloudflareDeployer","_ref","_this","routes","call","this","scope","env","projectName","_proto","prototype","writeFiles","_ref2","dir","loadEnvVars","writeIndex","cfWorkerName","writeFileSync","join","JSON","stringify","name","main","compatibility_date","compatibility_flags","build","command","observability","logs","enabled","vars","_ref3","deploy","_deploy","_asyncToGenerator","_regeneratorRuntime","mark","_callee","_ref4","wrap","_context","prev","next","child_process","execSync","cwd","stdio","_extends","CLOUDFLARE_API_TOKEN","token","CLOUDFLARE_ACCOUNT_ID","PATH","process","stop","_x","apply","arguments","MastraDeployer"],"mappings":"m7OAUgCA,GAE9B,SAAAC,EAAAC,GAUC,IAAAC,EANCC,EAAMF,EAANE,OASqB,OAFrBD,EAAAH,EAAAK,KAAMC,KAAA,CAAEC,MAVHL,EAALK,MAUeC,IATZN,EAAHM,IASoBC,YARTP,EAAXO,eAQkCH,MAZpCF,OAAqB,GAcnBD,EAAKC,OAASA,EAAOD,CACvB,WAACH,KAAAC,yE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