arri 0.0.5 → 0.0.7
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/chunks/browser.cjs +21 -0
- package/dist/chunks/browser.mjs +19 -0
- package/dist/chunks/index.cjs +84 -0
- package/dist/chunks/index.mjs +82 -0
- package/dist/chunks/index2.cjs +231 -0
- package/dist/chunks/index2.mjs +220 -0
- package/dist/chunks/index3.cjs +8854 -0
- package/dist/chunks/index3.mjs +8832 -0
- package/dist/chunks/xdg-open.cjs +1071 -0
- package/dist/chunks/xdg-open.mjs +1069 -0
- package/dist/cli.cjs +53435 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +53388 -0
- package/dist/codegen.cjs +255 -0
- package/dist/{codegen/index.d.mts → codegen.d.cts} +4 -3
- package/dist/{codegen/index.d.ts → codegen.d.mts} +4 -3
- package/dist/{codegen/index.d.cts → codegen.d.ts} +4 -3
- package/dist/codegen.mjs +237 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{codegen/index.mjs → shared/arri.0e69fc28.mjs} +119 -311
- package/dist/shared/{arri.215ad025.mjs → arri.1f1b9dfc.mjs} +268 -15
- package/dist/{codegen/index.cjs → shared/arri.835c5c3c.cjs} +203 -398
- package/dist/shared/{arri.e2731572.cjs → arri.8e602d87.cjs} +280 -14
- package/package.json +5 -4
- package/dist/shared/{arri.c20aaf19.d.cts → arri.2ff96786.d.cts} +7 -7
- package/dist/shared/{arri.c20aaf19.d.mts → arri.2ff96786.d.mts} +7 -7
- package/dist/shared/{arri.c20aaf19.d.ts → arri.2ff96786.d.ts} +7 -7
package/dist/codegen.cjs
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./shared/arri.8e602d87.cjs');
|
|
4
|
+
const dart = require('./shared/arri.835c5c3c.cjs');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
require('module');
|
|
7
|
+
require('url');
|
|
8
|
+
require('path');
|
|
9
|
+
require('process');
|
|
10
|
+
require('os');
|
|
11
|
+
require('tty');
|
|
12
|
+
require('assert');
|
|
13
|
+
require('fs/promises');
|
|
14
|
+
require('v8');
|
|
15
|
+
require('util');
|
|
16
|
+
require('child_process');
|
|
17
|
+
|
|
18
|
+
let createdModels = [];
|
|
19
|
+
const typescriptClientGenerator = dart.defineClientGeneratorPlugin(
|
|
20
|
+
(options) => ({
|
|
21
|
+
generator: async (def) => {
|
|
22
|
+
if (!options.clientName) {
|
|
23
|
+
throw new Error("Name is requires");
|
|
24
|
+
}
|
|
25
|
+
if (!options.outputFile) {
|
|
26
|
+
throw new Error("No output file specified");
|
|
27
|
+
}
|
|
28
|
+
const result = await createTypescriptClient(
|
|
29
|
+
def,
|
|
30
|
+
options.clientName
|
|
31
|
+
);
|
|
32
|
+
fs.writeFileSync(options.outputFile, result);
|
|
33
|
+
},
|
|
34
|
+
options
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
async function createTypescriptClient(def, prefix = "Client") {
|
|
38
|
+
createdModels = [];
|
|
39
|
+
const services = index.unflattenObject(def.procedures);
|
|
40
|
+
const serviceParts = [];
|
|
41
|
+
const procedureParts = [];
|
|
42
|
+
const modelParts = [];
|
|
43
|
+
Object.keys(services).forEach((key) => {
|
|
44
|
+
const item = services[key];
|
|
45
|
+
if (index.isServiceDefinition(item)) {
|
|
46
|
+
const serviceName = index.pascalCase(`${prefix}_${key}_service`);
|
|
47
|
+
serviceParts.push({
|
|
48
|
+
name: serviceName,
|
|
49
|
+
key,
|
|
50
|
+
content: tsServiceFromServiceDefinition(serviceName, item)
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
procedureParts.push(tsRpcFromProcedureDefinition(key, item));
|
|
55
|
+
});
|
|
56
|
+
Object.keys(def.models).forEach((key) => {
|
|
57
|
+
const modelName = index.pascalCase(`${key}`);
|
|
58
|
+
if (!createdModels.includes(modelName)) {
|
|
59
|
+
modelParts.push(tsModelFromDefinition(modelName, def.models[key]));
|
|
60
|
+
createdModels.push(modelName);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return dart.format2(
|
|
64
|
+
`/* eslint-disable */
|
|
65
|
+
import { arriRequest, ArriRequestError } from 'arri-client';
|
|
66
|
+
|
|
67
|
+
export class ${prefix} {
|
|
68
|
+
private baseUrl: string;
|
|
69
|
+
private headers: Record<string, string>;
|
|
70
|
+
${serviceParts.map((service) => `${service.key}: ${service.name}`).join("\n")}
|
|
71
|
+
constructor(opts: { baseUrl?: string; headers?: Record<string, string> }) {
|
|
72
|
+
this.baseUrl = opts.baseUrl ?? "";
|
|
73
|
+
this.headers = opts.headers ?? {};
|
|
74
|
+
${serviceParts.map(
|
|
75
|
+
(service) => `this.${service.key} = new ${service.name}(opts);`
|
|
76
|
+
).join("\n")}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
${procedureParts.join("\n")}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
${serviceParts.map((service) => service.content).join("\n")}
|
|
83
|
+
${modelParts.join("\n")}`,
|
|
84
|
+
{
|
|
85
|
+
parser: "typescript"
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function tsServiceFromServiceDefinition(name, def) {
|
|
90
|
+
const rpcParts = [];
|
|
91
|
+
const subServiceParts = [];
|
|
92
|
+
Object.keys(def).forEach((key) => {
|
|
93
|
+
const val = def[key];
|
|
94
|
+
if (index.isProcedureDefinition(val)) {
|
|
95
|
+
rpcParts.push(tsRpcFromProcedureDefinition(key, val));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const subServiceName = index.pascalCase(
|
|
99
|
+
`${name.split("Service").join("")}_${key}_service`
|
|
100
|
+
);
|
|
101
|
+
subServiceParts.push({
|
|
102
|
+
name: subServiceName,
|
|
103
|
+
key,
|
|
104
|
+
content: tsServiceFromServiceDefinition(subServiceName, val)
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
return `export class ${name} {
|
|
108
|
+
private baseUrl: string;
|
|
109
|
+
private headers: Record<string, string>;
|
|
110
|
+
${subServiceParts.map((service) => `${service.key}: ${service.name};`).join("\n")}
|
|
111
|
+
constructor(opts: { baseUrl?: string; headers?: Record<string, string> }) {
|
|
112
|
+
this.baseUrl = opts.baseUrl ?? "";
|
|
113
|
+
this.headers = opts.headers ?? {};
|
|
114
|
+
${subServiceParts.map(
|
|
115
|
+
(service) => `this.${service.key} = new ${service.name}(opts);`
|
|
116
|
+
).join("\n")}
|
|
117
|
+
}
|
|
118
|
+
${rpcParts.join("\n")}
|
|
119
|
+
}
|
|
120
|
+
${subServiceParts.map((service) => service.content).join("\n")}`;
|
|
121
|
+
}
|
|
122
|
+
function tsRpcFromProcedureDefinition(name, def) {
|
|
123
|
+
let paramStr = "";
|
|
124
|
+
let responseName = "";
|
|
125
|
+
if (def.params) {
|
|
126
|
+
paramStr = `params: ${def.params}`;
|
|
127
|
+
}
|
|
128
|
+
if (def.response) {
|
|
129
|
+
responseName = def.response;
|
|
130
|
+
}
|
|
131
|
+
return `async ${name}(${paramStr}) {
|
|
132
|
+
return arriRequest<${responseName || "undefined"}>({
|
|
133
|
+
url: \`\${this.baseUrl}${def.path}\`,
|
|
134
|
+
method: '${def.method}',
|
|
135
|
+
${paramStr.length ? `params,` : ""}
|
|
136
|
+
headers: this.headers,
|
|
137
|
+
});
|
|
138
|
+
}`;
|
|
139
|
+
}
|
|
140
|
+
function tsModelFromDefinition(name, def) {
|
|
141
|
+
const fieldParts = [];
|
|
142
|
+
const subModelParts = [];
|
|
143
|
+
Object.keys(def.properties ?? {}).forEach((key) => {
|
|
144
|
+
const isOptional = !def.required?.includes(key);
|
|
145
|
+
const prop = def.properties?.[key];
|
|
146
|
+
const keyPart = isOptional ? `${key}?` : key;
|
|
147
|
+
if (index.isJsonSchemaScalarType(prop)) {
|
|
148
|
+
fieldParts.push(
|
|
149
|
+
tsInterfaceScalarField(key, prop, isOptional) ?? ""
|
|
150
|
+
);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (index.isJsonSchemaNullType(prop)) {
|
|
154
|
+
switch (prop.type) {
|
|
155
|
+
case "null":
|
|
156
|
+
fieldParts.push(`${keyPart}: null;`);
|
|
157
|
+
break;
|
|
158
|
+
case "undefined":
|
|
159
|
+
fieldParts.push(`${keyPart}: undefined`);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (index.isJsonSchemaObject(prop)) {
|
|
165
|
+
const subModelName = prop.$id ?? index.pascalCase(`${name}_${key}`);
|
|
166
|
+
if (!createdModels.includes(subModelName)) {
|
|
167
|
+
const content = tsModelFromDefinition(
|
|
168
|
+
subModelName,
|
|
169
|
+
prop
|
|
170
|
+
);
|
|
171
|
+
subModelParts.push(content);
|
|
172
|
+
}
|
|
173
|
+
fieldParts.push(`${keyPart}: ${subModelName};`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (index.isJsonSchemaEnum(prop)) {
|
|
177
|
+
const vals = prop.anyOf.map(
|
|
178
|
+
(opt) => opt.type === "string" ? `'${opt.const}'` : `${opt.const}`
|
|
179
|
+
);
|
|
180
|
+
fieldParts.push(`${keyPart}: ${vals.join(" | ")};`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (index.isJsonSchemaArray(prop)) {
|
|
184
|
+
if (index.isJsonSchemaScalarType(prop.items)) {
|
|
185
|
+
const part = tsInterfaceScalarField(
|
|
186
|
+
key,
|
|
187
|
+
prop.items,
|
|
188
|
+
isOptional
|
|
189
|
+
).replace(";", "[];");
|
|
190
|
+
fieldParts.push(part);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (index.isJsonSchemaNullType(prop.items)) {
|
|
194
|
+
if (prop.items.type === "null") {
|
|
195
|
+
fieldParts.push(`${keyPart}: null[]`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
fieldParts.push(`${keyPart}: undefined[]`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (index.isJsonSchemaObject(prop.items)) {
|
|
202
|
+
const subModelName = prop.items.$id ?? index.pascalCase(`${name}_${key}_item`);
|
|
203
|
+
if (!createdModels.includes(subModelName)) {
|
|
204
|
+
subModelParts.push(
|
|
205
|
+
tsModelFromDefinition(subModelName, prop.items)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
fieldParts.push(`${keyPart}: ${subModelName}[];`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return `export interface ${name} {
|
|
213
|
+
${fieldParts.join("\n")}
|
|
214
|
+
}
|
|
215
|
+
${subModelParts.join("\n")}`;
|
|
216
|
+
}
|
|
217
|
+
function tsInterfaceScalarField(key, prop, isOptional = false) {
|
|
218
|
+
const keyPart = isOptional ? `${key}?` : key;
|
|
219
|
+
switch (prop.type) {
|
|
220
|
+
case "string":
|
|
221
|
+
return `${keyPart}: string;`;
|
|
222
|
+
case "bigint":
|
|
223
|
+
return `${keyPart}: bigint;`;
|
|
224
|
+
case "Date":
|
|
225
|
+
return `${keyPart}: Date;`;
|
|
226
|
+
case "boolean":
|
|
227
|
+
return `${keyPart}: boolean;`;
|
|
228
|
+
case "integer":
|
|
229
|
+
return `/**
|
|
230
|
+
* must be an integer
|
|
231
|
+
*/
|
|
232
|
+
${keyPart}: number;`;
|
|
233
|
+
case "number":
|
|
234
|
+
return `${keyPart}: number;`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
exports.classListTransformer = dart.classListTransformer;
|
|
239
|
+
exports.classTransformer = dart.classTransformer;
|
|
240
|
+
exports.createDartClient = dart.createDartClient;
|
|
241
|
+
exports.dartClientGenerator = dart.dartClientGenerator;
|
|
242
|
+
exports.dartModelFromJsonSchema = dart.dartModelFromJsonSchema;
|
|
243
|
+
exports.dartParsedJsonField = dart.dartParsedJsonField;
|
|
244
|
+
exports.dartProcedureFromServiceDefinition = dart.dartProcedureFromServiceDefinition;
|
|
245
|
+
exports.dartPropertyTypeFromSchema = dart.dartPropertyTypeFromSchema;
|
|
246
|
+
exports.dartServiceFromServiceDefinition = dart.dartServiceFromServiceDefinition;
|
|
247
|
+
exports.defineClientGeneratorPlugin = dart.defineClientGeneratorPlugin;
|
|
248
|
+
exports.isDartType = dart.isDartType;
|
|
249
|
+
exports.isDartTypeWithNullables = dart.isDartTypeWithNullables;
|
|
250
|
+
exports.transformers = dart.transformers;
|
|
251
|
+
exports.createTypescriptClient = createTypescriptClient;
|
|
252
|
+
exports.tsModelFromDefinition = tsModelFromDefinition;
|
|
253
|
+
exports.tsRpcFromProcedureDefinition = tsRpcFromProcedureDefinition;
|
|
254
|
+
exports.tsServiceFromServiceDefinition = tsServiceFromServiceDefinition;
|
|
255
|
+
exports.typescriptClientGenerator = typescriptClientGenerator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from '
|
|
1
|
+
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from './shared/arri.2ff96786.cjs';
|
|
2
2
|
import '@sinclair/typebox';
|
|
3
3
|
import 'h3';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (
|
|
|
10
10
|
declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
|
|
11
11
|
|
|
12
12
|
interface TypescriptClientGeneratorOptions {
|
|
13
|
-
|
|
13
|
+
clientName: string;
|
|
14
14
|
outputFile: string;
|
|
15
15
|
}
|
|
16
16
|
declare const typescriptClientGenerator: ClientGeneratorPlugin<TypescriptClientGeneratorOptions>;
|
|
@@ -26,6 +26,7 @@ interface DartClientGeneratorOptions {
|
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
27
|
declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
|
|
28
28
|
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
|
|
29
|
+
declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
|
|
29
30
|
declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
|
|
30
31
|
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
|
|
31
32
|
declare function dartParsedJsonField(fieldName: string, dartType: string): string;
|
|
@@ -57,4 +58,4 @@ type DartTypeWithNullables = DartType | Exclude<`${DartType}?`, "null?">;
|
|
|
57
58
|
declare function isDartType(input: any): input is DartType;
|
|
58
59
|
declare function isDartTypeWithNullables(input: any): input is DartTypeWithNullables;
|
|
59
60
|
|
|
60
|
-
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
|
61
|
+
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartProcedureFromServiceDefinition, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from '
|
|
1
|
+
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from './shared/arri.2ff96786.mjs';
|
|
2
2
|
import '@sinclair/typebox';
|
|
3
3
|
import 'h3';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (
|
|
|
10
10
|
declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
|
|
11
11
|
|
|
12
12
|
interface TypescriptClientGeneratorOptions {
|
|
13
|
-
|
|
13
|
+
clientName: string;
|
|
14
14
|
outputFile: string;
|
|
15
15
|
}
|
|
16
16
|
declare const typescriptClientGenerator: ClientGeneratorPlugin<TypescriptClientGeneratorOptions>;
|
|
@@ -26,6 +26,7 @@ interface DartClientGeneratorOptions {
|
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
27
|
declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
|
|
28
28
|
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
|
|
29
|
+
declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
|
|
29
30
|
declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
|
|
30
31
|
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
|
|
31
32
|
declare function dartParsedJsonField(fieldName: string, dartType: string): string;
|
|
@@ -57,4 +58,4 @@ type DartTypeWithNullables = DartType | Exclude<`${DartType}?`, "null?">;
|
|
|
57
58
|
declare function isDartType(input: any): input is DartType;
|
|
58
59
|
declare function isDartTypeWithNullables(input: any): input is DartTypeWithNullables;
|
|
59
60
|
|
|
60
|
-
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
|
61
|
+
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartProcedureFromServiceDefinition, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from '
|
|
1
|
+
import { B as ApplicationDefinition, S as ServiceDefinition, P as ProcedureDefinition, J as JsonSchemaObject } from './shared/arri.2ff96786.js';
|
|
2
2
|
import '@sinclair/typebox';
|
|
3
3
|
import 'h3';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ type ClientGeneratorPlugin<TOptions extends Record<string, any> | undefined> = (
|
|
|
10
10
|
declare function defineClientGeneratorPlugin<TOptions extends Record<string, any> | undefined>(plugin: ClientGeneratorPlugin<TOptions>): ClientGeneratorPlugin<TOptions>;
|
|
11
11
|
|
|
12
12
|
interface TypescriptClientGeneratorOptions {
|
|
13
|
-
|
|
13
|
+
clientName: string;
|
|
14
14
|
outputFile: string;
|
|
15
15
|
}
|
|
16
16
|
declare const typescriptClientGenerator: ClientGeneratorPlugin<TypescriptClientGeneratorOptions>;
|
|
@@ -26,6 +26,7 @@ interface DartClientGeneratorOptions {
|
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
27
|
declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
|
|
28
28
|
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
|
|
29
|
+
declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
|
|
29
30
|
declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
|
|
30
31
|
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
|
|
31
32
|
declare function dartParsedJsonField(fieldName: string, dartType: string): string;
|
|
@@ -57,4 +58,4 @@ type DartTypeWithNullables = DartType | Exclude<`${DartType}?`, "null?">;
|
|
|
57
58
|
declare function isDartType(input: any): input is DartType;
|
|
58
59
|
declare function isDartTypeWithNullables(input: any): input is DartTypeWithNullables;
|
|
59
60
|
|
|
60
|
-
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
|
61
|
+
export { type ClientGenerator, type ClientGeneratorPlugin, type DartBaseType, type DartClientGeneratorOptions, type DartType, type DartTypeWithNullables, classListTransformer, classTransformer, createDartClient, createTypescriptClient, dartClientGenerator, dartModelFromJsonSchema, dartParsedJsonField, dartProcedureFromServiceDefinition, dartPropertyTypeFromSchema, dartServiceFromServiceDefinition, defineClientGeneratorPlugin, isDartType, isDartTypeWithNullables, transformers, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
package/dist/codegen.mjs
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { u as unflattenObject, i as isServiceDefinition, p as pascalCase, a as isProcedureDefinition, b as isJsonSchemaScalarType, c as isJsonSchemaNullType, d as isJsonSchemaObject, e as isJsonSchemaEnum, f as isJsonSchemaArray } from './shared/arri.1f1b9dfc.mjs';
|
|
2
|
+
import { d as defineClientGeneratorPlugin, f as format2 } from './shared/arri.0e69fc28.mjs';
|
|
3
|
+
export { k as classListTransformer, j as classTransformer, c as createDartClient, a as dartClientGenerator, g as dartModelFromJsonSchema, i as dartParsedJsonField, e as dartProcedureFromServiceDefinition, h as dartPropertyTypeFromSchema, b as dartServiceFromServiceDefinition, l as isDartType, m as isDartTypeWithNullables, t as transformers } from './shared/arri.0e69fc28.mjs';
|
|
4
|
+
import { writeFileSync } from 'fs';
|
|
5
|
+
import 'module';
|
|
6
|
+
import 'url';
|
|
7
|
+
import 'path';
|
|
8
|
+
import 'process';
|
|
9
|
+
import 'os';
|
|
10
|
+
import 'tty';
|
|
11
|
+
import 'assert';
|
|
12
|
+
import 'fs/promises';
|
|
13
|
+
import 'v8';
|
|
14
|
+
import 'util';
|
|
15
|
+
import 'child_process';
|
|
16
|
+
|
|
17
|
+
let createdModels = [];
|
|
18
|
+
const typescriptClientGenerator = defineClientGeneratorPlugin(
|
|
19
|
+
(options) => ({
|
|
20
|
+
generator: async (def) => {
|
|
21
|
+
if (!options.clientName) {
|
|
22
|
+
throw new Error("Name is requires");
|
|
23
|
+
}
|
|
24
|
+
if (!options.outputFile) {
|
|
25
|
+
throw new Error("No output file specified");
|
|
26
|
+
}
|
|
27
|
+
const result = await createTypescriptClient(
|
|
28
|
+
def,
|
|
29
|
+
options.clientName
|
|
30
|
+
);
|
|
31
|
+
writeFileSync(options.outputFile, result);
|
|
32
|
+
},
|
|
33
|
+
options
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
async function createTypescriptClient(def, prefix = "Client") {
|
|
37
|
+
createdModels = [];
|
|
38
|
+
const services = unflattenObject(def.procedures);
|
|
39
|
+
const serviceParts = [];
|
|
40
|
+
const procedureParts = [];
|
|
41
|
+
const modelParts = [];
|
|
42
|
+
Object.keys(services).forEach((key) => {
|
|
43
|
+
const item = services[key];
|
|
44
|
+
if (isServiceDefinition(item)) {
|
|
45
|
+
const serviceName = pascalCase(`${prefix}_${key}_service`);
|
|
46
|
+
serviceParts.push({
|
|
47
|
+
name: serviceName,
|
|
48
|
+
key,
|
|
49
|
+
content: tsServiceFromServiceDefinition(serviceName, item)
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
procedureParts.push(tsRpcFromProcedureDefinition(key, item));
|
|
54
|
+
});
|
|
55
|
+
Object.keys(def.models).forEach((key) => {
|
|
56
|
+
const modelName = pascalCase(`${key}`);
|
|
57
|
+
if (!createdModels.includes(modelName)) {
|
|
58
|
+
modelParts.push(tsModelFromDefinition(modelName, def.models[key]));
|
|
59
|
+
createdModels.push(modelName);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return format2(
|
|
63
|
+
`/* eslint-disable */
|
|
64
|
+
import { arriRequest, ArriRequestError } from 'arri-client';
|
|
65
|
+
|
|
66
|
+
export class ${prefix} {
|
|
67
|
+
private baseUrl: string;
|
|
68
|
+
private headers: Record<string, string>;
|
|
69
|
+
${serviceParts.map((service) => `${service.key}: ${service.name}`).join("\n")}
|
|
70
|
+
constructor(opts: { baseUrl?: string; headers?: Record<string, string> }) {
|
|
71
|
+
this.baseUrl = opts.baseUrl ?? "";
|
|
72
|
+
this.headers = opts.headers ?? {};
|
|
73
|
+
${serviceParts.map(
|
|
74
|
+
(service) => `this.${service.key} = new ${service.name}(opts);`
|
|
75
|
+
).join("\n")}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
${procedureParts.join("\n")}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
${serviceParts.map((service) => service.content).join("\n")}
|
|
82
|
+
${modelParts.join("\n")}`,
|
|
83
|
+
{
|
|
84
|
+
parser: "typescript"
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function tsServiceFromServiceDefinition(name, def) {
|
|
89
|
+
const rpcParts = [];
|
|
90
|
+
const subServiceParts = [];
|
|
91
|
+
Object.keys(def).forEach((key) => {
|
|
92
|
+
const val = def[key];
|
|
93
|
+
if (isProcedureDefinition(val)) {
|
|
94
|
+
rpcParts.push(tsRpcFromProcedureDefinition(key, val));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const subServiceName = pascalCase(
|
|
98
|
+
`${name.split("Service").join("")}_${key}_service`
|
|
99
|
+
);
|
|
100
|
+
subServiceParts.push({
|
|
101
|
+
name: subServiceName,
|
|
102
|
+
key,
|
|
103
|
+
content: tsServiceFromServiceDefinition(subServiceName, val)
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return `export class ${name} {
|
|
107
|
+
private baseUrl: string;
|
|
108
|
+
private headers: Record<string, string>;
|
|
109
|
+
${subServiceParts.map((service) => `${service.key}: ${service.name};`).join("\n")}
|
|
110
|
+
constructor(opts: { baseUrl?: string; headers?: Record<string, string> }) {
|
|
111
|
+
this.baseUrl = opts.baseUrl ?? "";
|
|
112
|
+
this.headers = opts.headers ?? {};
|
|
113
|
+
${subServiceParts.map(
|
|
114
|
+
(service) => `this.${service.key} = new ${service.name}(opts);`
|
|
115
|
+
).join("\n")}
|
|
116
|
+
}
|
|
117
|
+
${rpcParts.join("\n")}
|
|
118
|
+
}
|
|
119
|
+
${subServiceParts.map((service) => service.content).join("\n")}`;
|
|
120
|
+
}
|
|
121
|
+
function tsRpcFromProcedureDefinition(name, def) {
|
|
122
|
+
let paramStr = "";
|
|
123
|
+
let responseName = "";
|
|
124
|
+
if (def.params) {
|
|
125
|
+
paramStr = `params: ${def.params}`;
|
|
126
|
+
}
|
|
127
|
+
if (def.response) {
|
|
128
|
+
responseName = def.response;
|
|
129
|
+
}
|
|
130
|
+
return `async ${name}(${paramStr}) {
|
|
131
|
+
return arriRequest<${responseName || "undefined"}>({
|
|
132
|
+
url: \`\${this.baseUrl}${def.path}\`,
|
|
133
|
+
method: '${def.method}',
|
|
134
|
+
${paramStr.length ? `params,` : ""}
|
|
135
|
+
headers: this.headers,
|
|
136
|
+
});
|
|
137
|
+
}`;
|
|
138
|
+
}
|
|
139
|
+
function tsModelFromDefinition(name, def) {
|
|
140
|
+
const fieldParts = [];
|
|
141
|
+
const subModelParts = [];
|
|
142
|
+
Object.keys(def.properties ?? {}).forEach((key) => {
|
|
143
|
+
const isOptional = !def.required?.includes(key);
|
|
144
|
+
const prop = def.properties?.[key];
|
|
145
|
+
const keyPart = isOptional ? `${key}?` : key;
|
|
146
|
+
if (isJsonSchemaScalarType(prop)) {
|
|
147
|
+
fieldParts.push(
|
|
148
|
+
tsInterfaceScalarField(key, prop, isOptional) ?? ""
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (isJsonSchemaNullType(prop)) {
|
|
153
|
+
switch (prop.type) {
|
|
154
|
+
case "null":
|
|
155
|
+
fieldParts.push(`${keyPart}: null;`);
|
|
156
|
+
break;
|
|
157
|
+
case "undefined":
|
|
158
|
+
fieldParts.push(`${keyPart}: undefined`);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (isJsonSchemaObject(prop)) {
|
|
164
|
+
const subModelName = prop.$id ?? pascalCase(`${name}_${key}`);
|
|
165
|
+
if (!createdModels.includes(subModelName)) {
|
|
166
|
+
const content = tsModelFromDefinition(
|
|
167
|
+
subModelName,
|
|
168
|
+
prop
|
|
169
|
+
);
|
|
170
|
+
subModelParts.push(content);
|
|
171
|
+
}
|
|
172
|
+
fieldParts.push(`${keyPart}: ${subModelName};`);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isJsonSchemaEnum(prop)) {
|
|
176
|
+
const vals = prop.anyOf.map(
|
|
177
|
+
(opt) => opt.type === "string" ? `'${opt.const}'` : `${opt.const}`
|
|
178
|
+
);
|
|
179
|
+
fieldParts.push(`${keyPart}: ${vals.join(" | ")};`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (isJsonSchemaArray(prop)) {
|
|
183
|
+
if (isJsonSchemaScalarType(prop.items)) {
|
|
184
|
+
const part = tsInterfaceScalarField(
|
|
185
|
+
key,
|
|
186
|
+
prop.items,
|
|
187
|
+
isOptional
|
|
188
|
+
).replace(";", "[];");
|
|
189
|
+
fieldParts.push(part);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (isJsonSchemaNullType(prop.items)) {
|
|
193
|
+
if (prop.items.type === "null") {
|
|
194
|
+
fieldParts.push(`${keyPart}: null[]`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
fieldParts.push(`${keyPart}: undefined[]`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (isJsonSchemaObject(prop.items)) {
|
|
201
|
+
const subModelName = prop.items.$id ?? pascalCase(`${name}_${key}_item`);
|
|
202
|
+
if (!createdModels.includes(subModelName)) {
|
|
203
|
+
subModelParts.push(
|
|
204
|
+
tsModelFromDefinition(subModelName, prop.items)
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
fieldParts.push(`${keyPart}: ${subModelName}[];`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return `export interface ${name} {
|
|
212
|
+
${fieldParts.join("\n")}
|
|
213
|
+
}
|
|
214
|
+
${subModelParts.join("\n")}`;
|
|
215
|
+
}
|
|
216
|
+
function tsInterfaceScalarField(key, prop, isOptional = false) {
|
|
217
|
+
const keyPart = isOptional ? `${key}?` : key;
|
|
218
|
+
switch (prop.type) {
|
|
219
|
+
case "string":
|
|
220
|
+
return `${keyPart}: string;`;
|
|
221
|
+
case "bigint":
|
|
222
|
+
return `${keyPart}: bigint;`;
|
|
223
|
+
case "Date":
|
|
224
|
+
return `${keyPart}: Date;`;
|
|
225
|
+
case "boolean":
|
|
226
|
+
return `${keyPart}: boolean;`;
|
|
227
|
+
case "integer":
|
|
228
|
+
return `/**
|
|
229
|
+
* must be an integer
|
|
230
|
+
*/
|
|
231
|
+
${keyPart}: number;`;
|
|
232
|
+
case "number":
|
|
233
|
+
return `${keyPart}: number;`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { createTypescriptClient, defineClientGeneratorPlugin, tsModelFromDefinition, tsRpcFromProcedureDefinition, tsServiceFromServiceDefinition, typescriptClientGenerator };
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.
|
|
1
|
+
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.2ff96786.cjs';
|
|
2
2
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
3
3
|
import { Static } from '@sinclair/typebox';
|
|
4
4
|
import { ValueError } from '@sinclair/typebox/errors';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.
|
|
1
|
+
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.2ff96786.mjs';
|
|
2
2
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
3
3
|
import { Static } from '@sinclair/typebox';
|
|
4
4
|
import { ValueError } from '@sinclair/typebox/errors';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.
|
|
1
|
+
export { d as ArriProcedure, c as ArriProcedureBase, g as ArriProcedureHandler, h as ArriProcedurePostHandler, q as ArriRoute, v as ArriRouteHandler, y as ArriRoutePostHandler, A as ArriServer, a as ArriService, E as ExtractParam, u as ExtractParams, e as HandlerContext, b as HttpMethod, H as HttpMethodValues, M as Middleware, w as RouteHandlerContext, x as RoutePostHandlerContext, R as RpcHandlerContext, f as RpcPostHandlerContext, l as createRpcDefinition, t as defineMiddleware, s as defineRoute, k as defineRpc, o as getRpcParamDefinition, n as getRpcParamName, m as getRpcPath, p as getRpcResponseName, i as isHttpMethod, j as isRpc, z as registerRoute, r as registerRpc } from './shared/arri.2ff96786.js';
|
|
2
2
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
3
3
|
import { Static } from '@sinclair/typebox';
|
|
4
4
|
import { ValueError } from '@sinclair/typebox/errors';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as ArriServer, E as ErrorResponse, H as HttpMethodValues,
|
|
1
|
+
export { A as ArriServer, E as ErrorResponse, H as HttpMethodValues, z as createRpcDefinition, L as defineError, J as defineMiddleware, I as defineRoute, y as defineRpc, M as errorResponseFromValidationErrors, D as getRpcParamDefinition, C as getRpcParamName, B as getRpcPath, F as getRpcResponseName, x as isHttpMethod, o as isRpc, K as registerRoute, G as registerRpc } from './shared/arri.1f1b9dfc.mjs';
|