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