arri 0.0.15 → 0.0.16

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.
Files changed (64) hide show
  1. package/dist/chunks/index.cjs +8836 -65
  2. package/dist/chunks/index.mjs +8817 -66
  3. package/dist/cli.cjs +16563 -52524
  4. package/dist/cli.mjs +16529 -52475
  5. package/dist/codegen.cjs +308 -31
  6. package/dist/codegen.d.cts +23 -15
  7. package/dist/codegen.d.mts +23 -15
  8. package/dist/codegen.d.ts +23 -15
  9. package/dist/codegen.mjs +274 -17
  10. package/dist/index.cjs +47 -21
  11. package/dist/index.d.cts +19 -2
  12. package/dist/index.d.mts +19 -2
  13. package/dist/index.d.ts +19 -2
  14. package/dist/index.mjs +30 -1
  15. package/dist/shared/arri.0671bb8c.mjs +641 -0
  16. package/dist/shared/arri.a9b80e98.cjs +655 -0
  17. package/dist/shared/{arri.bb7e9a4e.d.ts → arri.b176bba1.d.cts} +61 -13
  18. package/dist/shared/{arri.bb7e9a4e.d.cts → arri.b176bba1.d.mts} +61 -13
  19. package/dist/shared/{arri.bb7e9a4e.d.mts → arri.b176bba1.d.ts} +61 -13
  20. package/dist/shared/arri.b2f4eb7d.cjs +851 -0
  21. package/dist/shared/arri.fd713b2e.mjs +812 -0
  22. package/package.json +1 -1
  23. package/dist/chunks/acorn.cjs +0 -18
  24. package/dist/chunks/acorn.mjs +0 -15
  25. package/dist/chunks/angular.cjs +0 -7
  26. package/dist/chunks/angular.mjs +0 -4
  27. package/dist/chunks/babel.cjs +0 -21
  28. package/dist/chunks/babel.mjs +0 -18
  29. package/dist/chunks/browser.cjs +0 -21
  30. package/dist/chunks/browser.mjs +0 -19
  31. package/dist/chunks/estree.cjs +0 -42
  32. package/dist/chunks/estree.mjs +0 -37
  33. package/dist/chunks/flow.cjs +0 -26
  34. package/dist/chunks/flow.mjs +0 -23
  35. package/dist/chunks/glimmer.cjs +0 -37
  36. package/dist/chunks/glimmer.mjs +0 -32
  37. package/dist/chunks/graphql.cjs +0 -37
  38. package/dist/chunks/graphql.mjs +0 -31
  39. package/dist/chunks/html.cjs +0 -27
  40. package/dist/chunks/html.mjs +0 -21
  41. package/dist/chunks/index2.cjs +0 -231
  42. package/dist/chunks/index2.mjs +0 -220
  43. package/dist/chunks/index3.cjs +0 -1822
  44. package/dist/chunks/index3.mjs +0 -1812
  45. package/dist/chunks/index4.cjs +0 -256
  46. package/dist/chunks/index4.mjs +0 -247
  47. package/dist/chunks/index5.cjs +0 -8854
  48. package/dist/chunks/index5.mjs +0 -8832
  49. package/dist/chunks/markdown.cjs +0 -67
  50. package/dist/chunks/markdown.mjs +0 -61
  51. package/dist/chunks/meriyah.cjs +0 -10
  52. package/dist/chunks/meriyah.mjs +0 -7
  53. package/dist/chunks/postcss.cjs +0 -60
  54. package/dist/chunks/postcss.mjs +0 -54
  55. package/dist/chunks/typescript.cjs +0 -30
  56. package/dist/chunks/typescript.mjs +0 -27
  57. package/dist/chunks/xdg-open.cjs +0 -1071
  58. package/dist/chunks/xdg-open.mjs +0 -1069
  59. package/dist/chunks/yaml.cjs +0 -169
  60. package/dist/chunks/yaml.mjs +0 -163
  61. package/dist/shared/arri.9717f131.cjs +0 -29694
  62. package/dist/shared/arri.bfebed73.cjs +0 -8711
  63. package/dist/shared/arri.dab1f9df.mjs +0 -8670
  64. package/dist/shared/arri.e335c10b.mjs +0 -29668
@@ -0,0 +1,655 @@
1
+ 'use strict';
2
+
3
+ const child_process = require('child_process');
4
+ const require$$0 = require('fs');
5
+ const app = require('./arri.b2f4eb7d.cjs');
6
+
7
+ function defineClientGeneratorPlugin(plugin) {
8
+ return plugin;
9
+ }
10
+
11
+ const dartClientGenerator = defineClientGeneratorPlugin(
12
+ (options) => {
13
+ return {
14
+ generator: async (def) => {
15
+ if (!options.clientName) {
16
+ throw new Error(
17
+ 'Missing "clientName" cannot generate dart client'
18
+ );
19
+ }
20
+ if (!options.outputFile) {
21
+ throw new Error(
22
+ 'Missing "outputFile" cannot generate dart client'
23
+ );
24
+ }
25
+ const result = createDartClient(def, {
26
+ clientName: options.clientName
27
+ });
28
+ require$$0.writeFileSync(options.outputFile, result);
29
+ try {
30
+ child_process.execSync(`dart format ${options.outputFile}`);
31
+ } catch (err) {
32
+ console.error("Error formatting dart client", err);
33
+ }
34
+ },
35
+ options
36
+ };
37
+ }
38
+ );
39
+ let generatedModels = [];
40
+ function createDartClient(appDef, opts = { clientName: "Client" }) {
41
+ generatedModels = [];
42
+ const { models, procedures } = appDef;
43
+ const serviceParts = [];
44
+ const procedureParts = [];
45
+ const services = app.unflattenProcedures(procedures);
46
+ Object.keys(services).forEach((k) => {
47
+ const item = services[k];
48
+ if (app.isServiceDef(item)) {
49
+ const serviceName = app.pascalCase(`${opts.clientName}_${k}_service`);
50
+ serviceParts.push({
51
+ name: serviceName,
52
+ key: k,
53
+ content: dartServiceFromServiceDefinition(
54
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
55
+ serviceName,
56
+ item)
57
+ });
58
+ return;
59
+ }
60
+ procedureParts.push(dartProcedureFromServiceDefinition(k, item));
61
+ });
62
+ const endpoints = {};
63
+ Object.keys(procedures).forEach((key) => {
64
+ const rpc = procedures[key];
65
+ endpoints[rpc.path] = rpc.method;
66
+ });
67
+ const modelParts = [];
68
+ Object.keys(models).forEach((key) => {
69
+ const model = models[key];
70
+ const typeName = app.pascalCase(key);
71
+ const objModel = model;
72
+ if (!generatedModels.includes(typeName)) {
73
+ modelParts.push(
74
+ dartModelFromJsonSchema(`${app.pascalCase(key)}`, objModel)
75
+ );
76
+ generatedModels.push(typeName);
77
+ }
78
+ });
79
+ return `// This code was autogenerated by Arri. Do not modify directly.
80
+ // For additional documentation visit http://github.com/modiimedia/arri
81
+ import "dart:convert";
82
+ import "package:arri_client/arri_client.dart";
83
+
84
+ class ${opts.clientName} {
85
+ final String _baseUrl;
86
+ final Map<String, String> _headers;
87
+ const ${opts.clientName}({
88
+ String baseUrl = "",
89
+ Map<String, String> headers = const {},
90
+ }): _headers = headers,
91
+ _baseUrl = baseUrl;
92
+ ${procedureParts.join("\n")}
93
+ ${serviceParts.map(
94
+ (service) => `${service.name} get ${service.key} {
95
+ return ${service.name}(
96
+ baseUrl: _baseUrl, headers: _headers,
97
+ );
98
+ }`
99
+ ).join("\n ")}
100
+ }
101
+ ${serviceParts.map((item) => item.content).join("\n")}
102
+ ${modelParts.join("\n")}
103
+
104
+ enum ${opts.clientName}Endpoints implements Comparable<${opts.clientName}Endpoints>, ArriEndpoint {
105
+ ${Object.keys(endpoints).map(
106
+ (key) => `${app.camelCase(key.split("/").join("_"))}(
107
+ path: "${key}",
108
+ method: HttpMethod.${endpoints[key]},
109
+ )`
110
+ ).join(",\n ")};
111
+
112
+ const ${opts.clientName}Endpoints({
113
+ required this.path, required this.method,
114
+ });
115
+ @override
116
+ final String path;
117
+ @override
118
+ final HttpMethod method;
119
+
120
+ @override
121
+ compareTo(${opts.clientName}Endpoints other) => name.compareTo(other.name);
122
+ }`;
123
+ }
124
+ function dartServiceFromServiceDefinition(name, def, opts) {
125
+ const rpcParts = [];
126
+ const subServiceParts = [];
127
+ const serviceName = `${name}`;
128
+ Object.keys(def).forEach((key) => {
129
+ const item = def[key];
130
+ if (app.isProcedureDef(item)) {
131
+ rpcParts.push(dartProcedureFromServiceDefinition(key, item));
132
+ return;
133
+ }
134
+ const nameParts = name.split("Service");
135
+ nameParts.pop();
136
+ const subServiceName = app.pascalCase(
137
+ `${nameParts.join("")}_${key}_Service`
138
+ );
139
+ const subService = dartServiceFromServiceDefinition(
140
+ subServiceName,
141
+ item);
142
+ subServiceParts.push({
143
+ name: subServiceName,
144
+ key,
145
+ content: subService
146
+ });
147
+ });
148
+ return `class ${serviceName} {
149
+ final String _baseUrl;
150
+ final Map<String, String> _headers;
151
+ const ${serviceName}({
152
+ String baseUrl = "",
153
+ Map<String, String> headers = const {},
154
+ }): _baseUrl = baseUrl,
155
+ _headers = headers;
156
+ ${subServiceParts.map(
157
+ (sub) => `${sub.name} get ${sub.key} {
158
+ return ${sub.name}(
159
+ baseUrl: _baseUrl,
160
+ headers: _headers,
161
+ );
162
+ }`
163
+ ).join("\n")}
164
+ ${rpcParts.join("\n ")}
165
+ }
166
+ ${subServiceParts.map((sub) => sub.content).join("\n")}
167
+ `;
168
+ }
169
+ function dartProcedureFromServiceDefinition(key, def, opts) {
170
+ let returnType = `Future<String>`;
171
+ let returnTypeName = "String";
172
+ if (def.response) {
173
+ returnType = `Future<${def.response}>`;
174
+ returnTypeName = `${def.response}`;
175
+ } else {
176
+ returnType = "Future<void>";
177
+ }
178
+ let paramsInput = "";
179
+ if (def.params) {
180
+ paramsInput = `${def.params} params`;
181
+ }
182
+ let responseParser = "(body) => body;";
183
+ switch (returnType) {
184
+ case "Future<String>":
185
+ break;
186
+ case "Future<int>":
187
+ responseParser = `(body) => Int.parse(body)`;
188
+ break;
189
+ case "Future<double>":
190
+ responseParser = `(body) => Double.parse(body)`;
191
+ break;
192
+ case "Future<void>":
193
+ responseParser = `(body) {}`;
194
+ break;
195
+ case "Future<bool>":
196
+ responseParser = `(body) {
197
+ switch(body) {
198
+ case "true":
199
+ case "1":
200
+ return true;
201
+ case "false":
202
+ case "0":
203
+ default:
204
+ return false;
205
+ }
206
+ }`;
207
+ break;
208
+ default:
209
+ responseParser = `(body) => ${returnTypeName}.fromJson(json.decode(body))`;
210
+ break;
211
+ }
212
+ return `${returnType} ${key}(${paramsInput}) {
213
+ return parsedArriRequest(
214
+ "$_baseUrl${def.path}",
215
+ method: HttpMethod.${def.method},
216
+ headers: _headers,
217
+ params: ${paramsInput.length ? `params.toJson()` : "null"},
218
+ parser: ${responseParser},
219
+ );
220
+ }`;
221
+ }
222
+ function dartModelFromJsonSchema(modelName, schema, opts) {
223
+ const modelDisplayName = app.pascalCase(`${modelName}`);
224
+ const fields = [];
225
+ const subModelParts = [];
226
+ Object.entries(schema.properties ?? {}).forEach(([key, val]) => {
227
+ if (typeof val !== "object") {
228
+ return;
229
+ }
230
+ const [dartType, subTypes] = dartPropertyTypeFromSchema(
231
+ modelName,
232
+ key,
233
+ schema);
234
+ if (subTypes?.length) {
235
+ for (const sub of subTypes) {
236
+ subModelParts.push(sub);
237
+ }
238
+ }
239
+ fields.push({ type: dartType, name: app.camelCase(key), jsonKey: key });
240
+ if (!isDartType(dartType) && app.isJsonSchemaObject(val)) {
241
+ if (val.$id && generatedModels.includes(val.$id)) {
242
+ return;
243
+ }
244
+ const subModelName = val.$id ? app.pascalCase(val.$id) : app.pascalCase(dartType.replace("?", ""));
245
+ subModelParts.push(
246
+ dartModelFromJsonSchema(subModelName, val)
247
+ );
248
+ generatedModels.push(subModelName);
249
+ }
250
+ });
251
+ return `class ${modelDisplayName} {
252
+ ${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
253
+ const ${modelDisplayName}({
254
+ ${fields.map(
255
+ (field) => field.type.includes("?") ? `this.${field.name},` : `required this.${field.name},`
256
+ ).join("\n ")}
257
+ });
258
+ factory ${modelDisplayName}.fromJson(Map<String, dynamic> json) {
259
+ return ${modelDisplayName}(
260
+ ${fields.map(
261
+ (field) => `${dartParsedJsonField(
262
+ field.name,
263
+ field.jsonKey,
264
+ field.type
265
+ )},`
266
+ ).join("\n ")}
267
+ );
268
+ }
269
+ Map<String, dynamic> toJson() {
270
+ return {
271
+ ${fields.map((field) => {
272
+ const isNullable = field.type.endsWith("?");
273
+ const typeName = field.type.replace("?", "");
274
+ if (isDartTypeWithNullables(field.type)) {
275
+ const transformer = transformers[typeName];
276
+ return transformer.toJsonBody(
277
+ field.name,
278
+ field.jsonKey,
279
+ isNullable
280
+ );
281
+ }
282
+ if (field.type.includes("List<")) {
283
+ return classListTransformer(typeName).toJsonBody(
284
+ field.name,
285
+ field.jsonKey,
286
+ isNullable
287
+ );
288
+ }
289
+ return classTransformer(typeName, isNullable).toJsonBody(
290
+ field.name,
291
+ field.jsonKey,
292
+ isNullable
293
+ );
294
+ }).join(",\n ")},
295
+ };
296
+ }
297
+ ${modelDisplayName} copyWith({
298
+ ${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
299
+ }) {
300
+ return ${modelDisplayName}(
301
+ ${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
302
+ );
303
+ }
304
+ }
305
+
306
+ ${subModelParts.join("\n")}`;
307
+ }
308
+ function dartPropertyTypeFromSchema(objectName, propertyName, schema, opts) {
309
+ const prop = schema.properties?.[propertyName];
310
+ const isOptional = !schema.required?.includes(propertyName);
311
+ let finalType = "";
312
+ const subTypes = [];
313
+ if (app.isJsonSchemaEnum(prop)) {
314
+ const enumName = app.pascalCase(`${objectName}_${propertyName}`);
315
+ finalType = isOptional ? `${enumName}?` : enumName;
316
+ const options = [];
317
+ for (const opt of prop.anyOf) {
318
+ if (opt.type === "string") {
319
+ options.push({
320
+ name: app.camelCase(opt.const.toString()),
321
+ type: "String",
322
+ value: opt.const
323
+ });
324
+ }
325
+ if (opt.type === "number" || opt.type === "integer") {
326
+ options.push({
327
+ name: app.camelCase(
328
+ `num_${opt.const}`.split(".").join("Point")
329
+ ),
330
+ type: opt.type === "number" ? "double" : "int",
331
+ value: opt.const
332
+ });
333
+ }
334
+ }
335
+ subTypes.push(`enum ${enumName} implements Comparable<${enumName}> {
336
+ ${options.map(
337
+ (opt) => `${opt.name}(${opt.type === "String" ? `"${opt.value}"` : opt.value})`
338
+ ).join(",\n ")};
339
+ const ${enumName}(this.value);
340
+ final dynamic value;
341
+
342
+ @override
343
+ compareTo(${enumName} other) => name.compareTo(other.name);
344
+
345
+ factory ${enumName}.fromJson(dynamic input) {
346
+ for(final val in values) {
347
+ if(val.value == input) {
348
+ return val;
349
+ }
350
+ }
351
+ return ${options[0].name};
352
+ }
353
+
354
+ dynamic toJson() {
355
+ return value;
356
+ }
357
+ }`);
358
+ return [finalType, subTypes];
359
+ }
360
+ if (app.isJsonSchemaNullType(prop)) {
361
+ finalType = "null";
362
+ return [finalType, subTypes];
363
+ }
364
+ if (app.isJsonSchemaScalarType(prop)) {
365
+ switch (prop.type) {
366
+ case "string":
367
+ finalType = isOptional ? "String?" : "String";
368
+ break;
369
+ case "integer":
370
+ finalType = isOptional ? "int?" : "int";
371
+ break;
372
+ case "number":
373
+ finalType = isOptional ? "double?" : "double";
374
+ break;
375
+ case "Date":
376
+ finalType = isOptional ? "DateTime?" : "DateTime";
377
+ break;
378
+ case "boolean":
379
+ finalType = isOptional ? "bool?" : "bool";
380
+ break;
381
+ }
382
+ }
383
+ if (app.isJsonSchemaObject(prop)) {
384
+ const joinedPropName = prop.$id ? app.pascalCase(prop.$id) : app.pascalCase(`${objectName}_${propertyName}`);
385
+ finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
386
+ }
387
+ if (app.isJsonSchemaArray(prop)) {
388
+ const item = prop.items;
389
+ const type = item.type;
390
+ if (typeof type !== "string") {
391
+ throw new Error(
392
+ "Union types are not supported in arrays at this time"
393
+ );
394
+ }
395
+ switch (type) {
396
+ case "string":
397
+ finalType = isOptional ? "List<String>?" : "List<String>";
398
+ break;
399
+ case "integer":
400
+ finalType = isOptional ? "List<int>?" : "List<int>";
401
+ break;
402
+ case "number":
403
+ finalType = isOptional ? "List<double>?" : "List<double>";
404
+ break;
405
+ case "null":
406
+ finalType = isOptional ? "List<null>?" : "List<null>";
407
+ break;
408
+ case "boolean":
409
+ finalType = isOptional ? "List<bool>?" : "List<bool>";
410
+ break;
411
+ case "Date":
412
+ finalType = isOptional ? "List<DateTime>?" : "List<DateTime>";
413
+ break;
414
+ case "object": {
415
+ const subTypeName = item.$id ?? app.pascalCase(`${objectName}_${propertyName}_item`);
416
+ if (!generatedModels.includes(subTypeName)) {
417
+ const model = dartModelFromJsonSchema(
418
+ subTypeName,
419
+ item);
420
+ subTypes.push(model);
421
+ generatedModels.push(subTypeName);
422
+ }
423
+ finalType = isOptional ? `List<${subTypeName}>?` : `List<${subTypeName}>`;
424
+ break;
425
+ }
426
+ }
427
+ }
428
+ return [finalType, subTypes.length ? subTypes : void 0];
429
+ }
430
+ function dartParsedJsonField(fieldName, jsonKey, dartType) {
431
+ if (isDartTypeWithNullables(dartType)) {
432
+ switch (dartType) {
433
+ case "String":
434
+ return transformers.String.fromJsonBody(
435
+ fieldName,
436
+ jsonKey,
437
+ '""'
438
+ );
439
+ case "String?":
440
+ return transformers.String.fromJsonBody(
441
+ fieldName,
442
+ jsonKey,
443
+ "null"
444
+ );
445
+ case "bool":
446
+ return transformers.bool.fromJsonBody(
447
+ fieldName,
448
+ jsonKey,
449
+ "false"
450
+ );
451
+ case "double":
452
+ return transformers.double.fromJsonBody(
453
+ fieldName,
454
+ jsonKey,
455
+ "0.0"
456
+ );
457
+ case "int":
458
+ return transformers.int.fromJsonBody(fieldName, jsonKey, "0");
459
+ case "null":
460
+ return transformers.null.fromJsonBody(fieldName, jsonKey, "");
461
+ case "DateTime":
462
+ return transformers.DateTime.fromJsonBody(
463
+ fieldName,
464
+ jsonKey,
465
+ "DateTime(0)"
466
+ );
467
+ case "DateTime?":
468
+ return transformers.DateTime.fromJsonBody(
469
+ fieldName,
470
+ jsonKey,
471
+ "null"
472
+ );
473
+ case "List<String>":
474
+ case "List<bool>":
475
+ case "List<double>":
476
+ case "List<int>":
477
+ case "List<null>":
478
+ return defaultListFromJsonBody(
479
+ fieldName,
480
+ jsonKey,
481
+ dartType.replace("List<", "").replace(">", ""),
482
+ "[]"
483
+ );
484
+ default:
485
+ return `${fieldName}: json["${jsonKey}"] is ${dartType.replace(
486
+ "?",
487
+ ""
488
+ )} ? json["${jsonKey}"] : null`;
489
+ }
490
+ }
491
+ if (dartType.includes("List<")) {
492
+ const innerType = dartType.replace("List<", "").replace(">", "").replace("?", "");
493
+ return classListTransformer(innerType).fromJsonBody(
494
+ fieldName,
495
+ jsonKey,
496
+ dartType.endsWith("?") ? "null" : "[]"
497
+ );
498
+ }
499
+ const classType = dartType.split("?").join("").trim();
500
+ return classTransformer(classType, dartType.endsWith("?")).fromJsonBody(
501
+ fieldName,
502
+ jsonKey,
503
+ classType
504
+ );
505
+ }
506
+ const dartTypeMap = {
507
+ integer: "int",
508
+ bigint: "int",
509
+ number: "double",
510
+ string: "String",
511
+ boolean: "bool",
512
+ null: "null",
513
+ Date: "DateTime",
514
+ object: void 0,
515
+ list: void 0,
516
+ // eslint-disable-next-line object-shorthand
517
+ undefined: void 0,
518
+ array: void 0,
519
+ Uint8Array: "Uint8List"
520
+ };
521
+ const transformers = {
522
+ null: {
523
+ fromJsonBody: (_) => `null`,
524
+ toJsonBody: defaultToJsonBody
525
+ },
526
+ int: {
527
+ fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "int", fallback),
528
+ toJsonBody: defaultToJsonBody
529
+ },
530
+ double: {
531
+ fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "double", fallback),
532
+ toJsonBody: defaultToJsonBody
533
+ },
534
+ String: {
535
+ fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "String", fallback),
536
+ toJsonBody: defaultToJsonBody
537
+ },
538
+ bool: {
539
+ fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "bool", fallback),
540
+ toJsonBody: defaultToJsonBody
541
+ },
542
+ DateTime: {
543
+ fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is String ? DateTime.parse(json["${jsonKey}"]) : ${fallback}`,
544
+ toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toIso8601String()`
545
+ },
546
+ "List<null>": {
547
+ fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "null", fallback),
548
+ toJsonBody: defaultToJsonBody
549
+ },
550
+ "List<int>": {
551
+ fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "int", fallback),
552
+ toJsonBody: defaultToJsonBody
553
+ },
554
+ "List<double>": {
555
+ fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "double", fallback),
556
+ toJsonBody: defaultToJsonBody
557
+ },
558
+ "List<String>": {
559
+ fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "String", fallback),
560
+ toJsonBody: defaultToJsonBody
561
+ },
562
+ "List<bool>": {
563
+ fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "bool", fallback),
564
+ toJsonBody: defaultToJsonBody
565
+ },
566
+ "List<DateTime>": {
567
+ fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List<String> ?
568
+ (json["${jsonKey}"] as List<String>)
569
+ .map((item) => DateTime.parse(item)).toList() : ${fallback}`,
570
+ toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toIso8601String()).toList()`
571
+ },
572
+ Uint8List: {
573
+ fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List ? Uint8List.fromList(json["${jsonKey}"]) : ${fallback}`,
574
+ toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toList()`
575
+ },
576
+ "List<Uint8List>": {
577
+ fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List && (json["${jsonKey}"] as List).isNotEmpty && (json["${jsonKey}"] as List).first is List ? json["${jsonKey}"] : ${fallback}`,
578
+ toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toList()).toList()`
579
+ }
580
+ };
581
+ function defaultFromJsonBody(key, jsonKey, typename, fallback) {
582
+ return `${key}: json["${jsonKey}"] is ${typename} ? json["${jsonKey}"] : ${fallback}`;
583
+ }
584
+ function defaultListFromJsonBody(key, jsonKey, typename, fallback) {
585
+ return `${key}: json["${jsonKey}"] is List<${typename}> ? json["${jsonKey}"] : ${fallback}`;
586
+ }
587
+ function defaultToJsonBody(key, jsonKey) {
588
+ return `"${jsonKey}": ${key}`;
589
+ }
590
+ const classTransformer = (typename, nullable) => {
591
+ return {
592
+ fromJsonBody: (key, jsonKey, fallback) => {
593
+ if (nullable) {
594
+ return `${key}: json["${jsonKey}"] is Map<String, dynamic> ?
595
+ ${typename}.fromJson(json["${jsonKey}"]) : null`;
596
+ }
597
+ return `${key}: ${typename}.fromJson(json["${jsonKey}"])`;
598
+ },
599
+ toJsonBody: (key, jsonKey, isNullable) => {
600
+ return `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toJson()`;
601
+ }
602
+ };
603
+ };
604
+ const classListTransformer = (typename) => {
605
+ return {
606
+ fromJsonBody: (key, jsonKey, fallback) => {
607
+ return `${key}: json["${jsonKey}"] is List<Map<String, dynamic>> ?
608
+ (json["${jsonKey}"] as List<Map<String, dynamic>>)
609
+ .map((val) => ${typename}.fromJson(val)).toList() : ${fallback}`;
610
+ },
611
+ toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toJson()).toList()`
612
+ };
613
+ };
614
+ function isDartType(input) {
615
+ if (typeof input !== "string") {
616
+ return false;
617
+ }
618
+ for (const val of Object.values(dartTypeMap)) {
619
+ if (input === val) {
620
+ return true;
621
+ }
622
+ if (input.replace("List<", "").replace(">", "") === val) {
623
+ return true;
624
+ }
625
+ }
626
+ return false;
627
+ }
628
+ function isDartTypeWithNullables(input) {
629
+ if (typeof input !== "string") {
630
+ return false;
631
+ }
632
+ for (const val of Object.values(dartTypeMap)) {
633
+ if (input.replace("?", "") === val) {
634
+ return true;
635
+ }
636
+ if (input.replace("?", "").replace("List<", "").replace(">", "") === val) {
637
+ return true;
638
+ }
639
+ }
640
+ return false;
641
+ }
642
+
643
+ exports.classListTransformer = classListTransformer;
644
+ exports.classTransformer = classTransformer;
645
+ exports.createDartClient = createDartClient;
646
+ exports.dartClientGenerator = dartClientGenerator;
647
+ exports.dartModelFromJsonSchema = dartModelFromJsonSchema;
648
+ exports.dartParsedJsonField = dartParsedJsonField;
649
+ exports.dartProcedureFromServiceDefinition = dartProcedureFromServiceDefinition;
650
+ exports.dartPropertyTypeFromSchema = dartPropertyTypeFromSchema;
651
+ exports.dartServiceFromServiceDefinition = dartServiceFromServiceDefinition;
652
+ exports.defineClientGeneratorPlugin = defineClientGeneratorPlugin;
653
+ exports.isDartType = isDartType;
654
+ exports.isDartTypeWithNullables = isDartTypeWithNullables;
655
+ exports.transformers = transformers;