arri 0.0.19 → 0.0.21

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.mjs CHANGED
@@ -1,17 +1,10 @@
1
1
  #! /usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
+ import { execSync } from 'node:child_process';
3
4
  import fs$e, { existsSync, readFileSync, realpathSync, statSync as statSync$1, Stats, promises } from 'node:fs';
4
- import { ofetch } from 'ofetch';
5
- import require$$0 from 'fs';
6
- import * as prettier from 'prettier';
7
- import '@sinclair/typebox';
8
- import 'h3';
9
- import { a as DEV_DEFINITION_ENDPOINT, C as isApplicationDef, z as camelCase, G as removeDisallowedChars, L as kebabCase } from './shared/arri.54e67ffe.mjs';
10
- import '@sinclair/typebox/errors';
11
- import '@sinclair/typebox/value';
12
- import { a as dartClientGenerator } from './shared/arri.4d2ea869.mjs';
13
5
  import fs$f, { rm } from 'node:fs/promises';
14
6
  import path$e, { isAbsolute, resolve as resolve$1, dirname, join, extname as extname$1, basename } from 'pathe';
7
+ import require$$0 from 'fs';
15
8
  import require$$0$1 from 'path';
16
9
  import require$$2 from 'os';
17
10
  import require$$3 from 'crypto';
@@ -28,79 +21,20 @@ import require$$0$4 from 'events';
28
21
  import require$$0$2 from 'util';
29
22
  import require$$0$3 from 'stream';
30
23
  import { createConsola } from 'consola';
31
- import { build } from 'esbuild';
24
+ import { build as build$1 } from 'esbuild';
25
+ import prettier from 'prettier';
26
+ import { h as camelCase, r as removeDisallowedChars, m as kebabCase, j as isApplicationDef, D as DEV_DEFINITION_ENDPOINT } from './shared/arri.e547206a.mjs';
27
+ import { defaultConfig } from './index.mjs';
32
28
  import 'node:stream';
29
+ import { ofetch } from 'ofetch';
30
+ import '@sinclair/typebox';
31
+ import 'h3';
32
+ import '@sinclair/typebox/errors';
33
+ import '@sinclair/typebox/value';
34
+ import { a as dartClientGenerator } from './shared/arri.c6b92822.mjs';
33
35
  import { listenAndWatch } from 'listhen';
34
36
  import 'child_process';
35
37
 
36
- const codegenDart = defineCommand({
37
- args: {
38
- location: {
39
- type: "positional",
40
- required: true,
41
- description: "The path to an Arri definition file or a url that returns an Arri definition file."
42
- },
43
- clientName: {
44
- type: "string",
45
- alias: ["name"],
46
- required: true
47
- },
48
- outFile: {
49
- type: "string",
50
- alias: ["out", "o"],
51
- required: true
52
- }
53
- },
54
- async run({ args }) {
55
- const isUrl = args.location.startsWith("http://") || args.location.startsWith("https://");
56
- let def;
57
- if (isUrl) {
58
- const result = await ofetch(args.location);
59
- def = result;
60
- } else {
61
- if (!existsSync(args.location)) {
62
- throw new Error(`Unable to find ${args.location}`);
63
- }
64
- const jsonString = JSON.parse(
65
- readFileSync(args.location, { encoding: "utf-8" })
66
- );
67
- def = jsonString;
68
- }
69
- if (!def) {
70
- throw new Error("Unable to load ApplicationDefinition json file");
71
- }
72
- await dartClientGenerator({
73
- clientName: args.clientName,
74
- outputFile: args.outFile
75
- }).generator(def);
76
- }
77
- });
78
- const codegenTypescript = defineCommand({
79
- args: {
80
- location: {
81
- type: "positional",
82
- required: true,
83
- description: "The path to an Arri definition file or a url that returns an Arri definition file."
84
- },
85
- clientName: {
86
- type: "string",
87
- alias: ["name"],
88
- required: true
89
- },
90
- outFile: {
91
- type: "string",
92
- alias: ["out", "o"],
93
- required: true
94
- }
95
- }
96
- });
97
- const codegen = defineCommand({
98
- subCommands: {
99
- dart: codegenDart,
100
- typescript: codegenTypescript
101
- }
102
- });
103
-
104
38
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
105
39
 
106
40
  function getDefaultExportFromCjs (x) {
@@ -132,12 +66,12 @@ function getAugmentedNamespace(n) {
132
66
  return a;
133
67
  }
134
68
 
135
- var main$3 = {exports: {}};
69
+ var main$2 = {exports: {}};
136
70
 
137
71
  const name = "dotenv";
138
72
  const version$2 = "16.3.1";
139
73
  const description = "Loads environment variables from .env file";
140
- const main$2 = "lib/main.js";
74
+ const main$1 = "lib/main.js";
141
75
  const types$2 = "lib/main.d.ts";
142
76
  const exports = {
143
77
  ".": {
@@ -200,7 +134,7 @@ const _package = {
200
134
  name: name,
201
135
  version: version$2,
202
136
  description: description,
203
- main: main$2,
137
+ main: main$1,
204
138
  types: types$2,
205
139
  exports: exports,
206
140
  scripts: scripts,
@@ -215,23 +149,23 @@ const _package = {
215
149
  };
216
150
 
217
151
  const _package$1 = {
218
- __proto__: null,
219
- browser: browser,
220
- default: _package,
221
- description: description,
222
- devDependencies: devDependencies,
223
- engines: engines,
224
- exports: exports,
225
- funding: funding,
226
- keywords: keywords$2,
227
- license: license,
228
- main: main$2,
229
- name: name,
230
- readmeFilename: readmeFilename,
231
- repository: repository,
232
- scripts: scripts,
233
- types: types$2,
234
- version: version$2
152
+ __proto__: null,
153
+ browser: browser,
154
+ default: _package,
155
+ description: description,
156
+ devDependencies: devDependencies,
157
+ engines: engines,
158
+ exports: exports,
159
+ funding: funding,
160
+ keywords: keywords$2,
161
+ license: license,
162
+ main: main$1,
163
+ name: name,
164
+ readmeFilename: readmeFilename,
165
+ repository: repository,
166
+ scripts: scripts,
167
+ types: types$2,
168
+ version: version$2
235
169
  };
236
170
 
237
171
  const require$$4 = /*@__PURE__*/getAugmentedNamespace(_package$1);
@@ -541,15 +475,15 @@ const DotenvModule = {
541
475
  populate
542
476
  };
543
477
 
544
- main$3.exports.configDotenv = DotenvModule.configDotenv;
545
- main$3.exports._configVault = DotenvModule._configVault;
546
- main$3.exports._parseVault = DotenvModule._parseVault;
547
- main$3.exports.config = DotenvModule.config;
548
- main$3.exports.decrypt = DotenvModule.decrypt;
549
- var parse_1$2 = main$3.exports.parse = DotenvModule.parse;
550
- main$3.exports.populate = DotenvModule.populate;
478
+ main$2.exports.configDotenv = DotenvModule.configDotenv;
479
+ main$2.exports._configVault = DotenvModule._configVault;
480
+ main$2.exports._parseVault = DotenvModule._parseVault;
481
+ main$2.exports.config = DotenvModule.config;
482
+ main$2.exports.decrypt = DotenvModule.decrypt;
483
+ var parse_1$2 = main$2.exports.parse = DotenvModule.parse;
484
+ main$2.exports.populate = DotenvModule.populate;
551
485
 
552
- main$3.exports = DotenvModule;
486
+ main$2.exports = DotenvModule;
553
487
 
554
488
  const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
555
489
  const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
@@ -19854,9 +19788,294 @@ const globby = normalizeArguments(async (patterns, options) => {
19854
19788
  return unionFastGlobResults(results, filter);
19855
19789
  });
19856
19790
 
19791
+ async function setupWorkingDir(config) {
19792
+ const arriDir = path$e.resolve(config.rootDir, config.buildDir);
19793
+ const outDir = path$e.resolve(config.rootDir, ".output");
19794
+ if (existsSync(arriDir)) {
19795
+ await fs$f.rm(arriDir, { recursive: true, force: true });
19796
+ }
19797
+ if (existsSync(outDir)) {
19798
+ await fs$f.rm(outDir, { recursive: true, force: true });
19799
+ }
19800
+ await fs$f.mkdir(arriDir);
19801
+ await fs$f.mkdir(outDir);
19802
+ }
19803
+ async function createRoutesModule(config) {
19804
+ const routes = [];
19805
+ await Promise.all(
19806
+ config.procedureGlobPatterns.map(async (pattern) => {
19807
+ const results = await getVirtualRouteBatch(pattern, config);
19808
+ for (const result of results) {
19809
+ routes.push(result);
19810
+ }
19811
+ })
19812
+ );
19813
+ routes.sort((a, b) => a.name < b.name ? -1 : 1);
19814
+ const module = await prettier.format(
19815
+ `${routes.map(
19816
+ (route) => `import ${route.importName} from '${route.importPath}';`
19817
+ ).join("\n")}
19818
+ const routes: { id: string; route: any }[] = [${routes.map(
19819
+ (route) => `{ id: '${route.name}', route: ${route.importName} }`
19820
+ ).join(",\n")}
19821
+ ];
19822
+ export default routes`,
19823
+ { parser: "typescript", tabWidth: 4 }
19824
+ );
19825
+ await fs$f.writeFile(
19826
+ path$e.resolve(config.rootDir, config.buildDir, "routes.ts"),
19827
+ module
19828
+ );
19829
+ }
19830
+ async function getVirtualRouteBatch(globPattern, config) {
19831
+ if (!config.procedureDir) {
19832
+ return [];
19833
+ }
19834
+ const target = `${config.rootDir}/${config.srcDir}/${config.procedureDir}/${globPattern}`.split("//").join("/").split("//").join("/");
19835
+ const files = await globby(target, {
19836
+ onlyFiles: true
19837
+ });
19838
+ const routes = [];
19839
+ for (const file of files) {
19840
+ const meta = getRpcMetaFromPath(config, file);
19841
+ if (meta) {
19842
+ const importParts = path$e.relative(path$e.resolve(config.rootDir, config.buildDir), file).split(".");
19843
+ importParts.pop();
19844
+ routes.push({
19845
+ name: meta.id,
19846
+ importName: camelCase(meta.id.split(".").join("_")),
19847
+ importPath: `./${importParts.join(".")}`
19848
+ });
19849
+ }
19850
+ }
19851
+ return routes;
19852
+ }
19853
+ const disallowedNameChars = "~`!@#$%^&*()-+=[]{}\\|:;\"'<>,./";
19854
+ const getRpcMetaFromPath = (config, filePath) => {
19855
+ if (!config.procedureDir) {
19856
+ return void 0;
19857
+ }
19858
+ const resolvedFilePath = filePath.split("./").join("/");
19859
+ const parts = resolvedFilePath.split("/");
19860
+ const reversedParts = [...parts].reverse();
19861
+ const nameParts = [];
19862
+ for (const part of reversedParts) {
19863
+ if (part === config.procedureDir) {
19864
+ break;
19865
+ }
19866
+ nameParts.push(part);
19867
+ }
19868
+ const fileName = nameParts.reverse().pop() ?? "";
19869
+ const serviceParts = nameParts.filter((part) => part.trim().length > 0).map((part) => removeDisallowedChars(part, disallowedNameChars));
19870
+ const fileNameParts = fileName.split(".");
19871
+ if (!fileNameParts.length) {
19872
+ return void 0;
19873
+ }
19874
+ const rpcName = removeDisallowedChars(
19875
+ fileNameParts[0],
19876
+ disallowedNameChars
19877
+ );
19878
+ const httpParts = [
19879
+ ...serviceParts.map((part) => kebabCase(part)),
19880
+ kebabCase(rpcName)
19881
+ ];
19882
+ return {
19883
+ id: [...serviceParts, rpcName].join("."),
19884
+ httpPath: `/${httpParts.join("/")}`
19885
+ };
19886
+ };
19887
+
19888
+ const build = defineCommand({
19889
+ args: {
19890
+ config: {
19891
+ type: "string",
19892
+ description: "Path to the arri config file",
19893
+ alias: "c",
19894
+ default: "./arri.config.ts"
19895
+ },
19896
+ skipCodegen: {
19897
+ type: "boolean",
19898
+ default: false
19899
+ }
19900
+ },
19901
+ async run({ args }) {
19902
+ const { config } = await loadConfig({
19903
+ configFile: args.config,
19904
+ defaultConfig
19905
+ });
19906
+ if (!config) {
19907
+ throw new Error("Unable to find arri config");
19908
+ }
19909
+ await startBuild(config);
19910
+ }
19911
+ });
19912
+ const logger$1 = createConsola({
19913
+ fancy: true
19914
+ }).withTag("arri");
19915
+ async function startBuild(config) {
19916
+ logger$1.log("Bundling server....");
19917
+ await setupWorkingDir(config);
19918
+ await Promise.all([
19919
+ createRoutesModule(config),
19920
+ createBuildEntryModule(config),
19921
+ createBuildCodegenModule(config)
19922
+ ]);
19923
+ await bundleFiles$1(config);
19924
+ logger$1.log("Finished bundling");
19925
+ const clientCount = config.clientGenerators.length;
19926
+ const codegenModule = path$e.resolve(config.rootDir, ".output", "codegen.js");
19927
+ if (clientCount > 0) {
19928
+ logger$1.log("Generating clients");
19929
+ execSync(`node ${codegenModule}`);
19930
+ const defJson = path$e.resolve(
19931
+ config.rootDir,
19932
+ ".output",
19933
+ "__definition.json"
19934
+ );
19935
+ const def = JSON.parse(readFileSync(defJson, { encoding: "utf-8" }));
19936
+ if (isApplicationDef(def)) {
19937
+ await Promise.all(
19938
+ config.clientGenerators.map((plugin) => plugin.generator(def))
19939
+ );
19940
+ }
19941
+ logger$1.log(`${clientCount} clients generated`);
19942
+ } else {
19943
+ logger$1.log("No client generators specified. Skipping codegen.");
19944
+ }
19945
+ logger$1.log("Cleaning up files");
19946
+ await fs$f.rm(codegenModule);
19947
+ logger$1.log(
19948
+ `Build finished! You can start your server by running "node .output/server.js"`
19949
+ );
19950
+ }
19951
+ async function bundleFiles$1(config) {
19952
+ await build$1({
19953
+ ...config.esbuild,
19954
+ entryPoints: [
19955
+ path$e.resolve(config.rootDir, config.buildDir, "server.ts"),
19956
+ path$e.resolve(config.rootDir, config.buildDir, "codegen.ts")
19957
+ ],
19958
+ platform: config.esbuild.platform ?? "node",
19959
+ target: config.esbuild.target ?? "node18",
19960
+ bundle: true,
19961
+ outdir: path$e.resolve(config.rootDir, ".output")
19962
+ });
19963
+ }
19964
+ async function createBuildEntryModule(config) {
19965
+ const appModule = path$e.resolve(config.rootDir, config.srcDir, config.entry);
19966
+ const appImportParts = path$e.relative(path$e.resolve(config.rootDir, config.buildDir), appModule).split(".");
19967
+ appImportParts.pop();
19968
+ const virtualEntry = `import { toNodeListener } from 'h3';
19969
+ import { listen } from 'listhen';
19970
+ import routes from './routes';
19971
+ import app from './${appImportParts.join(".")}';
19972
+
19973
+ for (const route of routes) {
19974
+ app.registerRpc(route.id, route.route);
19975
+ }
19976
+
19977
+ void listen(toNodeListener(app.getH3Instance()), {
19978
+ port: process.env.PORT ?? ${config.port},
19979
+ });`;
19980
+ await fs$f.writeFile(
19981
+ path$e.resolve(config.rootDir, config.buildDir, "server.ts"),
19982
+ virtualEntry
19983
+ );
19984
+ }
19985
+ async function createBuildCodegenModule(config) {
19986
+ const appModule = path$e.resolve(config.rootDir, config.srcDir, config.entry);
19987
+ const appImportParts = path$e.relative(path$e.resolve(config.rootDir, config.buildDir), appModule).split(".");
19988
+ appImportParts.pop();
19989
+ const virtualModule = await prettier.format(
19990
+ `
19991
+ import { writeFileSync } from 'node:fs';
19992
+ import path from 'pathe';
19993
+ import app from './${appImportParts.join(".")}';
19994
+
19995
+ const def = app.getAppDefinition();
19996
+ writeFileSync(
19997
+ path.resolve(__dirname, "__definition.json"),
19998
+ JSON.stringify(def),
19999
+ );`,
20000
+ { tabWidth: 4, parser: "typescript" }
20001
+ );
20002
+ await fs$f.writeFile(
20003
+ path$e.resolve(config.rootDir, config.buildDir, "codegen.ts"),
20004
+ virtualModule
20005
+ );
20006
+ }
20007
+
20008
+ const codegenDart = defineCommand({
20009
+ args: {
20010
+ location: {
20011
+ type: "positional",
20012
+ required: true,
20013
+ description: "The path to an Arri definition file or a url that returns an Arri definition file."
20014
+ },
20015
+ clientName: {
20016
+ type: "string",
20017
+ alias: ["name"],
20018
+ required: true
20019
+ },
20020
+ outFile: {
20021
+ type: "string",
20022
+ alias: ["out", "o"],
20023
+ required: true
20024
+ }
20025
+ },
20026
+ async run({ args }) {
20027
+ const isUrl = args.location.startsWith("http://") || args.location.startsWith("https://");
20028
+ let def;
20029
+ if (isUrl) {
20030
+ const result = await ofetch(args.location);
20031
+ def = result;
20032
+ } else {
20033
+ if (!existsSync(args.location)) {
20034
+ throw new Error(`Unable to find ${args.location}`);
20035
+ }
20036
+ const jsonString = JSON.parse(
20037
+ readFileSync(args.location, { encoding: "utf-8" })
20038
+ );
20039
+ def = jsonString;
20040
+ }
20041
+ if (!def) {
20042
+ throw new Error("Unable to load ApplicationDefinition json file");
20043
+ }
20044
+ await dartClientGenerator({
20045
+ clientName: args.clientName,
20046
+ outputFile: args.outFile
20047
+ }).generator(def);
20048
+ }
20049
+ });
20050
+ const codegenTypescript = defineCommand({
20051
+ args: {
20052
+ location: {
20053
+ type: "positional",
20054
+ required: true,
20055
+ description: "The path to an Arri definition file or a url that returns an Arri definition file."
20056
+ },
20057
+ clientName: {
20058
+ type: "string",
20059
+ alias: ["name"],
20060
+ required: true
20061
+ },
20062
+ outFile: {
20063
+ type: "string",
20064
+ alias: ["out", "o"],
20065
+ required: true
20066
+ }
20067
+ }
20068
+ });
20069
+ const codegen = defineCommand({
20070
+ subCommands: {
20071
+ dart: codegenDart,
20072
+ typescript: codegenTypescript
20073
+ }
20074
+ });
20075
+
19857
20076
  const logger = createConsola({
19858
20077
  fancy: true
19859
- }).withTag("[arri]");
20078
+ }).withTag("arri");
19860
20079
  const dev = defineCommand({
19861
20080
  meta: {
19862
20081
  name: "dev",
@@ -19873,14 +20092,18 @@ const dev = defineCommand({
19873
20092
  async run({ args }) {
19874
20093
  process.env.ARRI_DEV_MODE = "true";
19875
20094
  const config = await loadConfig({
19876
- configFile: path$e.resolve(args.config)
20095
+ configFile: path$e.resolve(args.config),
20096
+ defaultConfig
19877
20097
  });
19878
- await main$1(config.config);
20098
+ if (!config) {
20099
+ throw new Error("Unable to find config");
20100
+ }
20101
+ await startDevServer(config.config);
19879
20102
  }
19880
20103
  });
19881
20104
  async function bundleFiles(config) {
19882
20105
  const outDir = path$e.resolve(config.rootDir, ".output");
19883
- await build({
20106
+ await build$1({
19884
20107
  ...config.esbuild,
19885
20108
  entryPoints: [
19886
20109
  path$e.resolve(config.rootDir, config.buildDir, "entry.ts")
@@ -19891,16 +20114,18 @@ async function bundleFiles(config) {
19891
20114
  platform: "node"
19892
20115
  });
19893
20116
  }
19894
- async function main$1(config) {
20117
+ const startListener = (config, showQr = false) => listenAndWatch(path$e.resolve(config.rootDir, ".output", "entry.js"), {
20118
+ public: true,
20119
+ port: config.port,
20120
+ logger,
20121
+ qr: showQr
20122
+ });
20123
+ async function startDevServer(config) {
19895
20124
  await setupWorkingDir(config);
19896
20125
  let fileWatcher;
19897
20126
  await Promise.all([createRoutesModule(config), createEntryModule(config)]);
19898
20127
  await bundleFiles(config);
19899
- await listenAndWatch(path$e.resolve(config.rootDir, ".output", "entry.js"), {
19900
- public: true,
19901
- port: config.port,
19902
- logger
19903
- });
20128
+ let listener = await startListener(config, true);
19904
20129
  setTimeout(async () => {
19905
20130
  await generateClients(config);
19906
20131
  }, 1e3);
@@ -19923,8 +20148,12 @@ async function main$1(config) {
19923
20148
  await createRoutesModule(config);
19924
20149
  let bundleCreated = false;
19925
20150
  try {
19926
- logger.log("Change detected. Bundling files....");
20151
+ logger.log(
20152
+ "Change detected. Bundling files and restarting server...."
20153
+ );
20154
+ await listener.close();
19927
20155
  await bundleFiles(config);
20156
+ listener = await startListener(config);
19928
20157
  bundleCreated = true;
19929
20158
  } catch (err) {
19930
20159
  logger.error(err);
@@ -19964,18 +20193,6 @@ async function generateClients(config) {
19964
20193
  console.error(err);
19965
20194
  }
19966
20195
  }
19967
- async function setupWorkingDir(config) {
19968
- const arriDir = path$e.resolve(config.rootDir, config.buildDir);
19969
- const outDir = path$e.resolve(config.rootDir, ".output");
19970
- if (existsSync(arriDir)) {
19971
- await fs$f.rm(arriDir, { recursive: true, force: true });
19972
- }
19973
- if (existsSync(outDir)) {
19974
- await fs$f.rm(outDir, { recursive: true, force: true });
19975
- }
19976
- await fs$f.mkdir(arriDir);
19977
- await fs$f.mkdir(outDir);
19978
- }
19979
20196
  async function createEntryModule(config) {
19980
20197
  const appModule = path$e.resolve(config.rootDir, config.srcDir, config.entry);
19981
20198
  const appImportParts = path$e.relative(path$e.resolve(config.rootDir, config.buildDir), appModule).split(".");
@@ -19995,93 +20212,10 @@ export default app.getH3Instance();`;
19995
20212
  virtualEntry
19996
20213
  );
19997
20214
  }
19998
- async function createRoutesModule(config) {
19999
- const routes = [];
20000
- await Promise.all(
20001
- config.procedureGlobPatterns.map(async (pattern) => {
20002
- const results = await getVirtualRouteBatch(pattern, config);
20003
- for (const result of results) {
20004
- routes.push(result);
20005
- }
20006
- })
20007
- );
20008
- routes.sort((a, b) => a.name < b.name ? -1 : 1);
20009
- const module = await prettier.format(
20010
- `${routes.map(
20011
- (route) => `import ${route.importName} from '${route.importPath}';`
20012
- ).join("\n")}
20013
- const routes: { id: string; route: any }[] = [${routes.map(
20014
- (route) => `{ id: '${route.name}', route: ${route.importName} }`
20015
- ).join(",\n")}
20016
- ];
20017
- export default routes`,
20018
- { parser: "typescript", tabWidth: 4 }
20019
- );
20020
- await fs$f.writeFile(
20021
- path$e.resolve(config.rootDir, config.buildDir, "routes.ts"),
20022
- module
20023
- );
20024
- }
20025
- async function getVirtualRouteBatch(globPattern, config) {
20026
- if (!config.procedureDir) {
20027
- return [];
20028
- }
20029
- const target = `${config.rootDir}/${config.srcDir}/${config.procedureDir}/${globPattern}`.split("//").join("/").split("//").join("/");
20030
- const files = await globby(target, {
20031
- onlyFiles: true
20032
- });
20033
- const routes = [];
20034
- for (const file of files) {
20035
- const meta = getRpcMetaFromPath(config, file);
20036
- if (meta) {
20037
- const importParts = path$e.relative(path$e.resolve(config.rootDir, config.buildDir), file).split(".");
20038
- importParts.pop();
20039
- routes.push({
20040
- name: meta.id,
20041
- importName: camelCase(meta.id.split(".").join("_")),
20042
- importPath: `./${importParts.join(".")}`
20043
- });
20044
- }
20045
- }
20046
- return routes;
20047
- }
20048
- const disallowedNameChars = "~`!@#$%^&*()-+=[]{}\\|:;\"'<>,./";
20049
- const getRpcMetaFromPath = (config, filePath) => {
20050
- if (!config.procedureDir) {
20051
- return void 0;
20052
- }
20053
- const resolvedFilePath = filePath.split("./").join("/");
20054
- const parts = resolvedFilePath.split("/");
20055
- const reversedParts = [...parts].reverse();
20056
- const nameParts = [];
20057
- for (const part of reversedParts) {
20058
- if (part === config.procedureDir) {
20059
- break;
20060
- }
20061
- nameParts.push(part);
20062
- }
20063
- const fileName = nameParts.reverse().pop() ?? "";
20064
- const serviceParts = nameParts.filter((part) => part.trim().length > 0).map((part) => removeDisallowedChars(part, disallowedNameChars));
20065
- const fileNameParts = fileName.split(".");
20066
- if (!fileNameParts.length) {
20067
- return void 0;
20068
- }
20069
- const rpcName = removeDisallowedChars(
20070
- fileNameParts[0],
20071
- disallowedNameChars
20072
- );
20073
- const httpParts = [
20074
- ...serviceParts.map((part) => kebabCase(part)),
20075
- kebabCase(rpcName)
20076
- ];
20077
- return {
20078
- id: [...serviceParts, rpcName].join("."),
20079
- httpPath: `/${httpParts.join("/")}`
20080
- };
20081
- };
20082
20215
 
20083
20216
  const main = defineCommand({
20084
20217
  subCommands: {
20218
+ build,
20085
20219
  dev,
20086
20220
  codegen
20087
20221
  }
package/dist/codegen.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { writeFileSync } from 'fs';
2
2
  import { format } from 'prettier';
3
- import { u as unflattenObject, o as isServiceDef, p as pascalCase, q as isProcedureDef, s as isJsonSchemaScalarType, t as isJsonSchemaNullType, v as isJsonSchemaObject, w as isJsonSchemaEnum, x as isJsonSchemaArray, y as unflattenProcedures, z as camelCase } from './shared/arri.54e67ffe.mjs';
4
- export { K as JsonSchemaComplexTypeValues, I as JsonSchemaNullTypeValues, J as JsonSchemaScalarTypeValues, C as isApplicationDef, B as normalizeWhitespace, G as removeDisallowedChars, F as setNestedObjectProperty } from './shared/arri.54e67ffe.mjs';
5
- import { d as defineClientGeneratorPlugin } from './shared/arri.4d2ea869.mjs';
6
- export { j as classListTransformer, i as classTransformer, c as createDartClient, a as dartClientGenerator, f as dartModelFromJsonSchema, h as dartParsedJsonField, e as dartProcedureFromServiceDefinition, g as dartPropertyTypeFromSchema, b as dartServiceFromServiceDefinition, k as isDartType, l as isDartTypeWithNullables, t as transformers } from './shared/arri.4d2ea869.mjs';
3
+ import { u as unflattenObject, i as isServiceDef, p as pascalCase, a as isProcedureDef, b as isJsonSchemaScalarType, c as isJsonSchemaNullType, d as isJsonSchemaObject, e as isJsonSchemaEnum, f as isJsonSchemaArray, g as unflattenProcedures, h as camelCase } from './shared/arri.e547206a.mjs';
4
+ export { l as JsonSchemaComplexTypeValues, k as JsonSchemaNullTypeValues, J as JsonSchemaScalarTypeValues, j as isApplicationDef, n as normalizeWhitespace, r as removeDisallowedChars, s as setNestedObjectProperty } from './shared/arri.e547206a.mjs';
5
+ import { d as defineClientGeneratorPlugin } from './shared/arri.c6b92822.mjs';
6
+ export { j as classListTransformer, i as classTransformer, c as createDartClient, a as dartClientGenerator, f as dartModelFromJsonSchema, h as dartParsedJsonField, e as dartProcedureFromServiceDefinition, g as dartPropertyTypeFromSchema, b as dartServiceFromServiceDefinition, k as isDartType, l as isDartTypeWithNullables, t as transformers } from './shared/arri.c6b92822.mjs';
7
7
  import '@sinclair/typebox';
8
8
  import 'h3';
9
9
  import '@sinclair/typebox/errors';
package/dist/index.cjs CHANGED
@@ -50,4 +50,5 @@ exports.isHttpMethod = app.isHttpMethod;
50
50
  exports.isRpc = app.isRpc;
51
51
  exports.registerRoute = app.registerRoute;
52
52
  exports.registerRpc = app.registerRpc;
53
+ exports.defaultConfig = defaultConfig;
53
54
  exports.defineConfig = defineConfig;
package/dist/index.d.cts CHANGED
@@ -34,6 +34,7 @@ interface ArriConfig {
34
34
  esbuild?: Omit<BuildOptions, "outfile" | "outdir" | "entryNames" | "entryPoints">;
35
35
  }
36
36
  type ResolvedArriConfig = Required<ArriConfig>;
37
+ declare const defaultConfig: Required<ArriConfig>;
37
38
  declare function defineConfig(config: ArriConfig): ResolvedArriConfig;
38
39
 
39
- export { type ArriConfig, ErrorResponse, type ResolvedArriConfig, type StatusCode, defineConfig, defineError, errorResponseFromValidationErrors };
40
+ export { type ArriConfig, ErrorResponse, type ResolvedArriConfig, type StatusCode, defaultConfig, defineConfig, defineError, errorResponseFromValidationErrors };