arri 0.0.6 → 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/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.c20aaf19.js';
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, v as createRpcDefinition, G as defineError, D as defineMiddleware, C as defineRoute, s as defineRpc, I as errorResponseFromValidationErrors, y as getRpcParamDefinition, x as getRpcParamName, w as getRpcPath, z as getRpcResponseName, q as isHttpMethod, m as isRpc, F as registerRoute, B as registerRpc } from './shared/arri.b4c5ce27.mjs';
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';
@@ -4,11 +4,13 @@ import require$$0, { dirname } from 'path';
4
4
  import process4 from 'process';
5
5
  import require$$0$1 from 'os';
6
6
  import tty from 'tty';
7
- import fs$1, { realpathSync, statSync, Stats } from 'fs';
7
+ import fs$1, { realpathSync, statSync, Stats, writeFileSync } from 'fs';
8
8
  import assert4 from 'assert';
9
9
  import fs from 'fs/promises';
10
10
  import v8 from 'v8';
11
11
  import { format, inspect } from 'util';
12
+ import { g as unflattenProcedures, i as isServiceDefinition, p as pascalCase, h as camelCase, a as isProcedureDefinition, e as isJsonSchemaEnum, c as isJsonSchemaNullType, b as isJsonSchemaScalarType, d as isJsonSchemaObject, f as isJsonSchemaArray } from './arri.1f1b9dfc.mjs';
13
+ import { execSync } from 'child_process';
12
14
 
13
15
  const require$1 = createRequire(import.meta.url);
14
16
  const __filename$1 = fileURLToPath(import.meta.url);
@@ -29027,4 +29029,617 @@ var debugApis = {
29027
29029
  printDocToString: withPlugins(printDocToString2)
29028
29030
  };
29029
29031
 
29030
- export { format2 as f };
29032
+ function defineClientGeneratorPlugin(plugin) {
29033
+ return plugin;
29034
+ }
29035
+
29036
+ const dartClientGenerator = defineClientGeneratorPlugin(
29037
+ (options) => {
29038
+ return {
29039
+ generator: async (def) => {
29040
+ if (!options.clientName) {
29041
+ throw new Error(
29042
+ 'Missing "clientName" cannot generate dart client'
29043
+ );
29044
+ }
29045
+ if (!options.outputFile) {
29046
+ throw new Error(
29047
+ 'Missing "outputFile" cannot generate dart client'
29048
+ );
29049
+ }
29050
+ const result = createDartClient(def, options.clientName);
29051
+ writeFileSync(options.outputFile, result);
29052
+ execSync(`dart format ${options.outputFile}`);
29053
+ },
29054
+ options
29055
+ };
29056
+ }
29057
+ );
29058
+ const generatedModels = [];
29059
+ function createDartClient(appDef, prefix = "Client") {
29060
+ const { models, procedures } = appDef;
29061
+ const serviceParts = [];
29062
+ const procedureParts = [];
29063
+ const services = unflattenProcedures(procedures);
29064
+ Object.keys(services).forEach((k) => {
29065
+ const item = services[k];
29066
+ if (isServiceDefinition(item)) {
29067
+ const serviceName = pascalCase(`${prefix}_${k}_service`);
29068
+ serviceParts.push({
29069
+ name: serviceName,
29070
+ key: k,
29071
+ content: dartServiceFromServiceDefinition(
29072
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
29073
+ serviceName,
29074
+ item,
29075
+ prefix
29076
+ )
29077
+ });
29078
+ return;
29079
+ }
29080
+ procedureParts.push(
29081
+ dartProcedureFromServiceDefinition(prefix, k, item)
29082
+ );
29083
+ });
29084
+ const endpoints = {};
29085
+ Object.keys(procedures).forEach((key) => {
29086
+ const rpc = procedures[key];
29087
+ endpoints[rpc.path] = rpc.method;
29088
+ });
29089
+ const modelParts = [];
29090
+ Object.keys(models).forEach((key) => {
29091
+ const model = models[key];
29092
+ const typeName = `${prefix}${pascalCase(key)}`;
29093
+ const objModel = model;
29094
+ if (!generatedModels.includes(typeName)) {
29095
+ modelParts.push(
29096
+ dartModelFromJsonSchema(
29097
+ `${prefix}${pascalCase(key)}`,
29098
+ objModel
29099
+ )
29100
+ );
29101
+ generatedModels.push(typeName);
29102
+ }
29103
+ });
29104
+ return `// This code was autogenerated by arri. Do not modify directly.
29105
+ import "dart:convert";
29106
+ import "package:http/http.dart" as http;
29107
+ import "package:arri_client/arri_client.dart";
29108
+
29109
+ class ${prefix} {
29110
+ final String _baseUrl;
29111
+ final Map<String, String> _headers;
29112
+ const ${prefix}({
29113
+ String baseUrl = "",
29114
+ Map<String, String> headers = const {},
29115
+ }): _headers = headers,
29116
+ _baseUrl = baseUrl;
29117
+ ${procedureParts.join("\n")}
29118
+ ${serviceParts.map(
29119
+ (service) => `${service.name} get ${service.key} {
29120
+ return ${service.name}(
29121
+ baseUrl: _baseUrl, headers: _headers,
29122
+ );
29123
+ }`
29124
+ ).join("\n ")}
29125
+ Future<http.Response> rawRequest(
29126
+ ${prefix}Endpoints endpoint, {
29127
+ Map<String, String>? query,
29128
+ dynamic body,
29129
+ Map<String, String>? headers,
29130
+ Encoding? encoding,
29131
+ }) async {
29132
+ return arriRequest(
29133
+ "$_baseUrl\${endpoint.path}",
29134
+ method: endpoint.method,
29135
+ headers: headers ?? this._headers,
29136
+ body: body,
29137
+ query: query,
29138
+ encoding: encoding,
29139
+ );
29140
+ }
29141
+ }
29142
+ ${serviceParts.map((item) => item.content).join("\n")}
29143
+ ${modelParts.join("\n")}
29144
+
29145
+ enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint {
29146
+ ${Object.keys(endpoints).map(
29147
+ (key) => `${camelCase(key.split("/").join("_"))}(
29148
+ path: "${key}",
29149
+ method: HttpMethod.${endpoints[key]},
29150
+ )`
29151
+ ).join(",\n ")};
29152
+
29153
+ const ${prefix}Endpoints({
29154
+ required this.path, required this.method,
29155
+ });
29156
+ @override
29157
+ final String path;
29158
+ @override
29159
+ final HttpMethod method;
29160
+
29161
+ @override
29162
+ compareTo(${prefix}Endpoints other) => name.compareTo(other.name);
29163
+ }`;
29164
+ }
29165
+ function dartServiceFromServiceDefinition(name, def, prefix = "") {
29166
+ const rpcParts = [];
29167
+ const subServiceParts = [];
29168
+ const serviceName = `${name}`;
29169
+ Object.keys(def).forEach((key) => {
29170
+ const item = def[key];
29171
+ if (isProcedureDefinition(item)) {
29172
+ rpcParts.push(
29173
+ dartProcedureFromServiceDefinition(prefix, key, item)
29174
+ );
29175
+ return;
29176
+ }
29177
+ const nameParts = name.split("Service");
29178
+ nameParts.pop();
29179
+ const subServiceName = pascalCase(
29180
+ `${nameParts.join("")}_${key}_Service`
29181
+ );
29182
+ const subService = dartServiceFromServiceDefinition(
29183
+ subServiceName,
29184
+ item,
29185
+ prefix
29186
+ );
29187
+ subServiceParts.push({
29188
+ name: subServiceName,
29189
+ key,
29190
+ content: subService
29191
+ });
29192
+ });
29193
+ return `class ${serviceName} {
29194
+ final String _baseUrl;
29195
+ final Map<String, String> _headers;
29196
+ const ${serviceName}({
29197
+ String baseUrl = "",
29198
+ Map<String, String> headers = const {},
29199
+ }): _baseUrl = baseUrl,
29200
+ _headers = headers;
29201
+ ${subServiceParts.map(
29202
+ (sub) => `${sub.name} get ${sub.key} {
29203
+ return ${sub.name}(
29204
+ baseUrl: _baseUrl,
29205
+ headers: _headers,
29206
+ );
29207
+ }`
29208
+ ).join("\n")}
29209
+ ${rpcParts.join("\n ")}
29210
+ }
29211
+ ${subServiceParts.map((sub) => sub.content).join("\n")}
29212
+ `;
29213
+ }
29214
+ function dartProcedureFromServiceDefinition(clientName, key, def) {
29215
+ let returnType = `Future<String>`;
29216
+ let returnTypeName = "String";
29217
+ if (def.response) {
29218
+ returnType = `Future<${clientName}${def.response}>`;
29219
+ returnTypeName = `${clientName}${def.response}`;
29220
+ } else {
29221
+ returnType = "Future<void>";
29222
+ }
29223
+ let paramsInput = "";
29224
+ if (def.params) {
29225
+ paramsInput = `${clientName}${def.params} params`;
29226
+ }
29227
+ let responseParser = "(body) => body;";
29228
+ switch (returnType) {
29229
+ case "Future<String>":
29230
+ break;
29231
+ case "Future<int>":
29232
+ responseParser = `(body) => Int.parse(body)`;
29233
+ break;
29234
+ case "Future<double>":
29235
+ responseParser = `(body) => Double.parse(body)`;
29236
+ break;
29237
+ case "Future<void>":
29238
+ responseParser = `(body) {}`;
29239
+ break;
29240
+ case "Future<bool>":
29241
+ responseParser = `(body) {
29242
+ switch(body) {
29243
+ case "true":
29244
+ case "1":
29245
+ return true;
29246
+ case "false":
29247
+ case "0":
29248
+ default:
29249
+ return false;
29250
+ }
29251
+ }`;
29252
+ break;
29253
+ default:
29254
+ responseParser = `(body) => ${returnTypeName}.fromJson(json.decode(body))`;
29255
+ break;
29256
+ }
29257
+ return `${returnType} ${key}(${paramsInput}) {
29258
+ return parsedArriRequest(
29259
+ "$_baseUrl${def.path}",
29260
+ method: HttpMethod.${def.method},
29261
+ headers: _headers,
29262
+ params: ${paramsInput.length ? `params.toJson()` : "null"},
29263
+ parser: ${responseParser},
29264
+ );
29265
+ }`;
29266
+ }
29267
+ function dartModelFromJsonSchema(name, schema) {
29268
+ const fields = [];
29269
+ const subModelParts = [];
29270
+ Object.entries(schema.properties ?? {}).forEach(([key, val]) => {
29271
+ if (typeof val !== "object") {
29272
+ return;
29273
+ }
29274
+ const [dartType, subTypes] = dartPropertyTypeFromSchema(
29275
+ name,
29276
+ key,
29277
+ schema
29278
+ );
29279
+ if (subTypes?.length) {
29280
+ for (const sub of subTypes) {
29281
+ subModelParts.push(sub);
29282
+ }
29283
+ }
29284
+ fields.push({ type: dartType, name: key });
29285
+ if (!isDartType(dartType) && "type" in val && val.type === "object") {
29286
+ subModelParts.push(
29287
+ dartModelFromJsonSchema(dartType.replace("?", ""), val)
29288
+ );
29289
+ }
29290
+ });
29291
+ return `class ${name} {
29292
+ ${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
29293
+ const ${name}({
29294
+ ${fields.map(
29295
+ (field) => field.type.includes("?") ? `this.${field.name},` : `required this.${field.name},`
29296
+ ).join("\n ")}
29297
+ });
29298
+ factory ${name}.fromJson(Map<String, dynamic> json) {
29299
+ return ${name}(
29300
+ ${fields.map((field) => `${dartParsedJsonField(field.name, field.type)},`).join("\n ")}
29301
+ );
29302
+ }
29303
+ Map<String, dynamic> toJson() {
29304
+ return {
29305
+ ${fields.map((field) => {
29306
+ const isNullable = field.type.endsWith("?");
29307
+ const typeName = field.type.replace("?", "");
29308
+ if (isDartTypeWithNullables(field.type)) {
29309
+ const transformer = transformers[typeName];
29310
+ return transformer.toJsonBody(field.name, isNullable);
29311
+ }
29312
+ if (field.type.includes("List<")) {
29313
+ return classListTransformer(typeName).toJsonBody(
29314
+ field.name,
29315
+ isNullable
29316
+ );
29317
+ }
29318
+ return classTransformer(typeName, isNullable).toJsonBody(
29319
+ field.name,
29320
+ isNullable
29321
+ );
29322
+ }).join(",\n ")},
29323
+ };
29324
+ }
29325
+ ${name} copyWith({
29326
+ ${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
29327
+ }) {
29328
+ return ${name}(
29329
+ ${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
29330
+ );
29331
+ }
29332
+ }
29333
+
29334
+ ${subModelParts.join("\n")}`;
29335
+ }
29336
+ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29337
+ const prop = schema.properties?.[propertyName];
29338
+ const isOptional = !schema.required?.includes(propertyName);
29339
+ let finalType = "";
29340
+ const subTypes = [];
29341
+ if (isJsonSchemaEnum(prop)) {
29342
+ const enumName = pascalCase(`${objectName}_${propertyName}`);
29343
+ finalType = isOptional ? `${enumName}?` : enumName;
29344
+ const options = [];
29345
+ for (const opt of prop.anyOf) {
29346
+ if (opt.type === "string") {
29347
+ options.push({
29348
+ name: camelCase(opt.const.toString()),
29349
+ type: "String",
29350
+ value: opt.const
29351
+ });
29352
+ }
29353
+ if (opt.type === "number" || opt.type === "integer") {
29354
+ options.push({
29355
+ name: camelCase(
29356
+ `num_${opt.const}`.split(".").join("Point")
29357
+ ),
29358
+ type: opt.type === "number" ? "double" : "int",
29359
+ value: opt.const
29360
+ });
29361
+ }
29362
+ }
29363
+ subTypes.push(`enum ${enumName} implements Comparable<${enumName}> {
29364
+ ${options.map(
29365
+ (opt) => `${opt.name}(${opt.type === "String" ? `"${opt.value}"` : opt.value})`
29366
+ ).join(",\n ")};
29367
+ const ${enumName}(this.value);
29368
+ final dynamic value;
29369
+
29370
+ @override
29371
+ compareTo(${enumName} other) => name.compareTo(other.name);
29372
+
29373
+ factory ${enumName}.fromJson(dynamic input) {
29374
+ for(final val in values) {
29375
+ if(val.value == input) {
29376
+ return val;
29377
+ }
29378
+ }
29379
+ return ${options[0].name};
29380
+ }
29381
+
29382
+ dynamic toJson() {
29383
+ return value;
29384
+ }
29385
+ }`);
29386
+ return [finalType, subTypes];
29387
+ }
29388
+ if (isJsonSchemaNullType(prop)) {
29389
+ finalType = "null";
29390
+ return [finalType, subTypes];
29391
+ }
29392
+ if (isJsonSchemaScalarType(prop)) {
29393
+ switch (prop.type) {
29394
+ case "string":
29395
+ finalType = isOptional ? "String?" : "String";
29396
+ break;
29397
+ case "integer":
29398
+ finalType = isOptional ? "int?" : "int";
29399
+ break;
29400
+ case "number":
29401
+ finalType = isOptional ? "double?" : "double";
29402
+ break;
29403
+ case "Date":
29404
+ finalType = isOptional ? "DateTime?" : "DateTime";
29405
+ break;
29406
+ case "boolean":
29407
+ finalType = isOptional ? "bool?" : "bool";
29408
+ break;
29409
+ }
29410
+ }
29411
+ if (isJsonSchemaObject(prop)) {
29412
+ const joinedPropName = pascalCase(
29413
+ `${objectName}_${propertyName}`
29414
+ );
29415
+ finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
29416
+ }
29417
+ if (isJsonSchemaArray(prop)) {
29418
+ const item = prop.items;
29419
+ const type = item.type;
29420
+ if (typeof type !== "string") {
29421
+ throw new Error(
29422
+ "Union types are not supported in arrays at this time"
29423
+ );
29424
+ }
29425
+ switch (type) {
29426
+ case "string":
29427
+ finalType = isOptional ? "List<String>?" : "List<String>";
29428
+ break;
29429
+ case "integer":
29430
+ finalType = isOptional ? "List<int>?" : "List<int>";
29431
+ break;
29432
+ case "number":
29433
+ finalType = isOptional ? "List<double>?" : "List<double>";
29434
+ break;
29435
+ case "null":
29436
+ finalType = isOptional ? "List<null>?" : "List<null>";
29437
+ break;
29438
+ case "boolean":
29439
+ finalType = isOptional ? "List<bool>?" : "List<bool>";
29440
+ break;
29441
+ case "Date":
29442
+ finalType = isOptional ? "List<DateTime>?" : "List<DateTime>";
29443
+ break;
29444
+ case "object": {
29445
+ const subTypeName = item.$id ?? pascalCase(`${objectName}_${propertyName}_item`);
29446
+ const model = dartModelFromJsonSchema(subTypeName, item);
29447
+ if (!generatedModels.includes(subTypeName)) {
29448
+ subTypes.push(model);
29449
+ generatedModels.push(subTypeName);
29450
+ }
29451
+ finalType = isOptional ? `List<${subTypeName}>?` : `List<${subTypeName}>`;
29452
+ break;
29453
+ }
29454
+ }
29455
+ }
29456
+ return [finalType, subTypes.length ? subTypes : void 0];
29457
+ }
29458
+ function dartParsedJsonField(fieldName, dartType) {
29459
+ if (isDartTypeWithNullables(dartType)) {
29460
+ switch (dartType) {
29461
+ case "String":
29462
+ return transformers.String.fromJsonBody(fieldName, '""');
29463
+ case "String?":
29464
+ return transformers.String.fromJsonBody(fieldName, "null");
29465
+ case "bool":
29466
+ return transformers.bool.fromJsonBody(fieldName, "false");
29467
+ case "double":
29468
+ return transformers.double.fromJsonBody(fieldName, "0.0");
29469
+ case "int":
29470
+ return transformers.int.fromJsonBody(fieldName, "0");
29471
+ case "null":
29472
+ return transformers.null.fromJsonBody(fieldName, "");
29473
+ case "DateTime":
29474
+ return transformers.DateTime.fromJsonBody(
29475
+ fieldName,
29476
+ "DateTime(0)"
29477
+ );
29478
+ case "DateTime?":
29479
+ return transformers.DateTime.fromJsonBody(fieldName, "null");
29480
+ case "List<String>":
29481
+ case "List<bool>":
29482
+ case "List<double>":
29483
+ case "List<int>":
29484
+ case "List<null>":
29485
+ return defaultListFromJsonBody(
29486
+ fieldName,
29487
+ dartType.replace("List<", "").replace(">", ""),
29488
+ "[]"
29489
+ );
29490
+ default:
29491
+ return `${fieldName}: json["${fieldName}"] is ${dartType.replace(
29492
+ "?",
29493
+ ""
29494
+ )} ? json["${fieldName}"] : null`;
29495
+ }
29496
+ }
29497
+ if (dartType.includes("List<")) {
29498
+ const innerType = dartType.replace("List<", "").replace(">", "").replace("?", "");
29499
+ return classListTransformer(innerType).fromJsonBody(
29500
+ fieldName,
29501
+ dartType.endsWith("?") ? "null" : "[]"
29502
+ );
29503
+ }
29504
+ const classType = dartType.split("?").join("").trim();
29505
+ return classTransformer(classType, dartType.endsWith("?")).fromJsonBody(
29506
+ fieldName,
29507
+ classType
29508
+ );
29509
+ }
29510
+ const dartTypeMap = {
29511
+ integer: "int",
29512
+ bigint: "int",
29513
+ number: "double",
29514
+ string: "String",
29515
+ boolean: "bool",
29516
+ null: "null",
29517
+ Date: "DateTime",
29518
+ object: void 0,
29519
+ list: void 0,
29520
+ // eslint-disable-next-line object-shorthand
29521
+ undefined: void 0,
29522
+ array: void 0,
29523
+ Uint8Array: "Uint8List"
29524
+ };
29525
+ const transformers = {
29526
+ null: {
29527
+ fromJsonBody: (_) => `null`,
29528
+ toJsonBody: defaultToJsonBody
29529
+ },
29530
+ int: {
29531
+ fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "int", fallback),
29532
+ toJsonBody: defaultToJsonBody
29533
+ },
29534
+ double: {
29535
+ fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "double", fallback),
29536
+ toJsonBody: defaultToJsonBody
29537
+ },
29538
+ String: {
29539
+ fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "String", fallback),
29540
+ toJsonBody: defaultToJsonBody
29541
+ },
29542
+ bool: {
29543
+ fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "bool", fallback),
29544
+ toJsonBody: defaultToJsonBody
29545
+ },
29546
+ DateTime: {
29547
+ fromJsonBody: (key, fallback) => `${key}: json["${key}"] is String ? DateTime.parse(json["${key}"]) : ${fallback}`,
29548
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.toIso8601String()`
29549
+ },
29550
+ "List<null>": {
29551
+ fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "null", fallback),
29552
+ toJsonBody: defaultToJsonBody
29553
+ },
29554
+ "List<int>": {
29555
+ fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "int", fallback),
29556
+ toJsonBody: defaultToJsonBody
29557
+ },
29558
+ "List<double>": {
29559
+ fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "double", fallback),
29560
+ toJsonBody: defaultToJsonBody
29561
+ },
29562
+ "List<String>": {
29563
+ fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "String", fallback),
29564
+ toJsonBody: defaultToJsonBody
29565
+ },
29566
+ "List<bool>": {
29567
+ fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "bool", fallback),
29568
+ toJsonBody: defaultToJsonBody
29569
+ },
29570
+ "List<DateTime>": {
29571
+ fromJsonBody: (key, fallback) => `${key}: json["${key}"] is List<String> ?
29572
+ (json["${key}"] as List<String>)
29573
+ .map((item) => DateTime.parse(item)).toList() : ${fallback}`,
29574
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.map((val) => val.toIso8601String()).toList()`
29575
+ },
29576
+ Uint8List: {
29577
+ fromJsonBody: (key, fallback) => `${key}: json["${key}"] is List ? Uint8List.fromList(json["${key}"]) : ${fallback}`,
29578
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.toList()`
29579
+ },
29580
+ "List<Uint8List>": {
29581
+ fromJsonBody: (key, fallback) => `${key}: json["${key}"] is List && (json["${key}"] as List).isNotEmpty && (json["${key}"] as List).first is List ? json["${key}"] : ${fallback}`,
29582
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.map((val) => val.toList()).toList()`
29583
+ }
29584
+ };
29585
+ function defaultFromJsonBody(key, typename, fallback) {
29586
+ return `${key}: json["${key}"] is ${typename} ? json["${key}"] : ${fallback}`;
29587
+ }
29588
+ function defaultListFromJsonBody(key, typename, fallback) {
29589
+ return `${key}: json["${key}"] is List<${typename}> ? json["${key}"] : ${fallback}`;
29590
+ }
29591
+ function defaultToJsonBody(key) {
29592
+ return `"${key}": ${key}`;
29593
+ }
29594
+ const classTransformer = (typename, nullable) => {
29595
+ return {
29596
+ fromJsonBody: (key, fallback) => {
29597
+ if (nullable) {
29598
+ return `${key}: json["${key}"] is Map<String, dynamic> ?
29599
+ ${typename}.fromJson(json["${key}"]) : null`;
29600
+ }
29601
+ return `${key}: ${typename}.fromJson(json["${key}"])`;
29602
+ },
29603
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.toJson()`
29604
+ };
29605
+ };
29606
+ const classListTransformer = (typename) => {
29607
+ return {
29608
+ fromJsonBody: (key, fallback) => {
29609
+ return `${key}: json["${key}"] is List<Map<String, dynamic>> ?
29610
+ (json["${key}"] as List<Map<String, dynamic>>)
29611
+ .map((val) => ${typename}.fromJson(val)).toList() : ${fallback}`;
29612
+ },
29613
+ toJsonBody: (key, isNullable) => `"${key}": ${key}${isNullable ? "?" : ""}.map((val) => val.toJson()).toList()`
29614
+ };
29615
+ };
29616
+ function isDartType(input) {
29617
+ if (typeof input !== "string") {
29618
+ return false;
29619
+ }
29620
+ for (const val of Object.values(dartTypeMap)) {
29621
+ if (input === val) {
29622
+ return true;
29623
+ }
29624
+ if (input.replace("List<", "").replace(">", "") === val) {
29625
+ return true;
29626
+ }
29627
+ }
29628
+ return false;
29629
+ }
29630
+ function isDartTypeWithNullables(input) {
29631
+ if (typeof input !== "string") {
29632
+ return false;
29633
+ }
29634
+ for (const val of Object.values(dartTypeMap)) {
29635
+ if (input.replace("?", "") === val) {
29636
+ return true;
29637
+ }
29638
+ if (input.replace("?", "").replace("List<", "").replace(">", "") === val) {
29639
+ return true;
29640
+ }
29641
+ }
29642
+ return false;
29643
+ }
29644
+
29645
+ export { dartClientGenerator as a, dartServiceFromServiceDefinition as b, createDartClient as c, defineClientGeneratorPlugin as d, dartProcedureFromServiceDefinition as e, format2 as f, dartModelFromJsonSchema as g, dartPropertyTypeFromSchema as h, dartParsedJsonField as i, classTransformer as j, classListTransformer as k, isDartType as l, isDartTypeWithNullables as m, transformers as t };