arri 0.63.1 → 0.63.3

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
@@ -3,11 +3,11 @@
3
3
 
4
4
  const citty = require('citty');
5
5
  const c12 = require('c12');
6
- const common = require('./shared/arri.7f2f73b2.cjs');
6
+ const common = require('./shared/arri.27334236.cjs');
7
7
  const fs = require('node:fs');
8
8
  const codegenUtils = require('@arrirpc/codegen-utils');
9
- const ofetch = require('@joshmossas/ofetch');
10
9
  const chokidar = require('chokidar');
10
+ const ofetch = require('ofetch');
11
11
  const path = require('pathe');
12
12
  const Degit = require('degit');
13
13
  const enquirer = require('enquirer');
package/dist/cli.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #! /usr/bin/env node
2
2
  import { defineCommand, runCommand, runMain } from 'citty';
3
3
  import { loadConfig } from 'c12';
4
- import { a as isArriConfig, l as logger, g as getArriPackageMetadata, e as dev } from './shared/arri.f4637ba5.mjs';
4
+ import { a as isArriConfig, l as logger, g as getArriPackageMetadata, e as dev } from './shared/arri.cc4e1de8.mjs';
5
5
  import fs, { rmSync, readFileSync, writeFileSync } from 'node:fs';
6
6
  import { isAppDefinition, kebabCase } from '@arrirpc/codegen-utils';
7
- import { ofetch } from '@joshmossas/ofetch';
8
7
  import { watch } from 'chokidar';
8
+ import { ofetch } from 'ofetch';
9
9
  import path from 'pathe';
10
10
  import Degit from 'degit';
11
11
  import enquirer from 'enquirer';
package/dist/index.cjs CHANGED
@@ -5,11 +5,12 @@ const codegenKotlin = require('@arrirpc/codegen-kotlin');
5
5
  const codegenRust = require('@arrirpc/codegen-rust');
6
6
  const codegenSwift = require('@arrirpc/codegen-swift');
7
7
  const codegenTs = require('@arrirpc/codegen-ts');
8
- const common = require('./shared/arri.7f2f73b2.cjs');
8
+ const common = require('./shared/arri.27334236.cjs');
9
9
  const node_child_process = require('node:child_process');
10
10
  const fs = require('node:fs');
11
- const fs$1 = require('node:fs/promises');
12
11
  const path = require('node:path');
12
+ const chokidar = require('chokidar');
13
+ const fs$1 = require('node:fs/promises');
13
14
  const codegenUtils = require('@arrirpc/codegen-utils');
14
15
  const listhen = require('@joshmossas/listhen');
15
16
  const esbuild = require('esbuild');
@@ -20,8 +21,8 @@ require('c12');
20
21
  require('citty');
21
22
  require('pathe');
22
23
  require('@arrirpc/schema');
23
- require('@joshmossas/ofetch');
24
24
  require('consola');
25
+ require('ofetch');
25
26
 
26
27
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
27
28
 
@@ -37,11 +38,175 @@ function _interopNamespaceCompat(e) {
37
38
  return n;
38
39
  }
39
40
 
40
- const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs$1);
41
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
41
42
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
43
+ const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
44
+ const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs$1);
42
45
  const esbuild__default = /*#__PURE__*/_interopDefaultCompat(esbuild);
43
46
  const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
44
47
 
48
+ function goServer(options = {}) {
49
+ const outDir = options.outputDir ?? ".output";
50
+ const resolvedOutDir = options.cwd ? path__default.resolve(options.cwd, outDir) : outDir;
51
+ return common.defineServerConfig({
52
+ devFn: async (_, generators) => {
53
+ if (!fs__default.existsSync(resolvedOutDir)) {
54
+ fs__default.mkdirSync(resolvedOutDir);
55
+ }
56
+ const ignoredDirs = ["node_modules", ".arri", ".output"];
57
+ const watcher = chokidar__default.watch(".", {
58
+ ignoreInitial: true,
59
+ ignored: (path2, stats) => {
60
+ if (stats?.isFile() == true && !path2.endsWith(".go")) {
61
+ return true;
62
+ }
63
+ if (stats?.isDirectory()) {
64
+ for (const dir of ignoredDirs) {
65
+ if (path2.includes(dir)) {
66
+ return true;
67
+ }
68
+ }
69
+ }
70
+ return false;
71
+ },
72
+ cwd: options.cwd
73
+ });
74
+ let childProcess;
75
+ async function spawnProcess() {
76
+ try {
77
+ node_child_process.execSync(`go build -o ${outDir}/server`, {
78
+ stdio: "inherit",
79
+ cwd: options.cwd
80
+ });
81
+ childProcess = node_child_process.spawn(
82
+ `${outDir}/server`,
83
+ [`--def-out=${outDir}/__definition.json`],
84
+ {
85
+ stdio: "inherit",
86
+ cwd: options.cwd
87
+ }
88
+ );
89
+ childProcess.on("error", (_2) => {
90
+ childProcess?.kill("SIGTERM");
91
+ childProcess?.removeAllListeners();
92
+ childProcess = void 0;
93
+ });
94
+ childProcess.on("close", (_2) => {
95
+ childProcess?.removeAllListeners();
96
+ childProcess = void 0;
97
+ });
98
+ } catch (err) {
99
+ common.logger.error(err);
100
+ }
101
+ }
102
+ async function closeChildProcess() {
103
+ if (!childProcess)
104
+ return true;
105
+ return new Promise((res, rej) => {
106
+ childProcess?.on("close", () => res(true));
107
+ childProcess?.on("exit", () => res(true));
108
+ childProcess?.on("error", (err) => {
109
+ rej(err);
110
+ });
111
+ childProcess?.kill("SIGTERM");
112
+ });
113
+ }
114
+ spawnProcess();
115
+ watcher.on("all", async (evt) => {
116
+ common.logger.info(`Changed detected. Restarting server...`);
117
+ switch (evt) {
118
+ case "addDir":
119
+ return;
120
+ default: {
121
+ await closeChildProcess();
122
+ childProcess?.removeAllListeners();
123
+ childProcess = void 0;
124
+ spawnProcess();
125
+ }
126
+ }
127
+ });
128
+ if (generators.length == 0) {
129
+ common.logger.warn(
130
+ "No generators specified in arri config. Skipping codegen."
131
+ );
132
+ return;
133
+ }
134
+ let defFileCache = "";
135
+ let hasRunGenerators = false;
136
+ async function handleAppDef() {
137
+ let defFile = "";
138
+ try {
139
+ defFile = fs__default.readFileSync(
140
+ `${resolvedOutDir}/__definition.json`,
141
+ "utf8"
142
+ );
143
+ } catch (_2) {
144
+ return;
145
+ }
146
+ if (!defFile || defFile == defFileCache) {
147
+ return;
148
+ }
149
+ const startTime = /* @__PURE__ */ new Date();
150
+ if (hasRunGenerators) {
151
+ common.logger.info(
152
+ "App definition updated. Rerunning generators..."
153
+ );
154
+ } else {
155
+ common.logger.info("Running generators...");
156
+ }
157
+ defFileCache = defFile;
158
+ const appDef = JSON.parse(defFile);
159
+ await Promise.allSettled(
160
+ generators.map((gen) => gen.generator(appDef, true))
161
+ );
162
+ common.logger.success(
163
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
164
+ );
165
+ hasRunGenerators = true;
166
+ }
167
+ const appDefWatcher = chokidar__default.watch(
168
+ [`${outDir}/__definition.json`],
169
+ {
170
+ cwd: options.cwd
171
+ }
172
+ );
173
+ appDefWatcher.on("add", () => handleAppDef());
174
+ appDefWatcher.on("change", () => handleAppDef());
175
+ },
176
+ buildFn: async (_, generators) => {
177
+ if (!fs__default.existsSync(outDir)) {
178
+ fs__default.mkdirSync(outDir);
179
+ }
180
+ node_child_process.execSync(`go build -o ${outDir}/server`, {
181
+ stdio: "inherit"
182
+ });
183
+ node_child_process.execSync(
184
+ `${outDir}/server def -output ${outDir}/__definition.json`,
185
+ {
186
+ stdio: "inherit"
187
+ }
188
+ );
189
+ if (generators.length === 0) {
190
+ common.logger.warn(
191
+ "No generators specified in arri config. Skipping codegen."
192
+ );
193
+ return;
194
+ }
195
+ const startTime = /* @__PURE__ */ new Date();
196
+ common.logger.info(`Running generators...`);
197
+ const appDef = JSON.parse(
198
+ fs__default.readFileSync(`${resolvedOutDir}/__definition.json`, "utf8")
199
+ );
200
+ await Promise.all(
201
+ generators.map((gen) => gen.generator(appDef, false))
202
+ );
203
+ common.logger.success(
204
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
205
+ );
206
+ }
207
+ });
208
+ }
209
+
45
210
  function tsServer(serverConfig) {
46
211
  return common.defineServerConfig({
47
212
  devArgs: void 0,
@@ -571,7 +736,8 @@ const getRpcMetaFromPath = (config, filePath) => {
571
736
  };
572
737
 
573
738
  const servers = {
574
- tsServer
739
+ tsServer,
740
+ goServer
575
741
  };
576
742
 
577
743
  const generators = {
package/dist/index.d.cts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.d.mts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.d.ts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.mjs CHANGED
@@ -3,12 +3,13 @@ import { kotlinClientGenerator } from '@arrirpc/codegen-kotlin';
3
3
  import { rustClientGenerator } from '@arrirpc/codegen-rust';
4
4
  import { swiftClientGenerator } from '@arrirpc/codegen-swift';
5
5
  import { typescriptClientGenerator } from '@arrirpc/codegen-ts';
6
- import { d as defineServerConfig, l as logger, i as isInsideDir } from './shared/arri.f4637ba5.mjs';
7
- export { D as DEV_DEFINITION_ENDPOINT, b as defineConfig, a as isArriConfig, c as isServerConfig } from './shared/arri.f4637ba5.mjs';
8
- import { execSync } from 'node:child_process';
9
- import { existsSync, readFileSync } from 'node:fs';
10
- import * as fs from 'node:fs/promises';
6
+ import { d as defineServerConfig, l as logger, i as isInsideDir } from './shared/arri.cc4e1de8.mjs';
7
+ export { D as DEV_DEFINITION_ENDPOINT, b as defineConfig, a as isArriConfig, c as isServerConfig } from './shared/arri.cc4e1de8.mjs';
8
+ import { execSync, spawn } from 'node:child_process';
9
+ import fs$1, { existsSync, readFileSync } from 'node:fs';
11
10
  import path from 'node:path';
11
+ import chokidar from 'chokidar';
12
+ import * as fs from 'node:fs/promises';
12
13
  import { isAppDefinition, camelCase, removeDisallowedChars, kebabCase } from '@arrirpc/codegen-utils';
13
14
  export { createAppDefinition } from '@arrirpc/codegen-utils';
14
15
  import { listen } from '@joshmossas/listhen';
@@ -20,8 +21,170 @@ import 'c12';
20
21
  import 'citty';
21
22
  import 'pathe';
22
23
  import '@arrirpc/schema';
23
- import '@joshmossas/ofetch';
24
24
  import 'consola';
25
+ import 'ofetch';
26
+
27
+ function goServer(options = {}) {
28
+ const outDir = options.outputDir ?? ".output";
29
+ const resolvedOutDir = options.cwd ? path.resolve(options.cwd, outDir) : outDir;
30
+ return defineServerConfig({
31
+ devFn: async (_, generators) => {
32
+ if (!fs$1.existsSync(resolvedOutDir)) {
33
+ fs$1.mkdirSync(resolvedOutDir);
34
+ }
35
+ const ignoredDirs = ["node_modules", ".arri", ".output"];
36
+ const watcher = chokidar.watch(".", {
37
+ ignoreInitial: true,
38
+ ignored: (path2, stats) => {
39
+ if (stats?.isFile() == true && !path2.endsWith(".go")) {
40
+ return true;
41
+ }
42
+ if (stats?.isDirectory()) {
43
+ for (const dir of ignoredDirs) {
44
+ if (path2.includes(dir)) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+ return false;
50
+ },
51
+ cwd: options.cwd
52
+ });
53
+ let childProcess;
54
+ async function spawnProcess() {
55
+ try {
56
+ execSync(`go build -o ${outDir}/server`, {
57
+ stdio: "inherit",
58
+ cwd: options.cwd
59
+ });
60
+ childProcess = spawn(
61
+ `${outDir}/server`,
62
+ [`--def-out=${outDir}/__definition.json`],
63
+ {
64
+ stdio: "inherit",
65
+ cwd: options.cwd
66
+ }
67
+ );
68
+ childProcess.on("error", (_2) => {
69
+ childProcess?.kill("SIGTERM");
70
+ childProcess?.removeAllListeners();
71
+ childProcess = void 0;
72
+ });
73
+ childProcess.on("close", (_2) => {
74
+ childProcess?.removeAllListeners();
75
+ childProcess = void 0;
76
+ });
77
+ } catch (err) {
78
+ logger.error(err);
79
+ }
80
+ }
81
+ async function closeChildProcess() {
82
+ if (!childProcess)
83
+ return true;
84
+ return new Promise((res, rej) => {
85
+ childProcess?.on("close", () => res(true));
86
+ childProcess?.on("exit", () => res(true));
87
+ childProcess?.on("error", (err) => {
88
+ rej(err);
89
+ });
90
+ childProcess?.kill("SIGTERM");
91
+ });
92
+ }
93
+ spawnProcess();
94
+ watcher.on("all", async (evt) => {
95
+ logger.info(`Changed detected. Restarting server...`);
96
+ switch (evt) {
97
+ case "addDir":
98
+ return;
99
+ default: {
100
+ await closeChildProcess();
101
+ childProcess?.removeAllListeners();
102
+ childProcess = void 0;
103
+ spawnProcess();
104
+ }
105
+ }
106
+ });
107
+ if (generators.length == 0) {
108
+ logger.warn(
109
+ "No generators specified in arri config. Skipping codegen."
110
+ );
111
+ return;
112
+ }
113
+ let defFileCache = "";
114
+ let hasRunGenerators = false;
115
+ async function handleAppDef() {
116
+ let defFile = "";
117
+ try {
118
+ defFile = fs$1.readFileSync(
119
+ `${resolvedOutDir}/__definition.json`,
120
+ "utf8"
121
+ );
122
+ } catch (_2) {
123
+ return;
124
+ }
125
+ if (!defFile || defFile == defFileCache) {
126
+ return;
127
+ }
128
+ const startTime = /* @__PURE__ */ new Date();
129
+ if (hasRunGenerators) {
130
+ logger.info(
131
+ "App definition updated. Rerunning generators..."
132
+ );
133
+ } else {
134
+ logger.info("Running generators...");
135
+ }
136
+ defFileCache = defFile;
137
+ const appDef = JSON.parse(defFile);
138
+ await Promise.allSettled(
139
+ generators.map((gen) => gen.generator(appDef, true))
140
+ );
141
+ logger.success(
142
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
143
+ );
144
+ hasRunGenerators = true;
145
+ }
146
+ const appDefWatcher = chokidar.watch(
147
+ [`${outDir}/__definition.json`],
148
+ {
149
+ cwd: options.cwd
150
+ }
151
+ );
152
+ appDefWatcher.on("add", () => handleAppDef());
153
+ appDefWatcher.on("change", () => handleAppDef());
154
+ },
155
+ buildFn: async (_, generators) => {
156
+ if (!fs$1.existsSync(outDir)) {
157
+ fs$1.mkdirSync(outDir);
158
+ }
159
+ execSync(`go build -o ${outDir}/server`, {
160
+ stdio: "inherit"
161
+ });
162
+ execSync(
163
+ `${outDir}/server def -output ${outDir}/__definition.json`,
164
+ {
165
+ stdio: "inherit"
166
+ }
167
+ );
168
+ if (generators.length === 0) {
169
+ logger.warn(
170
+ "No generators specified in arri config. Skipping codegen."
171
+ );
172
+ return;
173
+ }
174
+ const startTime = /* @__PURE__ */ new Date();
175
+ logger.info(`Running generators...`);
176
+ const appDef = JSON.parse(
177
+ fs$1.readFileSync(`${resolvedOutDir}/__definition.json`, "utf8")
178
+ );
179
+ await Promise.all(
180
+ generators.map((gen) => gen.generator(appDef, false))
181
+ );
182
+ logger.success(
183
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
184
+ );
185
+ }
186
+ });
187
+ }
25
188
 
26
189
  function tsServer(serverConfig) {
27
190
  return defineServerConfig({
@@ -552,7 +715,8 @@ const getRpcMetaFromPath = (config, filePath) => {
552
715
  };
553
716
 
554
717
  const servers = {
555
- tsServer
718
+ tsServer,
719
+ goServer
556
720
  };
557
721
 
558
722
  const generators = {
@@ -4,8 +4,8 @@ const c12 = require('c12');
4
4
  const citty = require('citty');
5
5
  const path = require('pathe');
6
6
  const schema = require('@arrirpc/schema');
7
- const ofetch = require('@joshmossas/ofetch');
8
7
  const consola = require('consola');
8
+ const ofetch = require('ofetch');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
11
 
@@ -2,8 +2,8 @@ import { loadConfig } from 'c12';
2
2
  import { defineCommand, runCommand } from 'citty';
3
3
  import path from 'pathe';
4
4
  import { a, ValidationError } from '@arrirpc/schema';
5
- import { ofetch } from '@joshmossas/ofetch';
6
5
  import { createConsola } from 'consola';
6
+ import { ofetch } from 'ofetch';
7
7
 
8
8
  function isServerConfig(input) {
9
9
  if (typeof input !== "object" || input === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.63.1",
3
+ "version": "0.63.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -26,9 +26,9 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@joshmossas/listhen": "^1.11.1",
29
- "@joshmossas/ofetch": "^1.3.5",
29
+ "ofetch": "^1.4.1",
30
30
  "c12": "^2.0.1",
31
- "chokidar": "^3.6.0",
31
+ "chokidar": "^4.0.1",
32
32
  "citty": "^0.1.6",
33
33
  "consola": "^3.2.3",
34
34
  "degit": "^2.8.4",
@@ -39,13 +39,13 @@
39
39
  "h3": "^1.13.0",
40
40
  "pathe": "^1.1.2",
41
41
  "prettier": "^3.3.3",
42
- "@arrirpc/codegen-rust": "0.63.1",
43
- "@arrirpc/codegen-dart": "0.63.1",
44
- "@arrirpc/codegen-kotlin": "0.63.1",
45
- "@arrirpc/codegen-ts": "0.63.1",
46
- "@arrirpc/schema": "0.63.1",
47
- "@arrirpc/codegen-swift": "0.63.1",
48
- "@arrirpc/codegen-utils": "0.63.1"
42
+ "@arrirpc/codegen-dart": "0.63.3",
43
+ "@arrirpc/codegen-rust": "0.63.3",
44
+ "@arrirpc/codegen-kotlin": "0.63.3",
45
+ "@arrirpc/codegen-swift": "0.63.3",
46
+ "@arrirpc/codegen-ts": "0.63.3",
47
+ "@arrirpc/codegen-utils": "0.63.3",
48
+ "@arrirpc/schema": "0.63.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/degit": "^2.8.6"