arri 0.30.0 → 0.32.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/cli.cjs CHANGED
@@ -7,18 +7,19 @@ const fs = require('node:fs');
7
7
  const fs$1 = require('node:fs/promises');
8
8
  const arriCodegenUtils = require('arri-codegen-utils');
9
9
  const c12 = require('c12');
10
- const consola = require('consola');
11
10
  const esbuild = require('esbuild');
12
11
  const esbuildPluginReplace = require('esbuild-plugin-replace');
13
12
  const path = require('pathe');
14
13
  const prettier = require('prettier');
15
- const config = require('./shared/arri.31b22fac.cjs');
14
+ const config = require('./shared/arri.7b5179bf.cjs');
15
+ const consola = require('consola');
16
16
  const globby = require('globby');
17
17
  const scule = require('scule');
18
18
  const ofetch = require('ofetch');
19
19
  const listhen = require('@joshmossas/listhen');
20
20
  const chokidar = require('chokidar');
21
21
  const Degit = require('degit');
22
+ const enquirer = require('enquirer');
22
23
  require('h3');
23
24
  require('arri-validate');
24
25
  require('h3-sse');
@@ -39,13 +40,14 @@ function _interopNamespaceCompat(e) {
39
40
 
40
41
  const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs);
41
42
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs$1);
42
- const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
43
43
  const esbuild__namespace = /*#__PURE__*/_interopNamespaceCompat(esbuild);
44
44
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
45
45
  const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
46
46
  const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
47
47
  const Degit__default = /*#__PURE__*/_interopDefaultCompat(Degit);
48
+ const enquirer__default = /*#__PURE__*/_interopDefaultCompat(enquirer);
48
49
 
50
+ const logger = consola.createConsola().withTag("arri");
49
51
  const GEN_APP_FILE = "__arri_app.js";
50
52
  const GEN_SERVER_ENTRY_FILE = "__arri_server.js";
51
53
  const OUT_APP_FILE = "app.mjs";
@@ -205,9 +207,13 @@ const build = citty.defineCommand({
205
207
  await startBuild(config$1, args.skipCodegen);
206
208
  }
207
209
  });
208
- const logger$2 = consola.createConsola().withTag("arri");
209
210
  async function startBuild(config, skipCodeGen = false) {
210
- logger$2.log("Bundling server....");
211
+ logger.log("Bundling server....");
212
+ const appEntry = path__default.resolve(config.rootDir, config.srcDir, config.entry);
213
+ if (!fs.existsSync(path__default.resolve(config.rootDir, config.srcDir, config.entry))) {
214
+ logger.error(`Unabled to find entry at ${appEntry}`);
215
+ process.exit(1);
216
+ }
211
217
  await setupWorkingDir(config);
212
218
  await Promise.all([
213
219
  createAppWithRoutesModule(config),
@@ -216,11 +222,11 @@ async function startBuild(config, skipCodeGen = false) {
216
222
  transpileFiles(config)
217
223
  ]);
218
224
  await bundleAppEntry(config);
219
- logger$2.log("Finished bundling");
220
- const clientCount = config.clientGenerators.length;
225
+ logger.log("Finished bundling");
226
+ const clientCount = config.generators.length;
221
227
  const codegenModule = path__default.resolve(config.rootDir, ".output", OUT_CODEGEN);
222
228
  if (!skipCodeGen) {
223
- logger$2.log("Generating Arri app definition (__definition.json)");
229
+ logger.log("Generating Arri app definition (__definition.json)");
224
230
  node_child_process.execSync(`node ${codegenModule}`, { env: process.env });
225
231
  const defJson = path__default.resolve(
226
232
  config.rootDir,
@@ -229,22 +235,22 @@ async function startBuild(config, skipCodeGen = false) {
229
235
  );
230
236
  const def = JSON.parse(fs.readFileSync(defJson, { encoding: "utf-8" }));
231
237
  if (arriCodegenUtils.isAppDefinition(def) && clientCount > 0) {
232
- logger$2.log(`Generating ${clientCount} clients`);
238
+ logger.log(`Generating ${clientCount} clients`);
233
239
  await Promise.all(
234
- config.clientGenerators.map((plugin) => plugin.generator(def))
240
+ config.generators.map((plugin) => plugin.generator(def))
235
241
  );
236
- logger$2.log(`${clientCount} clients generated`);
242
+ logger.log(`${clientCount} clients generated`);
237
243
  } else {
238
- logger$2.warn(
244
+ logger.warn(
239
245
  "No client generators specified. Skipping client codegen."
240
246
  );
241
247
  }
242
248
  } else {
243
- logger$2.log("Skipping codegen");
249
+ logger.log("Skipping codegen");
244
250
  }
245
- logger$2.log("Cleaning up files");
251
+ logger.log("Cleaning up files");
246
252
  await fs__default.rm(codegenModule);
247
- logger$2.success(
253
+ logger.success(
248
254
  `Build finished! You can start your server by running "node .output/${OUT_SERVER_ENTRY}"`
249
255
  );
250
256
  }
@@ -403,18 +409,30 @@ const codegen = citty.defineCommand({
403
409
  }
404
410
  const configPath = path__default.resolve(args.config);
405
411
  const { config: config$1 } = await c12.loadConfig({ configFile: configPath });
406
- if (!config.isResolvedArriConfig(config$1)) {
412
+ if (!config.isArriConfig(config$1)) {
407
413
  throw new Error(`Invalid arri config at ${args.config}`);
408
414
  }
409
- consola__default.info(`Generating ${config$1.clientGenerators.length} clients`);
415
+ if (!config$1.generators?.length) {
416
+ logger.warn(`No generators specified in ${args.config}`);
417
+ process.exit(1);
418
+ }
419
+ logger.info(`Generating ${config$1.generators?.length} client(s)`);
410
420
  await Promise.allSettled(
411
421
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
412
- config$1.clientGenerators.map((gen) => gen.generator(def))
422
+ config$1.generators.map(
423
+ (gen) => gen.generator(
424
+ def ?? {
425
+ arriSchemaVersion: "0.0.4",
426
+ procedures: {},
427
+ models: {}
428
+ }
429
+ )
430
+ )
413
431
  );
432
+ process.exit(0);
414
433
  }
415
434
  });
416
435
 
417
- const logger$1 = consola.createConsola().withTag("arri");
418
436
  const dev = citty.defineCommand({
419
437
  meta: {
420
438
  name: "dev",
@@ -436,13 +454,21 @@ const dev = citty.defineCommand({
436
454
  if (!config.isResolvedArriConfig(config$1)) {
437
455
  throw new Error("Unable to find config");
438
456
  }
457
+ const appEntry = path__default.resolve(
458
+ config$1.rootDir,
459
+ config$1.srcDir,
460
+ config$1.entry
461
+ );
462
+ if (!fs.existsSync(appEntry)) {
463
+ throw new Error(`Unable to find entry at ${appEntry}`);
464
+ }
439
465
  await startDevServer(config$1);
440
466
  }
441
467
  });
442
468
  const startListener = (config, showQr = false) => listhen.listenAndWatch(path__default.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY), {
443
469
  public: true,
444
470
  port: config.port,
445
- logger: logger$1,
471
+ logger,
446
472
  qr: showQr,
447
473
  https: config.https,
448
474
  http2: config.http2
@@ -517,17 +543,17 @@ async function startDevServer(config) {
517
543
  await createAppWithRoutesModule(config);
518
544
  let bundleCreated = false;
519
545
  try {
520
- logger$1.log(
546
+ logger.log(
521
547
  "Change detected. Bundling files and restarting server...."
522
548
  );
523
549
  await transpileFiles(config);
524
550
  await bundleFiles.rebuild();
525
551
  bundleCreated = true;
526
552
  } catch (err) {
527
- logger$1.error("ERROR", err);
553
+ logger.error("ERROR", err);
528
554
  bundleCreated = false;
529
555
  }
530
- if (bundleCreated && config.clientGenerators.length) {
556
+ if (bundleCreated && config.generators.length) {
531
557
  setTimeout(async () => {
532
558
  await generateClients(config);
533
559
  bundleCreated = false;
@@ -551,14 +577,14 @@ async function generateClients(config$1) {
551
577
  if (!arriCodegenUtils.isAppDefinition(result)) {
552
578
  return;
553
579
  }
554
- logger$1.log(`Generating client code...`);
555
- const clientCount = config$1.clientGenerators.length;
580
+ logger.log(`Generating client code...`);
581
+ const clientCount = config$1.generators.length;
556
582
  await Promise.all(
557
- config$1.clientGenerators.map(
558
- (generator) => generator.generator(result)
583
+ config$1.generators.map(
584
+ (generator) => generator.generator(result, true)
559
585
  )
560
586
  );
561
- logger$1.success(
587
+ logger.success(
562
588
  `Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
563
589
  );
564
590
  } catch (err) {
@@ -579,7 +605,6 @@ export default app.h3App;`;
579
605
  );
580
606
  }
581
607
 
582
- const logger = consola.createConsola();
583
608
  const init = citty.defineCommand({
584
609
  meta: {
585
610
  name: "Init",
@@ -596,9 +621,44 @@ const init = citty.defineCommand({
596
621
  default: false,
597
622
  alias: "f",
598
623
  description: "Force created a project when if a directory already exists"
624
+ },
625
+ type: {
626
+ type: "string",
627
+ description: `"app" | "plugin"`
599
628
  }
600
629
  },
601
630
  async run(context) {
631
+ let type;
632
+ switch (context.args.type?.toLowerCase()) {
633
+ case "app":
634
+ type = "app";
635
+ break;
636
+ case "plugin":
637
+ type = "plugin";
638
+ break;
639
+ }
640
+ if (!type) {
641
+ const { projectType } = await enquirer__default.prompt([
642
+ {
643
+ type: "select",
644
+ name: "projectType",
645
+ message: "What kind of project do you want to initialize?",
646
+ choices: ["application", "generator plugin"]
647
+ }
648
+ ]);
649
+ switch (projectType) {
650
+ case "application":
651
+ type = "app";
652
+ break;
653
+ case "generator plugin":
654
+ type = "plugin";
655
+ break;
656
+ default:
657
+ throw new Error(
658
+ `Unknown project type "${projectType}"`
659
+ );
660
+ }
661
+ }
602
662
  const dir = path__default.resolve(context.args.dir);
603
663
  if (!fs__default$1.existsSync(dir)) {
604
664
  fs__default$1.mkdirSync(dir);
@@ -610,42 +670,71 @@ const init = citty.defineCommand({
610
670
  );
611
671
  process.exit(1);
612
672
  }
613
- const degit = Degit__default("https://github.com/modiimedia/arri-starters", {
614
- force: context.args.force
615
- });
616
- await degit.clone(dir);
617
- fs.rmSync(path__default.resolve(dir, "pnpm-lock.yaml"));
618
- const packageJson = JSON.parse(
619
- fs.readFileSync(path__default.resolve(dir, "package.json"), {
620
- encoding: "utf-8"
621
- })
622
- );
623
- packageJson.name = scule.kebabCase(context.args.dir);
624
- packageJson.description = "An RPC server created with Arri RPC";
625
- packageJson.private = true;
626
- delete packageJson.license;
627
- delete packageJson.main;
628
- delete packageJson.author;
629
- delete packageJson.tags;
630
- fs.writeFileSync(
631
- path__default.resolve(dir, "package.json"),
632
- await prettier__default.format(JSON.stringify(packageJson), {
633
- parser: "json",
634
- tabWidth: 4,
635
- semi: true,
636
- endOfLine: "lf",
637
- trailingComma: "all"
638
- })
639
- );
640
- consola__default.log(
641
- `Project initialized in ${context.args.dir}. To get started:
642
- cd ${context.args.dir}
643
- npm install
644
- npm run dev`
645
- );
673
+ switch (type) {
674
+ case "app":
675
+ await initApp(context.args.dir, context.args.force);
676
+ break;
677
+ case "plugin":
678
+ await initPlugin(context.args.dir, context.args.force);
679
+ break;
680
+ default:
681
+ logger.error(`Unknown app type: '${type}'"`);
682
+ break;
683
+ }
646
684
  process.exit(0);
647
685
  }
648
686
  });
687
+ async function initApp(dir, force) {
688
+ const degit = Degit__default("modiimedia/arri-starters/app-starter-ts", {
689
+ force
690
+ });
691
+ await degit.clone(dir);
692
+ fs.rmSync(path__default.resolve(dir, "pnpm-lock.yaml"));
693
+ const packageJson = JSON.parse(
694
+ fs.readFileSync(path__default.resolve(dir, "package.json"), {
695
+ encoding: "utf-8"
696
+ })
697
+ );
698
+ packageJson.name = scule.kebabCase(dir);
699
+ packageJson.description = "An RPC server created with Arri RPC";
700
+ packageJson.private = true;
701
+ delete packageJson.license;
702
+ delete packageJson.main;
703
+ delete packageJson.author;
704
+ delete packageJson.tags;
705
+ fs.writeFileSync(
706
+ path__default.resolve(dir, "package.json"),
707
+ await prettier__default.format(JSON.stringify(packageJson), {
708
+ parser: "json",
709
+ tabWidth: 4,
710
+ semi: true,
711
+ endOfLine: "lf",
712
+ trailingComma: "all"
713
+ })
714
+ );
715
+ logger.success(`Project initialized in ${dir}!`);
716
+ logger.info(`To get started:
717
+ - cd ${dir}
718
+ - pnpm install
719
+ - pnpm run dev`);
720
+ }
721
+ async function initPlugin(dir, force) {
722
+ const name = scule.kebabCase(dir);
723
+ const degit = Degit__default("modiimedia/arri-starters/generator-starter", {
724
+ force
725
+ });
726
+ await degit.clone(dir);
727
+ fs.rmSync(path__default.resolve(dir, "pnpm-lock.yaml"));
728
+ let packageJson = fs.readFileSync(path__default.resolve(dir, "package.json"), {
729
+ encoding: "utf8"
730
+ });
731
+ packageJson = packageJson.replace(`"arri-generator-name"`, `"${name}"`);
732
+ fs.writeFileSync(path__default.resolve(dir, "package.json"), packageJson);
733
+ logger.success(`Project initialized in ${dir}!`);
734
+ logger.info(`To get started:
735
+ - cd ${dir}
736
+ - pnpm install`);
737
+ }
649
738
 
650
739
  const main = citty.defineCommand({
651
740
  subCommands: {
package/dist/cli.mjs CHANGED
@@ -5,23 +5,25 @@ import fs$1, { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
5
5
  import fs from 'node:fs/promises';
6
6
  import { removeDisallowedChars, isAppDefinition } from 'arri-codegen-utils';
7
7
  import { loadConfig } from 'c12';
8
- import consola, { createConsola } from 'consola';
9
8
  import * as esbuild from 'esbuild';
10
9
  import { build as build$1 } from 'esbuild';
11
10
  import { replace } from 'esbuild-plugin-replace';
12
11
  import path from 'pathe';
13
12
  import prettier from 'prettier';
14
- import { n as defaultConfig, m as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.d9f65487.mjs';
13
+ import { o as defaultConfig, m as isArriConfig, n as isResolvedArriConfig, a as DEV_DEFINITION_ENDPOINT } from './shared/arri.bbe2aa44.mjs';
14
+ import { createConsola } from 'consola';
15
15
  import { globby } from 'globby';
16
16
  import { camelCase, kebabCase } from 'scule';
17
17
  import { ofetch } from 'ofetch';
18
18
  import { listenAndWatch } from '@joshmossas/listhen';
19
19
  import chokidar from 'chokidar';
20
20
  import Degit from 'degit';
21
+ import enquirer from 'enquirer';
21
22
  import 'h3';
22
23
  import 'arri-validate';
23
24
  import 'h3-sse';
24
25
 
26
+ const logger = createConsola().withTag("arri");
25
27
  const GEN_APP_FILE = "__arri_app.js";
26
28
  const GEN_SERVER_ENTRY_FILE = "__arri_server.js";
27
29
  const OUT_APP_FILE = "app.mjs";
@@ -181,9 +183,13 @@ const build = defineCommand({
181
183
  await startBuild(config, args.skipCodegen);
182
184
  }
183
185
  });
184
- const logger$2 = createConsola().withTag("arri");
185
186
  async function startBuild(config, skipCodeGen = false) {
186
- logger$2.log("Bundling server....");
187
+ logger.log("Bundling server....");
188
+ const appEntry = path.resolve(config.rootDir, config.srcDir, config.entry);
189
+ if (!existsSync(path.resolve(config.rootDir, config.srcDir, config.entry))) {
190
+ logger.error(`Unabled to find entry at ${appEntry}`);
191
+ process.exit(1);
192
+ }
187
193
  await setupWorkingDir(config);
188
194
  await Promise.all([
189
195
  createAppWithRoutesModule(config),
@@ -192,11 +198,11 @@ async function startBuild(config, skipCodeGen = false) {
192
198
  transpileFiles(config)
193
199
  ]);
194
200
  await bundleAppEntry(config);
195
- logger$2.log("Finished bundling");
196
- const clientCount = config.clientGenerators.length;
201
+ logger.log("Finished bundling");
202
+ const clientCount = config.generators.length;
197
203
  const codegenModule = path.resolve(config.rootDir, ".output", OUT_CODEGEN);
198
204
  if (!skipCodeGen) {
199
- logger$2.log("Generating Arri app definition (__definition.json)");
205
+ logger.log("Generating Arri app definition (__definition.json)");
200
206
  execSync(`node ${codegenModule}`, { env: process.env });
201
207
  const defJson = path.resolve(
202
208
  config.rootDir,
@@ -205,22 +211,22 @@ async function startBuild(config, skipCodeGen = false) {
205
211
  );
206
212
  const def = JSON.parse(readFileSync(defJson, { encoding: "utf-8" }));
207
213
  if (isAppDefinition(def) && clientCount > 0) {
208
- logger$2.log(`Generating ${clientCount} clients`);
214
+ logger.log(`Generating ${clientCount} clients`);
209
215
  await Promise.all(
210
- config.clientGenerators.map((plugin) => plugin.generator(def))
216
+ config.generators.map((plugin) => plugin.generator(def))
211
217
  );
212
- logger$2.log(`${clientCount} clients generated`);
218
+ logger.log(`${clientCount} clients generated`);
213
219
  } else {
214
- logger$2.warn(
220
+ logger.warn(
215
221
  "No client generators specified. Skipping client codegen."
216
222
  );
217
223
  }
218
224
  } else {
219
- logger$2.log("Skipping codegen");
225
+ logger.log("Skipping codegen");
220
226
  }
221
- logger$2.log("Cleaning up files");
227
+ logger.log("Cleaning up files");
222
228
  await fs.rm(codegenModule);
223
- logger$2.success(
229
+ logger.success(
224
230
  `Build finished! You can start your server by running "node .output/${OUT_SERVER_ENTRY}"`
225
231
  );
226
232
  }
@@ -379,18 +385,30 @@ const codegen = defineCommand({
379
385
  }
380
386
  const configPath = path.resolve(args.config);
381
387
  const { config } = await loadConfig({ configFile: configPath });
382
- if (!isResolvedArriConfig(config)) {
388
+ if (!isArriConfig(config)) {
383
389
  throw new Error(`Invalid arri config at ${args.config}`);
384
390
  }
385
- consola.info(`Generating ${config.clientGenerators.length} clients`);
391
+ if (!config.generators?.length) {
392
+ logger.warn(`No generators specified in ${args.config}`);
393
+ process.exit(1);
394
+ }
395
+ logger.info(`Generating ${config.generators?.length} client(s)`);
386
396
  await Promise.allSettled(
387
397
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
388
- config.clientGenerators.map((gen) => gen.generator(def))
398
+ config.generators.map(
399
+ (gen) => gen.generator(
400
+ def ?? {
401
+ arriSchemaVersion: "0.0.4",
402
+ procedures: {},
403
+ models: {}
404
+ }
405
+ )
406
+ )
389
407
  );
408
+ process.exit(0);
390
409
  }
391
410
  });
392
411
 
393
- const logger$1 = createConsola().withTag("arri");
394
412
  const dev = defineCommand({
395
413
  meta: {
396
414
  name: "dev",
@@ -412,13 +430,21 @@ const dev = defineCommand({
412
430
  if (!isResolvedArriConfig(config)) {
413
431
  throw new Error("Unable to find config");
414
432
  }
433
+ const appEntry = path.resolve(
434
+ config.rootDir,
435
+ config.srcDir,
436
+ config.entry
437
+ );
438
+ if (!existsSync(appEntry)) {
439
+ throw new Error(`Unable to find entry at ${appEntry}`);
440
+ }
415
441
  await startDevServer(config);
416
442
  }
417
443
  });
418
444
  const startListener = (config, showQr = false) => listenAndWatch(path.resolve(config.rootDir, ".output", OUT_SERVER_ENTRY), {
419
445
  public: true,
420
446
  port: config.port,
421
- logger: logger$1,
447
+ logger,
422
448
  qr: showQr,
423
449
  https: config.https,
424
450
  http2: config.http2
@@ -493,17 +519,17 @@ async function startDevServer(config) {
493
519
  await createAppWithRoutesModule(config);
494
520
  let bundleCreated = false;
495
521
  try {
496
- logger$1.log(
522
+ logger.log(
497
523
  "Change detected. Bundling files and restarting server...."
498
524
  );
499
525
  await transpileFiles(config);
500
526
  await bundleFiles.rebuild();
501
527
  bundleCreated = true;
502
528
  } catch (err) {
503
- logger$1.error("ERROR", err);
529
+ logger.error("ERROR", err);
504
530
  bundleCreated = false;
505
531
  }
506
- if (bundleCreated && config.clientGenerators.length) {
532
+ if (bundleCreated && config.generators.length) {
507
533
  setTimeout(async () => {
508
534
  await generateClients(config);
509
535
  bundleCreated = false;
@@ -527,14 +553,14 @@ async function generateClients(config) {
527
553
  if (!isAppDefinition(result)) {
528
554
  return;
529
555
  }
530
- logger$1.log(`Generating client code...`);
531
- const clientCount = config.clientGenerators.length;
556
+ logger.log(`Generating client code...`);
557
+ const clientCount = config.generators.length;
532
558
  await Promise.all(
533
- config.clientGenerators.map(
534
- (generator) => generator.generator(result)
559
+ config.generators.map(
560
+ (generator) => generator.generator(result, true)
535
561
  )
536
562
  );
537
- logger$1.success(
563
+ logger.success(
538
564
  `Generated ${clientCount} client${clientCount === 1 ? "" : "s"}`
539
565
  );
540
566
  } catch (err) {
@@ -555,7 +581,6 @@ export default app.h3App;`;
555
581
  );
556
582
  }
557
583
 
558
- const logger = createConsola();
559
584
  const init = defineCommand({
560
585
  meta: {
561
586
  name: "Init",
@@ -572,9 +597,44 @@ const init = defineCommand({
572
597
  default: false,
573
598
  alias: "f",
574
599
  description: "Force created a project when if a directory already exists"
600
+ },
601
+ type: {
602
+ type: "string",
603
+ description: `"app" | "plugin"`
575
604
  }
576
605
  },
577
606
  async run(context) {
607
+ let type;
608
+ switch (context.args.type?.toLowerCase()) {
609
+ case "app":
610
+ type = "app";
611
+ break;
612
+ case "plugin":
613
+ type = "plugin";
614
+ break;
615
+ }
616
+ if (!type) {
617
+ const { projectType } = await enquirer.prompt([
618
+ {
619
+ type: "select",
620
+ name: "projectType",
621
+ message: "What kind of project do you want to initialize?",
622
+ choices: ["application", "generator plugin"]
623
+ }
624
+ ]);
625
+ switch (projectType) {
626
+ case "application":
627
+ type = "app";
628
+ break;
629
+ case "generator plugin":
630
+ type = "plugin";
631
+ break;
632
+ default:
633
+ throw new Error(
634
+ `Unknown project type "${projectType}"`
635
+ );
636
+ }
637
+ }
578
638
  const dir = path.resolve(context.args.dir);
579
639
  if (!fs$1.existsSync(dir)) {
580
640
  fs$1.mkdirSync(dir);
@@ -586,42 +646,71 @@ const init = defineCommand({
586
646
  );
587
647
  process.exit(1);
588
648
  }
589
- const degit = Degit("https://github.com/modiimedia/arri-starters", {
590
- force: context.args.force
591
- });
592
- await degit.clone(dir);
593
- rmSync(path.resolve(dir, "pnpm-lock.yaml"));
594
- const packageJson = JSON.parse(
595
- readFileSync(path.resolve(dir, "package.json"), {
596
- encoding: "utf-8"
597
- })
598
- );
599
- packageJson.name = kebabCase(context.args.dir);
600
- packageJson.description = "An RPC server created with Arri RPC";
601
- packageJson.private = true;
602
- delete packageJson.license;
603
- delete packageJson.main;
604
- delete packageJson.author;
605
- delete packageJson.tags;
606
- writeFileSync(
607
- path.resolve(dir, "package.json"),
608
- await prettier.format(JSON.stringify(packageJson), {
609
- parser: "json",
610
- tabWidth: 4,
611
- semi: true,
612
- endOfLine: "lf",
613
- trailingComma: "all"
614
- })
615
- );
616
- consola.log(
617
- `Project initialized in ${context.args.dir}. To get started:
618
- cd ${context.args.dir}
619
- npm install
620
- npm run dev`
621
- );
649
+ switch (type) {
650
+ case "app":
651
+ await initApp(context.args.dir, context.args.force);
652
+ break;
653
+ case "plugin":
654
+ await initPlugin(context.args.dir, context.args.force);
655
+ break;
656
+ default:
657
+ logger.error(`Unknown app type: '${type}'"`);
658
+ break;
659
+ }
622
660
  process.exit(0);
623
661
  }
624
662
  });
663
+ async function initApp(dir, force) {
664
+ const degit = Degit("modiimedia/arri-starters/app-starter-ts", {
665
+ force
666
+ });
667
+ await degit.clone(dir);
668
+ rmSync(path.resolve(dir, "pnpm-lock.yaml"));
669
+ const packageJson = JSON.parse(
670
+ readFileSync(path.resolve(dir, "package.json"), {
671
+ encoding: "utf-8"
672
+ })
673
+ );
674
+ packageJson.name = kebabCase(dir);
675
+ packageJson.description = "An RPC server created with Arri RPC";
676
+ packageJson.private = true;
677
+ delete packageJson.license;
678
+ delete packageJson.main;
679
+ delete packageJson.author;
680
+ delete packageJson.tags;
681
+ writeFileSync(
682
+ path.resolve(dir, "package.json"),
683
+ await prettier.format(JSON.stringify(packageJson), {
684
+ parser: "json",
685
+ tabWidth: 4,
686
+ semi: true,
687
+ endOfLine: "lf",
688
+ trailingComma: "all"
689
+ })
690
+ );
691
+ logger.success(`Project initialized in ${dir}!`);
692
+ logger.info(`To get started:
693
+ - cd ${dir}
694
+ - pnpm install
695
+ - pnpm run dev`);
696
+ }
697
+ async function initPlugin(dir, force) {
698
+ const name = kebabCase(dir);
699
+ const degit = Degit("modiimedia/arri-starters/generator-starter", {
700
+ force
701
+ });
702
+ await degit.clone(dir);
703
+ rmSync(path.resolve(dir, "pnpm-lock.yaml"));
704
+ let packageJson = readFileSync(path.resolve(dir, "package.json"), {
705
+ encoding: "utf8"
706
+ });
707
+ packageJson = packageJson.replace(`"arri-generator-name"`, `"${name}"`);
708
+ writeFileSync(path.resolve(dir, "package.json"), packageJson);
709
+ logger.success(`Project initialized in ${dir}!`);
710
+ logger.info(`To get started:
711
+ - cd ${dir}
712
+ - pnpm install`);
713
+ }
625
714
 
626
715
  const main = defineCommand({
627
716
  subCommands: {
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const config = require('./shared/arri.31b22fac.cjs');
3
+ const config = require('./shared/arri.7b5179bf.cjs');
4
4
  const h3 = require('h3');
5
5
  require('arri-codegen-utils');
6
6
  require('arri-validate');
@@ -15,7 +15,8 @@ exports.DEV_DEFINITION_ENDPOINT = config.DEV_DEFINITION_ENDPOINT;
15
15
  exports.DEV_ENDPOINT_ROOT = config.DEV_ENDPOINT_ROOT;
16
16
  exports.ErrorResponse = config.ErrorResponse;
17
17
  exports.EventStreamConnection = config.EventStreamConnection;
18
- exports.createRpcDefinition = config.createRpcDefinition;
18
+ exports.createAppDefinition = config.createAppDefinition;
19
+ exports.createHttpRpcDefinition = config.createHttpRpcDefinition;
19
20
  exports.defaultConfig = config.defaultConfig;
20
21
  exports.defineConfig = config.defineConfig;
21
22
  exports.defineError = config.defineError;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
1
+ import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
@@ -108,7 +108,7 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
108
108
  name: string;
109
109
  }, opts: RouteOptions): void;
110
110
 
111
- type RpcParamSchema<TObjectInner = any, TRecordInner extends ASchema = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ARecordSchema<TRecordInner> | ADiscriminatorSchema<TDiscriminatorInner>;
111
+ type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
112
112
  declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
113
113
  interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
114
114
  name: string;
@@ -144,7 +144,7 @@ type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, even
144
144
  type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
145
145
  declare function isRpc(input: unknown): input is Rpc<any, any>;
146
146
  declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
147
- declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): RpcDefinition;
147
+ declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
148
148
  declare function getRpcPath(rpcName: string, prefix?: string): string;
149
149
  declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
150
150
  declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
@@ -171,6 +171,7 @@ declare class ArriRouter implements ArriRouterBase {
171
171
  declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
172
172
  declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
173
173
  type ModelMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
174
+ declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
174
175
  declare class ArriApp implements ArriRouterBase {
175
176
  __isArri__: boolean;
176
177
  readonly h3App: App;
@@ -211,8 +212,8 @@ interface ArriOptions {
211
212
  }
212
213
 
213
214
  interface ArriConfig {
214
- port: number;
215
- entry: string;
215
+ port?: number;
216
+ entry?: string;
216
217
  serverEntry?: string;
217
218
  rootDir?: string;
218
219
  srcDir?: string;
@@ -221,7 +222,7 @@ interface ArriConfig {
221
222
  * this defaults to ["***\/*\*.rpc.ts"]
222
223
  */
223
224
  procedureGlobPatterns?: string[];
224
- clientGenerators?: Array<ClientGenerator<any>>;
225
+ generators?: Array<ClientGenerator<any>>;
225
226
  buildDir?: string;
226
227
  esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
227
228
  https?: {
@@ -237,4 +238,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
237
238
  declare const defaultConfig: Required<ArriConfig>;
238
239
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
239
240
 
240
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
241
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
1
+ import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
@@ -108,7 +108,7 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
108
108
  name: string;
109
109
  }, opts: RouteOptions): void;
110
110
 
111
- type RpcParamSchema<TObjectInner = any, TRecordInner extends ASchema = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ARecordSchema<TRecordInner> | ADiscriminatorSchema<TDiscriminatorInner>;
111
+ type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
112
112
  declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
113
113
  interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
114
114
  name: string;
@@ -144,7 +144,7 @@ type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, even
144
144
  type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
145
145
  declare function isRpc(input: unknown): input is Rpc<any, any>;
146
146
  declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
147
- declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): RpcDefinition;
147
+ declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
148
148
  declare function getRpcPath(rpcName: string, prefix?: string): string;
149
149
  declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
150
150
  declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
@@ -171,6 +171,7 @@ declare class ArriRouter implements ArriRouterBase {
171
171
  declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
172
172
  declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
173
173
  type ModelMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
174
+ declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
174
175
  declare class ArriApp implements ArriRouterBase {
175
176
  __isArri__: boolean;
176
177
  readonly h3App: App;
@@ -211,8 +212,8 @@ interface ArriOptions {
211
212
  }
212
213
 
213
214
  interface ArriConfig {
214
- port: number;
215
- entry: string;
215
+ port?: number;
216
+ entry?: string;
216
217
  serverEntry?: string;
217
218
  rootDir?: string;
218
219
  srcDir?: string;
@@ -221,7 +222,7 @@ interface ArriConfig {
221
222
  * this defaults to ["***\/*\*.rpc.ts"]
222
223
  */
223
224
  procedureGlobPatterns?: string[];
224
- clientGenerators?: Array<ClientGenerator<any>>;
225
+ generators?: Array<ClientGenerator<any>>;
225
226
  buildDir?: string;
226
227
  esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
227
228
  https?: {
@@ -237,4 +238,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
237
238
  declare const defaultConfig: Required<ArriConfig>;
238
239
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
239
240
 
240
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
241
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { HttpMethod, RpcHttpMethod, RpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
- import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ARecordSchema, ADiscriminatorSchema } from 'arri-validate';
1
+ import { HttpMethod, RpcHttpMethod, HttpRpcDefinition, SchemaFormProperties, SchemaFormDiscriminator, SchemaFormValues, AppDefinition, ClientGenerator } from 'arri-codegen-utils';
2
+ import { AObjectSchema, ASchema, InferType, a, ValidationError, ValueError, ADiscriminatorSchema } from 'arri-validate';
3
3
  import { H3EventContext, H3Event, Router, H3Error, App } from 'h3';
4
4
  export * from 'h3';
5
5
  import { EventStream } from 'h3-sse';
@@ -108,7 +108,7 @@ declare function registerEventStreamRpc(router: Router, path: string, procedure:
108
108
  name: string;
109
109
  }, opts: RouteOptions): void;
110
110
 
111
- type RpcParamSchema<TObjectInner = any, TRecordInner extends ASchema = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ARecordSchema<TRecordInner> | ADiscriminatorSchema<TDiscriminatorInner>;
111
+ type RpcParamSchema<TObjectInner = any, TDiscriminatorInner = any> = AObjectSchema<TObjectInner> | ADiscriminatorSchema<TDiscriminatorInner>;
112
112
  declare function isRpcParamSchema(input: unknown): input is RpcParamSchema;
113
113
  interface NamedRpc<TIsEventStream extends boolean = false, TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined = undefined> extends Rpc<TIsEventStream, TParams, TResponse> {
114
114
  name: string;
@@ -144,7 +144,7 @@ type RpcHandler<TParams, TResponse> = (context: RpcHandlerContext<TParams>, even
144
144
  type RpcPostHandler<TParams, TResponse> = (context: RpcPostHandlerContext<TParams, TResponse>, event: RpcPostEvent<TParams, TResponse>) => any;
145
145
  declare function isRpc(input: unknown): input is Rpc<any, any>;
146
146
  declare function defineRpc<TParams extends RpcParamSchema | undefined = undefined, TResponse extends RpcParamSchema | undefined | never = undefined>(config: HttpRpc<TParams, TResponse>): Rpc<false, TParams, TResponse>;
147
- declare function createRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): RpcDefinition;
147
+ declare function createHttpRpcDefinition(rpcName: string, httpPath: string, procedure: Rpc<any, any, any>): HttpRpcDefinition;
148
148
  declare function getRpcPath(rpcName: string, prefix?: string): string;
149
149
  declare function getRpcParamName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
150
150
  declare function getRpcResponseName(rpcName: string, procedure: Rpc<any, any, any>): string | undefined;
@@ -171,6 +171,7 @@ declare class ArriRouter implements ArriRouterBase {
171
171
  declare const DEV_ENDPOINT_ROOT = "/__arri_dev__";
172
172
  declare const DEV_DEFINITION_ENDPOINT = "/__arri_dev__/__definition";
173
173
  type ModelMap = Record<string, SchemaFormProperties | SchemaFormDiscriminator | SchemaFormValues>;
174
+ declare const createAppDefinition: (def: AppDefinition) => AppDefinition;
174
175
  declare class ArriApp implements ArriRouterBase {
175
176
  __isArri__: boolean;
176
177
  readonly h3App: App;
@@ -211,8 +212,8 @@ interface ArriOptions {
211
212
  }
212
213
 
213
214
  interface ArriConfig {
214
- port: number;
215
- entry: string;
215
+ port?: number;
216
+ entry?: string;
216
217
  serverEntry?: string;
217
218
  rootDir?: string;
218
219
  srcDir?: string;
@@ -221,7 +222,7 @@ interface ArriConfig {
221
222
  * this defaults to ["***\/*\*.rpc.ts"]
222
223
  */
223
224
  procedureGlobPatterns?: string[];
224
- clientGenerators?: Array<ClientGenerator<any>>;
225
+ generators?: Array<ClientGenerator<any>>;
225
226
  buildDir?: string;
226
227
  esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
227
228
  https?: {
@@ -237,4 +238,4 @@ type ResolvedArriConfig = Required<ArriConfig>;
237
238
  declare const defaultConfig: Required<ArriConfig>;
238
239
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
239
240
 
240
- export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
241
+ export { ArriApp, type ArriConfig, type ArriOptions, type ArriRoute, ArriRouter, type ArriRouterBase, DEV_DEFINITION_ENDPOINT, DEV_ENDPOINT_ROOT, ErrorResponse, EventStreamConnection, type EventStreamConnectionOptions, type EventStreamRpc, type EventStreamRpcHandler, type EventStreamRpcHandlerContext, type ExtractParam, type ExtractParams, type HandlerContext, type HttpRpc, type Middleware, type MiddlewareEvent, type MiddlewareEventContext, type ModelMap, type NamedRpc, type PostRouteEvent, type PostRouteEventContext, type ResolvedArriConfig, type RouteEvent, type RouteEventContext, type RouteOptions, type Rpc, type RpcEvent, type RpcHandler, type RpcHandlerContext, type RpcParamSchema, type RpcPostEvent, type RpcPostHandler, type RpcPostHandlerContext, type StatusCode, createAppDefinition, createHttpRpcDefinition, defaultConfig, defineConfig, defineError, defineEventStreamRpc, defineMiddleware, defineRoute, defineRpc, errorResponseFromValidationErrors, getRpcParamName, getRpcPath, getRpcResponseName, handleH3Error, handleRoute, isArriConfig, isEventStreamRpc, isResolvedArriConfig, isRpc, isRpcParamSchema, registerEventStreamRpc, registerRoute, registerRpc, validateRpcRequestInput };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ArriApp, p as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, x as EventStreamConnection, c as createRpcDefinition, n as defaultConfig, o as defineConfig, h as defineError, u as defineEventStreamRpc, q as defineRoute, d as defineRpc, j as errorResponseFromValidationErrors, e as getRpcParamName, g as getRpcPath, f as getRpcResponseName, k as handleH3Error, t as handleRoute, l as isArriConfig, w as isEventStreamRpc, m as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, y as registerEventStreamRpc, s as registerRoute, r as registerRpc, v as validateRpcRequestInput } from './shared/arri.d9f65487.mjs';
1
+ export { A as ArriApp, q as ArriRouter, a as DEV_DEFINITION_ENDPOINT, D as DEV_ENDPOINT_ROOT, E as ErrorResponse, y as EventStreamConnection, c as createAppDefinition, e as createHttpRpcDefinition, o as defaultConfig, p as defineConfig, j as defineError, w as defineEventStreamRpc, s as defineRoute, d as defineRpc, k as errorResponseFromValidationErrors, f as getRpcParamName, g as getRpcPath, h as getRpcResponseName, l as handleH3Error, u as handleRoute, m as isArriConfig, x as isEventStreamRpc, n as isResolvedArriConfig, b as isRpc, i as isRpcParamSchema, z as registerEventStreamRpc, t as registerRoute, r as registerRpc, v as validateRpcRequestInput } from './shared/arri.bbe2aa44.mjs';
2
2
  export * from 'h3';
3
3
  import 'arri-codegen-utils';
4
4
  import 'arri-validate';
@@ -212,7 +212,7 @@ async function handleH3Error(err, event, onError) {
212
212
  }
213
213
 
214
214
  function isRpcParamSchema(input) {
215
- return arriValidate.isAObjectSchema(input) || arriValidate.isARecordSchema(input) || arriValidate.isADiscriminatorSchema(input);
215
+ return arriValidate.isAObjectSchema(input) || arriValidate.isADiscriminatorSchema(input);
216
216
  }
217
217
  function isRpc(input) {
218
218
  return typeof input === "object" && input !== null && "method" in input && arriCodegenUtils.isRpcHttpMethod(input.method) && "handler" in input && typeof input.handler === "function";
@@ -220,7 +220,7 @@ function isRpc(input) {
220
220
  function defineRpc(config) {
221
221
  return config;
222
222
  }
223
- function createRpcDefinition(rpcName, httpPath, procedure) {
223
+ function createHttpRpcDefinition(rpcName, httpPath, procedure) {
224
224
  let method;
225
225
  if (procedure.isEventStream === true) {
226
226
  method = procedure.method ?? "get";
@@ -228,6 +228,7 @@ function createRpcDefinition(rpcName, httpPath, procedure) {
228
228
  method = procedure.method ?? "post";
229
229
  }
230
230
  return {
231
+ transport: "http",
231
232
  description: procedure.description,
232
233
  path: httpPath,
233
234
  method,
@@ -808,6 +809,7 @@ var __publicField = (obj, key, value) => {
808
809
  };
809
810
  const DEV_ENDPOINT_ROOT = `/__arri_dev__`;
810
811
  const DEV_DEFINITION_ENDPOINT = `${DEV_ENDPOINT_ROOT}/__definition`;
812
+ const createAppDefinition = (def) => def;
811
813
  class ArriApp {
812
814
  constructor(opts = {}) {
813
815
  __publicField(this, "__isArri__", true);
@@ -884,7 +886,7 @@ class ArriApp {
884
886
  }
885
887
  rpc(procedure) {
886
888
  const path = procedure.path ?? getRpcPath(procedure.name, this.rpcRoutePrefix);
887
- this.procedures[procedure.name] = createRpcDefinition(
889
+ this.procedures[procedure.name] = createHttpRpcDefinition(
888
890
  procedure.name,
889
891
  path,
890
892
  procedure
@@ -949,27 +951,41 @@ class ArriApp {
949
951
  }
950
952
 
951
953
  function isArriConfig(input) {
952
- if (typeof input !== "object" || !input) {
954
+ if (typeof input !== "object" || input === null) {
953
955
  return false;
954
956
  }
955
- return "port" in input && typeof input.port === "number" && !Number.isNaN(input.port) && "entry" in input && typeof input.entry === "string";
957
+ if ("generators" in input) {
958
+ if (!Array.isArray(input)) {
959
+ return false;
960
+ }
961
+ }
962
+ if ("port" in input && typeof input.port !== "number") {
963
+ return false;
964
+ }
965
+ if (Number.isNaN(input.port)) {
966
+ return false;
967
+ }
968
+ if ("entry" in input && typeof input.entry !== "string") {
969
+ return false;
970
+ }
971
+ return true;
956
972
  }
957
973
  function isResolvedArriConfig(input) {
958
974
  if (!isArriConfig(input)) {
959
975
  return false;
960
976
  }
961
- return typeof input.rootDir === "string" && typeof input.srcDir === "string" && (typeof input.procedureDir === "string" || typeof input.procedureDir === "boolean") && Array.isArray(input.procedureGlobPatterns) && Array.isArray(input.clientGenerators) && typeof input.buildDir === "string" && typeof input.esbuild === "object" && input.esbuild && !Array.isArray(input.esbuild);
977
+ return typeof input.rootDir === "string" && typeof input.srcDir === "string" && (typeof input.procedureDir === "string" || typeof input.procedureDir === "boolean") && Array.isArray(input.procedureGlobPatterns) && Array.isArray(input.generators) && typeof input.buildDir === "string" && typeof input.esbuild === "object" && input.esbuild && !Array.isArray(input.esbuild);
962
978
  }
963
979
  const defaultConfig = {
964
980
  port: 3e3,
965
981
  rootDir: ".",
966
982
  srcDir: "src",
967
983
  entry: "app.ts",
984
+ serverEntry: "",
968
985
  procedureDir: "procedures",
969
986
  procedureGlobPatterns: ["**/*.rpc.ts"],
970
- clientGenerators: [],
987
+ generators: [],
971
988
  buildDir: ".arri",
972
- serverEntry: "",
973
989
  esbuild: {},
974
990
  https: false,
975
991
  http2: false
@@ -982,7 +998,7 @@ function defineConfig(config) {
982
998
  entry: config.entry ?? defaultConfig.entry,
983
999
  procedureDir: config.procedureDir ?? defaultConfig.procedureDir,
984
1000
  procedureGlobPatterns: config.procedureGlobPatterns ?? defaultConfig.procedureGlobPatterns,
985
- clientGenerators: config.clientGenerators ?? defaultConfig.clientGenerators,
1001
+ generators: config.generators ?? defaultConfig.generators,
986
1002
  buildDir: config.buildDir ?? defaultConfig.buildDir,
987
1003
  esbuild: config.esbuild ?? defaultConfig.esbuild,
988
1004
  serverEntry: config.serverEntry ?? "",
@@ -997,7 +1013,8 @@ exports.DEV_DEFINITION_ENDPOINT = DEV_DEFINITION_ENDPOINT;
997
1013
  exports.DEV_ENDPOINT_ROOT = DEV_ENDPOINT_ROOT;
998
1014
  exports.ErrorResponse = ErrorResponse;
999
1015
  exports.EventStreamConnection = EventStreamConnection;
1000
- exports.createRpcDefinition = createRpcDefinition;
1016
+ exports.createAppDefinition = createAppDefinition;
1017
+ exports.createHttpRpcDefinition = createHttpRpcDefinition;
1001
1018
  exports.defaultConfig = defaultConfig;
1002
1019
  exports.defineConfig = defineConfig;
1003
1020
  exports.defineError = defineError;
@@ -1,6 +1,6 @@
1
1
  import { isRpcHttpMethod, removeDisallowedChars, SCHEMA_VERSION } from 'arri-codegen-utils';
2
2
  import { createError, isError, setResponseStatus, send, eventHandler, isPreflightRequest, setResponseHeader, readRawBody, getValidatedQuery, defineEventHandler, getQuery, setHeader, createRouter, createApp, sendError } from 'h3';
3
- import { a, isAObjectSchema, isARecordSchema, isADiscriminatorSchema } from 'arri-validate';
3
+ import { a, isAObjectSchema, isADiscriminatorSchema } from 'arri-validate';
4
4
  import { createEventStream } from 'h3-sse';
5
5
  import { kebabCase, pascalCase } from 'scule';
6
6
 
@@ -210,7 +210,7 @@ async function handleH3Error(err, event, onError) {
210
210
  }
211
211
 
212
212
  function isRpcParamSchema(input) {
213
- return isAObjectSchema(input) || isARecordSchema(input) || isADiscriminatorSchema(input);
213
+ return isAObjectSchema(input) || isADiscriminatorSchema(input);
214
214
  }
215
215
  function isRpc(input) {
216
216
  return typeof input === "object" && input !== null && "method" in input && isRpcHttpMethod(input.method) && "handler" in input && typeof input.handler === "function";
@@ -218,7 +218,7 @@ function isRpc(input) {
218
218
  function defineRpc(config) {
219
219
  return config;
220
220
  }
221
- function createRpcDefinition(rpcName, httpPath, procedure) {
221
+ function createHttpRpcDefinition(rpcName, httpPath, procedure) {
222
222
  let method;
223
223
  if (procedure.isEventStream === true) {
224
224
  method = procedure.method ?? "get";
@@ -226,6 +226,7 @@ function createRpcDefinition(rpcName, httpPath, procedure) {
226
226
  method = procedure.method ?? "post";
227
227
  }
228
228
  return {
229
+ transport: "http",
229
230
  description: procedure.description,
230
231
  path: httpPath,
231
232
  method,
@@ -806,6 +807,7 @@ var __publicField = (obj, key, value) => {
806
807
  };
807
808
  const DEV_ENDPOINT_ROOT = `/__arri_dev__`;
808
809
  const DEV_DEFINITION_ENDPOINT = `${DEV_ENDPOINT_ROOT}/__definition`;
810
+ const createAppDefinition = (def) => def;
809
811
  class ArriApp {
810
812
  constructor(opts = {}) {
811
813
  __publicField(this, "__isArri__", true);
@@ -882,7 +884,7 @@ class ArriApp {
882
884
  }
883
885
  rpc(procedure) {
884
886
  const path = procedure.path ?? getRpcPath(procedure.name, this.rpcRoutePrefix);
885
- this.procedures[procedure.name] = createRpcDefinition(
887
+ this.procedures[procedure.name] = createHttpRpcDefinition(
886
888
  procedure.name,
887
889
  path,
888
890
  procedure
@@ -947,27 +949,41 @@ class ArriApp {
947
949
  }
948
950
 
949
951
  function isArriConfig(input) {
950
- if (typeof input !== "object" || !input) {
952
+ if (typeof input !== "object" || input === null) {
951
953
  return false;
952
954
  }
953
- return "port" in input && typeof input.port === "number" && !Number.isNaN(input.port) && "entry" in input && typeof input.entry === "string";
955
+ if ("generators" in input) {
956
+ if (!Array.isArray(input)) {
957
+ return false;
958
+ }
959
+ }
960
+ if ("port" in input && typeof input.port !== "number") {
961
+ return false;
962
+ }
963
+ if (Number.isNaN(input.port)) {
964
+ return false;
965
+ }
966
+ if ("entry" in input && typeof input.entry !== "string") {
967
+ return false;
968
+ }
969
+ return true;
954
970
  }
955
971
  function isResolvedArriConfig(input) {
956
972
  if (!isArriConfig(input)) {
957
973
  return false;
958
974
  }
959
- return typeof input.rootDir === "string" && typeof input.srcDir === "string" && (typeof input.procedureDir === "string" || typeof input.procedureDir === "boolean") && Array.isArray(input.procedureGlobPatterns) && Array.isArray(input.clientGenerators) && typeof input.buildDir === "string" && typeof input.esbuild === "object" && input.esbuild && !Array.isArray(input.esbuild);
975
+ return typeof input.rootDir === "string" && typeof input.srcDir === "string" && (typeof input.procedureDir === "string" || typeof input.procedureDir === "boolean") && Array.isArray(input.procedureGlobPatterns) && Array.isArray(input.generators) && typeof input.buildDir === "string" && typeof input.esbuild === "object" && input.esbuild && !Array.isArray(input.esbuild);
960
976
  }
961
977
  const defaultConfig = {
962
978
  port: 3e3,
963
979
  rootDir: ".",
964
980
  srcDir: "src",
965
981
  entry: "app.ts",
982
+ serverEntry: "",
966
983
  procedureDir: "procedures",
967
984
  procedureGlobPatterns: ["**/*.rpc.ts"],
968
- clientGenerators: [],
985
+ generators: [],
969
986
  buildDir: ".arri",
970
- serverEntry: "",
971
987
  esbuild: {},
972
988
  https: false,
973
989
  http2: false
@@ -980,7 +996,7 @@ function defineConfig(config) {
980
996
  entry: config.entry ?? defaultConfig.entry,
981
997
  procedureDir: config.procedureDir ?? defaultConfig.procedureDir,
982
998
  procedureGlobPatterns: config.procedureGlobPatterns ?? defaultConfig.procedureGlobPatterns,
983
- clientGenerators: config.clientGenerators ?? defaultConfig.clientGenerators,
999
+ generators: config.generators ?? defaultConfig.generators,
984
1000
  buildDir: config.buildDir ?? defaultConfig.buildDir,
985
1001
  esbuild: config.esbuild ?? defaultConfig.esbuild,
986
1002
  serverEntry: config.serverEntry ?? "",
@@ -989,4 +1005,4 @@ function defineConfig(config) {
989
1005
  };
990
1006
  }
991
1007
 
992
- export { ArriApp as A, DEV_ENDPOINT_ROOT as D, ErrorResponse as E, DEV_DEFINITION_ENDPOINT as a, isRpc as b, createRpcDefinition as c, defineRpc as d, getRpcParamName as e, getRpcResponseName as f, getRpcPath as g, defineError as h, isRpcParamSchema as i, errorResponseFromValidationErrors as j, handleH3Error as k, isArriConfig as l, isResolvedArriConfig as m, defaultConfig as n, defineConfig as o, ArriRouter as p, defineRoute as q, registerRpc as r, registerRoute as s, handleRoute as t, defineEventStreamRpc as u, validateRpcRequestInput as v, isEventStreamRpc as w, EventStreamConnection as x, registerEventStreamRpc as y };
1008
+ export { ArriApp as A, DEV_ENDPOINT_ROOT as D, ErrorResponse as E, DEV_DEFINITION_ENDPOINT as a, isRpc as b, createAppDefinition as c, defineRpc as d, createHttpRpcDefinition as e, getRpcParamName as f, getRpcPath as g, getRpcResponseName as h, isRpcParamSchema as i, defineError as j, errorResponseFromValidationErrors as k, handleH3Error as l, isArriConfig as m, isResolvedArriConfig as n, defaultConfig as o, defineConfig as p, ArriRouter as q, registerRpc as r, defineRoute as s, registerRoute as t, handleRoute as u, validateRpcRequestInput as v, defineEventStreamRpc as w, isEventStreamRpc as x, EventStreamConnection as y, registerEventStreamRpc as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -31,6 +31,7 @@
31
31
  "citty": "^0.1.6",
32
32
  "consola": "^3.2.3",
33
33
  "degit": "^2.8.4",
34
+ "enquirer": "^2.4.1",
34
35
  "esbuild": "^0.20.1",
35
36
  "esbuild-plugin-replace": "^1.4.0",
36
37
  "globby": "^14.0.1",
@@ -42,10 +43,10 @@
42
43
  "prettier": "^3.2.5",
43
44
  "scule": "^1.3.0",
44
45
  "uncrypto": "^0.1.3",
45
- "arri-codegen-dart": "0.30.0",
46
- "arri-codegen-ts": "0.30.0",
47
- "arri-validate": "0.30.0",
48
- "arri-codegen-utils": "0.30.0"
46
+ "arri-codegen-dart": "0.32.0",
47
+ "arri-codegen-ts": "0.32.0",
48
+ "arri-validate": "0.32.0",
49
+ "arri-codegen-utils": "0.32.0"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@types/degit": "^2.8.6",