arri 0.0.44 → 0.1.0-beta.2

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