effortless-aws 0.34.0 → 0.36.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/dist/index.js CHANGED
@@ -116,11 +116,32 @@ var defineApp = () => (options) => ({
116
116
  });
117
117
 
118
118
  // src/handlers/define-static-site.ts
119
- var isBucketRoute = (v) => v != null && typeof v === "object" && "bucket" in v && v.bucket != null && typeof v.bucket === "object" && v.bucket.__brand === "effortless-bucket";
120
- var defineStaticSite = () => (options) => ({
121
- __brand: "effortless-static-site",
122
- __spec: options
123
- });
119
+ function defineStaticSite(options) {
120
+ const state = {
121
+ spec: { ...options },
122
+ routes: [],
123
+ middleware: void 0
124
+ };
125
+ const builder = {
126
+ route(pattern, origin, opts) {
127
+ state.routes.push({ pattern, origin, ...opts?.access ? { access: opts.access } : {} });
128
+ return builder;
129
+ },
130
+ middleware(fn) {
131
+ state.middleware = fn;
132
+ return builder;
133
+ },
134
+ build() {
135
+ return {
136
+ __brand: "effortless-static-site",
137
+ __spec: state.spec,
138
+ routes: state.routes,
139
+ ...state.middleware ? { middleware: state.middleware } : {}
140
+ };
141
+ }
142
+ };
143
+ return builder;
144
+ }
124
145
 
125
146
  // src/handlers/define-fifo-queue.ts
126
147
  function defineFifoQueue(options) {
@@ -301,13 +322,14 @@ function defineApi(options) {
301
322
  },
302
323
  routes: []
303
324
  };
304
- const addRoute = (method, path, handler, opts) => {
305
- const routeCache = opts?.cache != null ? resolveCache(opts.cache) : void 0;
325
+ const addRoute = (method, def, handler) => {
326
+ const routeCache = def.cache != null ? resolveCache(def.cache) : void 0;
306
327
  state.routes.push({
307
328
  method,
308
- path,
329
+ path: def.path,
309
330
  onRequest: handler,
310
- ...opts?.public ? { public: true } : {},
331
+ ...def.input ? { schema: def.input } : {},
332
+ ...def.public ? { public: true } : {},
311
333
  ...routeCache ? { cache: routeCache } : {}
312
334
  });
313
335
  };
@@ -324,13 +346,14 @@ function defineApi(options) {
324
346
  ...state.onError ? { onError: state.onError } : {},
325
347
  ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
326
348
  ...state.setup ? { setup: state.setup } : {},
349
+ ...state.authFn ? { authFn: state.authFn } : {},
327
350
  ...state.deps ? { deps: state.deps } : {},
328
351
  ...state.config ? { config: state.config } : {},
329
352
  ...state.static ? { static: state.static } : {}
330
353
  };
331
354
  for (const m of ["get", "post", "put", "patch", "delete"]) {
332
- handler[m] = (path, fn, opts) => {
333
- addRoute(m.toUpperCase(), path, fn, opts);
355
+ handler[m] = (def, fn) => {
356
+ addRoute(m.toUpperCase(), def, fn);
334
357
  handler.routes = state.routes;
335
358
  return handler;
336
359
  };
@@ -350,6 +373,10 @@ function defineApi(options) {
350
373
  state.static = [...state.static ?? [], glob];
351
374
  return builder;
352
375
  },
376
+ auth(fn) {
377
+ state.authFn = fn;
378
+ return builder;
379
+ },
353
380
  setup(fnOrLambda, maybeLambda) {
354
381
  if (typeof fnOrLambda === "function") {
355
382
  state.setup = fnOrLambda;
@@ -367,24 +394,24 @@ function defineApi(options) {
367
394
  state.onCleanup = fn;
368
395
  return builder;
369
396
  },
370
- get(path, handler, opts) {
371
- addRoute("GET", path, handler, opts);
397
+ get(def, fn) {
398
+ addRoute("GET", def, fn);
372
399
  return finalize();
373
400
  },
374
- post(path, handler, opts) {
375
- addRoute("POST", path, handler, opts);
401
+ post(def, fn) {
402
+ addRoute("POST", def, fn);
376
403
  return finalize();
377
404
  },
378
- put(path, handler, opts) {
379
- addRoute("PUT", path, handler, opts);
405
+ put(def, fn) {
406
+ addRoute("PUT", def, fn);
380
407
  return finalize();
381
408
  },
382
- patch(path, handler, opts) {
383
- addRoute("PATCH", path, handler, opts);
409
+ patch(def, fn) {
410
+ addRoute("PATCH", def, fn);
384
411
  return finalize();
385
412
  },
386
- delete(path, handler, opts) {
387
- addRoute("DELETE", path, handler, opts);
413
+ delete(def, fn) {
414
+ addRoute("DELETE", def, fn);
388
415
  return finalize();
389
416
  }
390
417
  };
@@ -522,25 +549,55 @@ function defineMcp(options) {
522
549
  ...options.version ? { version: options.version } : {},
523
550
  ...options.instructions ? { instructions: options.instructions } : {}
524
551
  };
525
- const state = { spec };
552
+ const state = { spec, toolEntries: [], resourceEntries: [], promptEntries: [] };
526
553
  const applyLambdaOptions = (lambda) => {
527
554
  if (Object.keys(lambda).length > 0) {
528
555
  state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
529
556
  }
530
557
  };
531
- const finalize = () => ({
532
- __brand: "effortless-mcp",
533
- __spec: state.spec,
534
- ...state.onError ? { onError: state.onError } : {},
535
- ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
536
- ...state.setup ? { setup: state.setup } : {},
537
- ...state.deps ? { deps: state.deps } : {},
538
- ...state.config ? { config: state.config } : {},
539
- ...state.static ? { static: state.static } : {},
540
- ...state.resources ? { resources: state.resources } : {},
541
- ...state.prompts ? { prompts: state.prompts } : {},
542
- ...state.tools ? { tools: state.tools } : {}
543
- });
558
+ const buildToolsFactory = () => state.toolEntries.length > 0 ? () => Object.fromEntries(state.toolEntries) : void 0;
559
+ const buildResourcesFactory = () => state.resourceEntries.length > 0 ? () => Object.fromEntries(state.resourceEntries) : void 0;
560
+ const buildPromptsFactory = () => state.promptEntries.length > 0 ? () => Object.fromEntries(state.promptEntries) : void 0;
561
+ const finalize = () => {
562
+ const tools = buildToolsFactory();
563
+ const resources = buildResourcesFactory();
564
+ const prompts = buildPromptsFactory();
565
+ return {
566
+ __brand: "effortless-mcp",
567
+ __spec: state.spec,
568
+ ...state.onError ? { onError: state.onError } : {},
569
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
570
+ ...state.setup ? { setup: state.setup } : {},
571
+ ...state.authFn ? { authFn: state.authFn } : {},
572
+ ...state.deps ? { deps: state.deps } : {},
573
+ ...state.config ? { config: state.config } : {},
574
+ ...state.static ? { static: state.static } : {},
575
+ ...resources ? { resources } : {},
576
+ ...prompts ? { prompts } : {},
577
+ ...tools ? { tools } : {}
578
+ };
579
+ };
580
+ const finalizeWithEntries = () => {
581
+ const handler = finalize();
582
+ handler.tool = (def, fn) => {
583
+ state.toolEntries.push([def.name, { description: def.description, input: def.input, handler: fn }]);
584
+ handler.tools = buildToolsFactory();
585
+ return handler;
586
+ };
587
+ handler.resource = (def, fn) => {
588
+ const entry = { name: def.name, ...def.description ? { description: def.description } : {}, ...def.mimeType ? { mimeType: def.mimeType } : {}, handler: fn, ...def.params ? { params: def.params } : {} };
589
+ state.resourceEntries.push([def.uri, entry]);
590
+ handler.resources = buildResourcesFactory();
591
+ return handler;
592
+ };
593
+ handler.prompt = (def, fn) => {
594
+ const entry = { ...def.description ? { description: def.description } : {}, args: def.args, handler: fn };
595
+ state.promptEntries.push([def.name, entry]);
596
+ handler.prompts = buildPromptsFactory();
597
+ return handler;
598
+ };
599
+ return handler;
600
+ };
544
601
  const builder = {
545
602
  deps(fn) {
546
603
  state.deps = fn;
@@ -554,6 +611,10 @@ function defineMcp(options) {
554
611
  state.static = [...state.static ?? [], glob];
555
612
  return builder;
556
613
  },
614
+ auth(fn) {
615
+ state.authFn = fn;
616
+ return builder;
617
+ },
557
618
  setup(fnOrLambda, maybeLambda) {
558
619
  if (typeof fnOrLambda === "function") {
559
620
  state.setup = fnOrLambda;
@@ -571,16 +632,21 @@ function defineMcp(options) {
571
632
  state.onCleanup = fn;
572
633
  return builder;
573
634
  },
574
- resources(fn) {
575
- state.resources = fn;
576
- return builder;
635
+ tool(def, fn) {
636
+ state.toolEntries.push([def.name, { description: def.description, input: def.input, handler: fn }]);
637
+ return finalizeWithEntries();
577
638
  },
578
- prompts(fn) {
579
- state.prompts = fn;
580
- return builder;
639
+ resource(def, fn) {
640
+ const entry = { name: def.name, ...def.description ? { description: def.description } : {}, ...def.mimeType ? { mimeType: def.mimeType } : {}, handler: fn, ...def.params ? { params: def.params } : {} };
641
+ state.resourceEntries.push([def.uri, entry]);
642
+ return finalizeWithEntries();
581
643
  },
582
- tools(fn) {
583
- state.tools = fn;
644
+ prompt(def, fn) {
645
+ const entry = { ...def.description ? { description: def.description } : {}, args: def.args, handler: fn };
646
+ state.promptEntries.push([def.name, entry]);
647
+ return finalizeWithEntries();
648
+ },
649
+ build() {
584
650
  return finalize();
585
651
  }
586
652
  };
@@ -602,7 +668,6 @@ export {
602
668
  generateBase64,
603
669
  generateHex,
604
670
  generateUuid,
605
- isBucketRoute,
606
671
  param,
607
672
  secret,
608
673
  toSeconds