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