arri 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/index.cjs +1 -1
- package/dist/chunks/index.mjs +1 -1
- package/dist/chunks/index2.cjs +1 -1
- package/dist/chunks/index2.mjs +1 -1
- package/dist/chunks/index3.cjs +1 -1
- package/dist/chunks/index3.mjs +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.d.cts +11 -8
- package/dist/codegen.d.mts +11 -8
- package/dist/codegen.d.ts +11 -8
- package/dist/codegen.mjs +2 -2
- package/dist/shared/{arri.0e69fc28.mjs → arri.d491643b.mjs} +130 -96
- package/dist/shared/{arri.835c5c3c.cjs → arri.dd4e8564.cjs} +133 -99
- package/package.json +1 -1
package/dist/chunks/index.cjs
CHANGED
|
@@ -29,7 +29,7 @@ require('node:module');
|
|
|
29
29
|
require('node:assert');
|
|
30
30
|
require('node:v8');
|
|
31
31
|
require('node:util');
|
|
32
|
-
require('../shared/arri.
|
|
32
|
+
require('../shared/arri.dd4e8564.cjs');
|
|
33
33
|
require('fs/promises');
|
|
34
34
|
require('child_process');
|
|
35
35
|
require('node:http');
|
package/dist/chunks/index.mjs
CHANGED
package/dist/chunks/index2.cjs
CHANGED
|
@@ -31,7 +31,7 @@ require('node:module');
|
|
|
31
31
|
require('node:assert');
|
|
32
32
|
require('node:v8');
|
|
33
33
|
require('node:util');
|
|
34
|
-
require('../shared/arri.
|
|
34
|
+
require('../shared/arri.dd4e8564.cjs');
|
|
35
35
|
require('fs/promises');
|
|
36
36
|
require('child_process');
|
|
37
37
|
require('node:http');
|
package/dist/chunks/index2.mjs
CHANGED
package/dist/chunks/index3.cjs
CHANGED
package/dist/chunks/index3.mjs
CHANGED
package/dist/cli.cjs
CHANGED
|
@@ -29,7 +29,7 @@ const node_module = require('node:module');
|
|
|
29
29
|
const assert = require('node:assert');
|
|
30
30
|
const v8$1 = require('node:v8');
|
|
31
31
|
const node_util = require('node:util');
|
|
32
|
-
const dart = require('./shared/arri.
|
|
32
|
+
const dart = require('./shared/arri.dd4e8564.cjs');
|
|
33
33
|
const node_http = require('node:http');
|
|
34
34
|
const https = require('node:https');
|
|
35
35
|
const node_net = require('node:net');
|
package/dist/cli.mjs
CHANGED
|
@@ -27,7 +27,7 @@ import { builtinModules } from 'node:module';
|
|
|
27
27
|
import assert from 'node:assert';
|
|
28
28
|
import v8$1 from 'node:v8';
|
|
29
29
|
import { format as format$1, inspect, promisify as promisify$5 } from 'node:util';
|
|
30
|
-
import { f as format2, a as dartClientGenerator } from './shared/arri.
|
|
30
|
+
import { f as format2, a as dartClientGenerator } from './shared/arri.d491643b.mjs';
|
|
31
31
|
import { createServer as createServer$2 } from 'node:http';
|
|
32
32
|
import { createServer as createServer$1 } from 'node:https';
|
|
33
33
|
import { createServer } from 'node:net';
|
package/dist/codegen.cjs
CHANGED
package/dist/codegen.d.cts
CHANGED
|
@@ -24,12 +24,15 @@ interface DartClientGeneratorOptions {
|
|
|
24
24
|
outputFile: string;
|
|
25
25
|
}
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare function
|
|
31
|
-
declare function
|
|
32
|
-
declare function
|
|
27
|
+
interface CreateClientOptions {
|
|
28
|
+
clientName: string;
|
|
29
|
+
}
|
|
30
|
+
declare function createDartClient(appDef: ApplicationDefinition, opts?: CreateClientOptions): string;
|
|
31
|
+
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, opts: CreateClientOptions): string;
|
|
32
|
+
declare function dartProcedureFromServiceDefinition(key: string, def: ProcedureDefinition, opts: CreateClientOptions): string;
|
|
33
|
+
declare function dartModelFromJsonSchema(modelName: string, schema: JsonSchemaObject, opts: CreateClientOptions): string;
|
|
34
|
+
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject, opts: CreateClientOptions): [DartType | string, string[] | undefined];
|
|
35
|
+
declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
|
|
33
36
|
declare const dartTypeMap: {
|
|
34
37
|
readonly integer: "int";
|
|
35
38
|
readonly bigint: "int";
|
|
@@ -46,8 +49,8 @@ declare const dartTypeMap: {
|
|
|
46
49
|
};
|
|
47
50
|
interface DartMappedType {
|
|
48
51
|
classBody?: string;
|
|
49
|
-
fromJsonBody: (jsonKey: string, fallback: string) => string;
|
|
50
|
-
toJsonBody: (key: string, isNullable?: boolean) => string;
|
|
52
|
+
fromJsonBody: (key: string, jsonKey: string, fallback: string) => string;
|
|
53
|
+
toJsonBody: (key: string, jsonKey: string, isNullable?: boolean) => string;
|
|
51
54
|
}
|
|
52
55
|
declare const transformers: Record<DartType, DartMappedType>;
|
|
53
56
|
declare const classTransformer: (typename: string, nullable: boolean) => DartMappedType;
|
package/dist/codegen.d.mts
CHANGED
|
@@ -24,12 +24,15 @@ interface DartClientGeneratorOptions {
|
|
|
24
24
|
outputFile: string;
|
|
25
25
|
}
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare function
|
|
31
|
-
declare function
|
|
32
|
-
declare function
|
|
27
|
+
interface CreateClientOptions {
|
|
28
|
+
clientName: string;
|
|
29
|
+
}
|
|
30
|
+
declare function createDartClient(appDef: ApplicationDefinition, opts?: CreateClientOptions): string;
|
|
31
|
+
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, opts: CreateClientOptions): string;
|
|
32
|
+
declare function dartProcedureFromServiceDefinition(key: string, def: ProcedureDefinition, opts: CreateClientOptions): string;
|
|
33
|
+
declare function dartModelFromJsonSchema(modelName: string, schema: JsonSchemaObject, opts: CreateClientOptions): string;
|
|
34
|
+
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject, opts: CreateClientOptions): [DartType | string, string[] | undefined];
|
|
35
|
+
declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
|
|
33
36
|
declare const dartTypeMap: {
|
|
34
37
|
readonly integer: "int";
|
|
35
38
|
readonly bigint: "int";
|
|
@@ -46,8 +49,8 @@ declare const dartTypeMap: {
|
|
|
46
49
|
};
|
|
47
50
|
interface DartMappedType {
|
|
48
51
|
classBody?: string;
|
|
49
|
-
fromJsonBody: (jsonKey: string, fallback: string) => string;
|
|
50
|
-
toJsonBody: (key: string, isNullable?: boolean) => string;
|
|
52
|
+
fromJsonBody: (key: string, jsonKey: string, fallback: string) => string;
|
|
53
|
+
toJsonBody: (key: string, jsonKey: string, isNullable?: boolean) => string;
|
|
51
54
|
}
|
|
52
55
|
declare const transformers: Record<DartType, DartMappedType>;
|
|
53
56
|
declare const classTransformer: (typename: string, nullable: boolean) => DartMappedType;
|
package/dist/codegen.d.ts
CHANGED
|
@@ -24,12 +24,15 @@ interface DartClientGeneratorOptions {
|
|
|
24
24
|
outputFile: string;
|
|
25
25
|
}
|
|
26
26
|
declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare function
|
|
31
|
-
declare function
|
|
32
|
-
declare function
|
|
27
|
+
interface CreateClientOptions {
|
|
28
|
+
clientName: string;
|
|
29
|
+
}
|
|
30
|
+
declare function createDartClient(appDef: ApplicationDefinition, opts?: CreateClientOptions): string;
|
|
31
|
+
declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, opts: CreateClientOptions): string;
|
|
32
|
+
declare function dartProcedureFromServiceDefinition(key: string, def: ProcedureDefinition, opts: CreateClientOptions): string;
|
|
33
|
+
declare function dartModelFromJsonSchema(modelName: string, schema: JsonSchemaObject, opts: CreateClientOptions): string;
|
|
34
|
+
declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject, opts: CreateClientOptions): [DartType | string, string[] | undefined];
|
|
35
|
+
declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
|
|
33
36
|
declare const dartTypeMap: {
|
|
34
37
|
readonly integer: "int";
|
|
35
38
|
readonly bigint: "int";
|
|
@@ -46,8 +49,8 @@ declare const dartTypeMap: {
|
|
|
46
49
|
};
|
|
47
50
|
interface DartMappedType {
|
|
48
51
|
classBody?: string;
|
|
49
|
-
fromJsonBody: (jsonKey: string, fallback: string) => string;
|
|
50
|
-
toJsonBody: (key: string, isNullable?: boolean) => string;
|
|
52
|
+
fromJsonBody: (key: string, jsonKey: string, fallback: string) => string;
|
|
53
|
+
toJsonBody: (key: string, jsonKey: string, isNullable?: boolean) => string;
|
|
51
54
|
}
|
|
52
55
|
declare const transformers: Record<DartType, DartMappedType>;
|
|
53
56
|
declare const classTransformer: (typename: string, nullable: boolean) => DartMappedType;
|
package/dist/codegen.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as unflattenObject, i as isServiceDefinition, p as pascalCase, a as isProcedureDefinition, b as isJsonSchemaScalarType, c as isJsonSchemaNullType, d as isJsonSchemaObject, e as isJsonSchemaEnum, f as isJsonSchemaArray } from './shared/arri.1f1b9dfc.mjs';
|
|
2
|
-
import { d as defineClientGeneratorPlugin, f as format2 } from './shared/arri.
|
|
3
|
-
export { k as classListTransformer, j as classTransformer, c as createDartClient, a as dartClientGenerator, g as dartModelFromJsonSchema, i as dartParsedJsonField, e as dartProcedureFromServiceDefinition, h as dartPropertyTypeFromSchema, b as dartServiceFromServiceDefinition, l as isDartType, m as isDartTypeWithNullables, t as transformers } from './shared/arri.
|
|
2
|
+
import { d as defineClientGeneratorPlugin, f as format2 } from './shared/arri.d491643b.mjs';
|
|
3
|
+
export { k as classListTransformer, j as classTransformer, c as createDartClient, a as dartClientGenerator, g as dartModelFromJsonSchema, i as dartParsedJsonField, e as dartProcedureFromServiceDefinition, h as dartPropertyTypeFromSchema, b as dartServiceFromServiceDefinition, l as isDartType, m as isDartTypeWithNullables, t as transformers } from './shared/arri.d491643b.mjs';
|
|
4
4
|
import { writeFileSync } from 'fs';
|
|
5
5
|
import 'module';
|
|
6
6
|
import 'url';
|
|
@@ -9,7 +9,7 @@ import assert4 from 'assert';
|
|
|
9
9
|
import fs from 'fs/promises';
|
|
10
10
|
import v8 from 'v8';
|
|
11
11
|
import { format, inspect } from 'util';
|
|
12
|
-
import { g as unflattenProcedures, i as isServiceDefinition, p as pascalCase, h as camelCase, a as isProcedureDefinition, e as isJsonSchemaEnum, c as isJsonSchemaNullType, b as isJsonSchemaScalarType,
|
|
12
|
+
import { g as unflattenProcedures, i as isServiceDefinition, p as pascalCase, h as camelCase, a as isProcedureDefinition, d as isJsonSchemaObject, e as isJsonSchemaEnum, c as isJsonSchemaNullType, b as isJsonSchemaScalarType, f as isJsonSchemaArray } from './arri.1f1b9dfc.mjs';
|
|
13
13
|
import { execSync } from 'child_process';
|
|
14
14
|
|
|
15
15
|
const require$1 = createRequire(import.meta.url);
|
|
@@ -29047,7 +29047,9 @@ const dartClientGenerator = defineClientGeneratorPlugin(
|
|
|
29047
29047
|
'Missing "outputFile" cannot generate dart client'
|
|
29048
29048
|
);
|
|
29049
29049
|
}
|
|
29050
|
-
const result = createDartClient(def,
|
|
29050
|
+
const result = createDartClient(def, {
|
|
29051
|
+
clientName: options.clientName
|
|
29052
|
+
});
|
|
29051
29053
|
writeFileSync(options.outputFile, result);
|
|
29052
29054
|
execSync(`dart format ${options.outputFile}`);
|
|
29053
29055
|
},
|
|
@@ -29056,7 +29058,7 @@ const dartClientGenerator = defineClientGeneratorPlugin(
|
|
|
29056
29058
|
}
|
|
29057
29059
|
);
|
|
29058
29060
|
const generatedModels = [];
|
|
29059
|
-
function createDartClient(appDef,
|
|
29061
|
+
function createDartClient(appDef, opts = { clientName: "Client" }) {
|
|
29060
29062
|
const { models, procedures } = appDef;
|
|
29061
29063
|
const serviceParts = [];
|
|
29062
29064
|
const procedureParts = [];
|
|
@@ -29064,22 +29066,18 @@ function createDartClient(appDef, prefix = "Client") {
|
|
|
29064
29066
|
Object.keys(services).forEach((k) => {
|
|
29065
29067
|
const item = services[k];
|
|
29066
29068
|
if (isServiceDefinition(item)) {
|
|
29067
|
-
const serviceName = pascalCase(`${
|
|
29069
|
+
const serviceName = pascalCase(`${opts.clientName}_${k}_service`);
|
|
29068
29070
|
serviceParts.push({
|
|
29069
29071
|
name: serviceName,
|
|
29070
29072
|
key: k,
|
|
29071
29073
|
content: dartServiceFromServiceDefinition(
|
|
29072
29074
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
29073
29075
|
serviceName,
|
|
29074
|
-
item
|
|
29075
|
-
prefix
|
|
29076
|
-
)
|
|
29076
|
+
item)
|
|
29077
29077
|
});
|
|
29078
29078
|
return;
|
|
29079
29079
|
}
|
|
29080
|
-
procedureParts.push(
|
|
29081
|
-
dartProcedureFromServiceDefinition(prefix, k, item)
|
|
29082
|
-
);
|
|
29080
|
+
procedureParts.push(dartProcedureFromServiceDefinition(k, item));
|
|
29083
29081
|
});
|
|
29084
29082
|
const endpoints = {};
|
|
29085
29083
|
Object.keys(procedures).forEach((key) => {
|
|
@@ -29089,14 +29087,11 @@ function createDartClient(appDef, prefix = "Client") {
|
|
|
29089
29087
|
const modelParts = [];
|
|
29090
29088
|
Object.keys(models).forEach((key) => {
|
|
29091
29089
|
const model = models[key];
|
|
29092
|
-
const typeName =
|
|
29090
|
+
const typeName = pascalCase(key);
|
|
29093
29091
|
const objModel = model;
|
|
29094
29092
|
if (!generatedModels.includes(typeName)) {
|
|
29095
29093
|
modelParts.push(
|
|
29096
|
-
dartModelFromJsonSchema(
|
|
29097
|
-
`${prefix}${pascalCase(key)}`,
|
|
29098
|
-
objModel
|
|
29099
|
-
)
|
|
29094
|
+
dartModelFromJsonSchema(`${pascalCase(key)}`, objModel)
|
|
29100
29095
|
);
|
|
29101
29096
|
generatedModels.push(typeName);
|
|
29102
29097
|
}
|
|
@@ -29106,10 +29101,10 @@ import "dart:convert";
|
|
|
29106
29101
|
import "package:http/http.dart" as http;
|
|
29107
29102
|
import "package:arri_client/arri_client.dart";
|
|
29108
29103
|
|
|
29109
|
-
class ${
|
|
29104
|
+
class ${opts.clientName} {
|
|
29110
29105
|
final String _baseUrl;
|
|
29111
29106
|
final Map<String, String> _headers;
|
|
29112
|
-
const ${
|
|
29107
|
+
const ${opts.clientName}({
|
|
29113
29108
|
String baseUrl = "",
|
|
29114
29109
|
Map<String, String> headers = const {},
|
|
29115
29110
|
}): _headers = headers,
|
|
@@ -29123,7 +29118,7 @@ class ${prefix} {
|
|
|
29123
29118
|
}`
|
|
29124
29119
|
).join("\n ")}
|
|
29125
29120
|
Future<http.Response> rawRequest(
|
|
29126
|
-
${
|
|
29121
|
+
${opts.clientName}Endpoints endpoint, {
|
|
29127
29122
|
Map<String, String>? query,
|
|
29128
29123
|
dynamic body,
|
|
29129
29124
|
Map<String, String>? headers,
|
|
@@ -29132,7 +29127,7 @@ class ${prefix} {
|
|
|
29132
29127
|
return arriRequest(
|
|
29133
29128
|
"$_baseUrl\${endpoint.path}",
|
|
29134
29129
|
method: endpoint.method,
|
|
29135
|
-
headers: headers ??
|
|
29130
|
+
headers: headers ?? _headers,
|
|
29136
29131
|
body: body,
|
|
29137
29132
|
query: query,
|
|
29138
29133
|
encoding: encoding,
|
|
@@ -29142,7 +29137,7 @@ class ${prefix} {
|
|
|
29142
29137
|
${serviceParts.map((item) => item.content).join("\n")}
|
|
29143
29138
|
${modelParts.join("\n")}
|
|
29144
29139
|
|
|
29145
|
-
enum ${
|
|
29140
|
+
enum ${opts.clientName}Endpoints implements Comparable<${opts.clientName}Endpoints>, ArriEndpoint {
|
|
29146
29141
|
${Object.keys(endpoints).map(
|
|
29147
29142
|
(key) => `${camelCase(key.split("/").join("_"))}(
|
|
29148
29143
|
path: "${key}",
|
|
@@ -29150,7 +29145,7 @@ enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint
|
|
|
29150
29145
|
)`
|
|
29151
29146
|
).join(",\n ")};
|
|
29152
29147
|
|
|
29153
|
-
const ${
|
|
29148
|
+
const ${opts.clientName}Endpoints({
|
|
29154
29149
|
required this.path, required this.method,
|
|
29155
29150
|
});
|
|
29156
29151
|
@override
|
|
@@ -29159,19 +29154,17 @@ enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint
|
|
|
29159
29154
|
final HttpMethod method;
|
|
29160
29155
|
|
|
29161
29156
|
@override
|
|
29162
|
-
compareTo(${
|
|
29157
|
+
compareTo(${opts.clientName}Endpoints other) => name.compareTo(other.name);
|
|
29163
29158
|
}`;
|
|
29164
29159
|
}
|
|
29165
|
-
function dartServiceFromServiceDefinition(name, def,
|
|
29160
|
+
function dartServiceFromServiceDefinition(name, def, opts) {
|
|
29166
29161
|
const rpcParts = [];
|
|
29167
29162
|
const subServiceParts = [];
|
|
29168
29163
|
const serviceName = `${name}`;
|
|
29169
29164
|
Object.keys(def).forEach((key) => {
|
|
29170
29165
|
const item = def[key];
|
|
29171
29166
|
if (isProcedureDefinition(item)) {
|
|
29172
|
-
rpcParts.push(
|
|
29173
|
-
dartProcedureFromServiceDefinition(prefix, key, item)
|
|
29174
|
-
);
|
|
29167
|
+
rpcParts.push(dartProcedureFromServiceDefinition(key, item));
|
|
29175
29168
|
return;
|
|
29176
29169
|
}
|
|
29177
29170
|
const nameParts = name.split("Service");
|
|
@@ -29181,9 +29174,7 @@ function dartServiceFromServiceDefinition(name, def, prefix = "") {
|
|
|
29181
29174
|
);
|
|
29182
29175
|
const subService = dartServiceFromServiceDefinition(
|
|
29183
29176
|
subServiceName,
|
|
29184
|
-
item
|
|
29185
|
-
prefix
|
|
29186
|
-
);
|
|
29177
|
+
item);
|
|
29187
29178
|
subServiceParts.push({
|
|
29188
29179
|
name: subServiceName,
|
|
29189
29180
|
key,
|
|
@@ -29211,18 +29202,18 @@ function dartServiceFromServiceDefinition(name, def, prefix = "") {
|
|
|
29211
29202
|
${subServiceParts.map((sub) => sub.content).join("\n")}
|
|
29212
29203
|
`;
|
|
29213
29204
|
}
|
|
29214
|
-
function dartProcedureFromServiceDefinition(
|
|
29205
|
+
function dartProcedureFromServiceDefinition(key, def, opts) {
|
|
29215
29206
|
let returnType = `Future<String>`;
|
|
29216
29207
|
let returnTypeName = "String";
|
|
29217
29208
|
if (def.response) {
|
|
29218
|
-
returnType = `Future<${
|
|
29219
|
-
returnTypeName = `${
|
|
29209
|
+
returnType = `Future<${def.response}>`;
|
|
29210
|
+
returnTypeName = `${def.response}`;
|
|
29220
29211
|
} else {
|
|
29221
29212
|
returnType = "Future<void>";
|
|
29222
29213
|
}
|
|
29223
29214
|
let paramsInput = "";
|
|
29224
29215
|
if (def.params) {
|
|
29225
|
-
paramsInput = `${
|
|
29216
|
+
paramsInput = `${def.params} params`;
|
|
29226
29217
|
}
|
|
29227
29218
|
let responseParser = "(body) => body;";
|
|
29228
29219
|
switch (returnType) {
|
|
@@ -29264,7 +29255,8 @@ function dartProcedureFromServiceDefinition(clientName, key, def) {
|
|
|
29264
29255
|
);
|
|
29265
29256
|
}`;
|
|
29266
29257
|
}
|
|
29267
|
-
function dartModelFromJsonSchema(
|
|
29258
|
+
function dartModelFromJsonSchema(modelName, schema, opts) {
|
|
29259
|
+
const modelDisplayName = pascalCase(`${modelName}`);
|
|
29268
29260
|
const fields = [];
|
|
29269
29261
|
const subModelParts = [];
|
|
29270
29262
|
Object.entries(schema.properties ?? {}).forEach(([key, val]) => {
|
|
@@ -29272,32 +29264,42 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29272
29264
|
return;
|
|
29273
29265
|
}
|
|
29274
29266
|
const [dartType, subTypes] = dartPropertyTypeFromSchema(
|
|
29275
|
-
|
|
29267
|
+
modelName,
|
|
29276
29268
|
key,
|
|
29277
|
-
schema
|
|
29278
|
-
);
|
|
29269
|
+
schema);
|
|
29279
29270
|
if (subTypes?.length) {
|
|
29280
29271
|
for (const sub of subTypes) {
|
|
29281
29272
|
subModelParts.push(sub);
|
|
29282
29273
|
}
|
|
29283
29274
|
}
|
|
29284
|
-
fields.push({ type: dartType, name: key });
|
|
29285
|
-
if (!isDartType(dartType) &&
|
|
29275
|
+
fields.push({ type: dartType, name: camelCase(key), jsonKey: key });
|
|
29276
|
+
if (!isDartType(dartType) && isJsonSchemaObject(val)) {
|
|
29277
|
+
if (val.$id && generatedModels.includes(val.$id)) {
|
|
29278
|
+
return;
|
|
29279
|
+
}
|
|
29280
|
+
const subModelName = val.$id ? pascalCase(val.$id) : pascalCase(dartType.replace("?", ""));
|
|
29286
29281
|
subModelParts.push(
|
|
29287
|
-
dartModelFromJsonSchema(
|
|
29282
|
+
dartModelFromJsonSchema(subModelName, val)
|
|
29288
29283
|
);
|
|
29284
|
+
generatedModels.push(subModelName);
|
|
29289
29285
|
}
|
|
29290
29286
|
});
|
|
29291
|
-
return `class ${
|
|
29287
|
+
return `class ${modelDisplayName} {
|
|
29292
29288
|
${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
|
|
29293
|
-
const ${
|
|
29289
|
+
const ${modelDisplayName}({
|
|
29294
29290
|
${fields.map(
|
|
29295
29291
|
(field) => field.type.includes("?") ? `this.${field.name},` : `required this.${field.name},`
|
|
29296
29292
|
).join("\n ")}
|
|
29297
29293
|
});
|
|
29298
|
-
factory ${
|
|
29299
|
-
return ${
|
|
29300
|
-
${fields.map(
|
|
29294
|
+
factory ${modelDisplayName}.fromJson(Map<String, dynamic> json) {
|
|
29295
|
+
return ${modelDisplayName}(
|
|
29296
|
+
${fields.map(
|
|
29297
|
+
(field) => `${dartParsedJsonField(
|
|
29298
|
+
field.name,
|
|
29299
|
+
field.jsonKey,
|
|
29300
|
+
field.type
|
|
29301
|
+
)},`
|
|
29302
|
+
).join("\n ")}
|
|
29301
29303
|
);
|
|
29302
29304
|
}
|
|
29303
29305
|
Map<String, dynamic> toJson() {
|
|
@@ -29307,25 +29309,31 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29307
29309
|
const typeName = field.type.replace("?", "");
|
|
29308
29310
|
if (isDartTypeWithNullables(field.type)) {
|
|
29309
29311
|
const transformer = transformers[typeName];
|
|
29310
|
-
return transformer.toJsonBody(
|
|
29312
|
+
return transformer.toJsonBody(
|
|
29313
|
+
field.name,
|
|
29314
|
+
field.jsonKey,
|
|
29315
|
+
isNullable
|
|
29316
|
+
);
|
|
29311
29317
|
}
|
|
29312
29318
|
if (field.type.includes("List<")) {
|
|
29313
29319
|
return classListTransformer(typeName).toJsonBody(
|
|
29314
29320
|
field.name,
|
|
29321
|
+
field.jsonKey,
|
|
29315
29322
|
isNullable
|
|
29316
29323
|
);
|
|
29317
29324
|
}
|
|
29318
29325
|
return classTransformer(typeName, isNullable).toJsonBody(
|
|
29319
29326
|
field.name,
|
|
29327
|
+
field.jsonKey,
|
|
29320
29328
|
isNullable
|
|
29321
29329
|
);
|
|
29322
29330
|
}).join(",\n ")},
|
|
29323
29331
|
};
|
|
29324
29332
|
}
|
|
29325
|
-
${
|
|
29333
|
+
${modelDisplayName} copyWith({
|
|
29326
29334
|
${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
|
|
29327
29335
|
}) {
|
|
29328
|
-
return ${
|
|
29336
|
+
return ${modelDisplayName}(
|
|
29329
29337
|
${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
|
|
29330
29338
|
);
|
|
29331
29339
|
}
|
|
@@ -29333,7 +29341,7 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29333
29341
|
|
|
29334
29342
|
${subModelParts.join("\n")}`;
|
|
29335
29343
|
}
|
|
29336
|
-
function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
29344
|
+
function dartPropertyTypeFromSchema(objectName, propertyName, schema, opts) {
|
|
29337
29345
|
const prop = schema.properties?.[propertyName];
|
|
29338
29346
|
const isOptional = !schema.required?.includes(propertyName);
|
|
29339
29347
|
let finalType = "";
|
|
@@ -29409,9 +29417,7 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29409
29417
|
}
|
|
29410
29418
|
}
|
|
29411
29419
|
if (isJsonSchemaObject(prop)) {
|
|
29412
|
-
const joinedPropName = pascalCase(
|
|
29413
|
-
`${objectName}_${propertyName}`
|
|
29414
|
-
);
|
|
29420
|
+
const joinedPropName = prop.$id ? pascalCase(prop.$id) : pascalCase(`${objectName}_${propertyName}`);
|
|
29415
29421
|
finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
|
|
29416
29422
|
}
|
|
29417
29423
|
if (isJsonSchemaArray(prop)) {
|
|
@@ -29443,8 +29449,10 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29443
29449
|
break;
|
|
29444
29450
|
case "object": {
|
|
29445
29451
|
const subTypeName = item.$id ?? pascalCase(`${objectName}_${propertyName}_item`);
|
|
29446
|
-
const model = dartModelFromJsonSchema(subTypeName, item);
|
|
29447
29452
|
if (!generatedModels.includes(subTypeName)) {
|
|
29453
|
+
const model = dartModelFromJsonSchema(
|
|
29454
|
+
subTypeName,
|
|
29455
|
+
item);
|
|
29448
29456
|
subTypes.push(model);
|
|
29449
29457
|
generatedModels.push(subTypeName);
|
|
29450
29458
|
}
|
|
@@ -29455,28 +29463,49 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29455
29463
|
}
|
|
29456
29464
|
return [finalType, subTypes.length ? subTypes : void 0];
|
|
29457
29465
|
}
|
|
29458
|
-
function dartParsedJsonField(fieldName, dartType) {
|
|
29466
|
+
function dartParsedJsonField(fieldName, jsonKey, dartType) {
|
|
29459
29467
|
if (isDartTypeWithNullables(dartType)) {
|
|
29460
29468
|
switch (dartType) {
|
|
29461
29469
|
case "String":
|
|
29462
|
-
return transformers.String.fromJsonBody(
|
|
29470
|
+
return transformers.String.fromJsonBody(
|
|
29471
|
+
fieldName,
|
|
29472
|
+
jsonKey,
|
|
29473
|
+
'""'
|
|
29474
|
+
);
|
|
29463
29475
|
case "String?":
|
|
29464
|
-
return transformers.String.fromJsonBody(
|
|
29476
|
+
return transformers.String.fromJsonBody(
|
|
29477
|
+
fieldName,
|
|
29478
|
+
jsonKey,
|
|
29479
|
+
"null"
|
|
29480
|
+
);
|
|
29465
29481
|
case "bool":
|
|
29466
|
-
return transformers.bool.fromJsonBody(
|
|
29482
|
+
return transformers.bool.fromJsonBody(
|
|
29483
|
+
fieldName,
|
|
29484
|
+
jsonKey,
|
|
29485
|
+
"false"
|
|
29486
|
+
);
|
|
29467
29487
|
case "double":
|
|
29468
|
-
return transformers.double.fromJsonBody(
|
|
29488
|
+
return transformers.double.fromJsonBody(
|
|
29489
|
+
fieldName,
|
|
29490
|
+
jsonKey,
|
|
29491
|
+
"0.0"
|
|
29492
|
+
);
|
|
29469
29493
|
case "int":
|
|
29470
|
-
return transformers.int.fromJsonBody(fieldName, "0");
|
|
29494
|
+
return transformers.int.fromJsonBody(fieldName, jsonKey, "0");
|
|
29471
29495
|
case "null":
|
|
29472
|
-
return transformers.null.fromJsonBody(fieldName, "");
|
|
29496
|
+
return transformers.null.fromJsonBody(fieldName, jsonKey, "");
|
|
29473
29497
|
case "DateTime":
|
|
29474
29498
|
return transformers.DateTime.fromJsonBody(
|
|
29475
29499
|
fieldName,
|
|
29500
|
+
jsonKey,
|
|
29476
29501
|
"DateTime(0)"
|
|
29477
29502
|
);
|
|
29478
29503
|
case "DateTime?":
|
|
29479
|
-
return transformers.DateTime.fromJsonBody(
|
|
29504
|
+
return transformers.DateTime.fromJsonBody(
|
|
29505
|
+
fieldName,
|
|
29506
|
+
jsonKey,
|
|
29507
|
+
"null"
|
|
29508
|
+
);
|
|
29480
29509
|
case "List<String>":
|
|
29481
29510
|
case "List<bool>":
|
|
29482
29511
|
case "List<double>":
|
|
@@ -29484,26 +29513,29 @@ function dartParsedJsonField(fieldName, dartType) {
|
|
|
29484
29513
|
case "List<null>":
|
|
29485
29514
|
return defaultListFromJsonBody(
|
|
29486
29515
|
fieldName,
|
|
29516
|
+
jsonKey,
|
|
29487
29517
|
dartType.replace("List<", "").replace(">", ""),
|
|
29488
29518
|
"[]"
|
|
29489
29519
|
);
|
|
29490
29520
|
default:
|
|
29491
|
-
return `${fieldName}: json["${
|
|
29521
|
+
return `${fieldName}: json["${jsonKey}"] is ${dartType.replace(
|
|
29492
29522
|
"?",
|
|
29493
29523
|
""
|
|
29494
|
-
)} ? json["${
|
|
29524
|
+
)} ? json["${jsonKey}"] : null`;
|
|
29495
29525
|
}
|
|
29496
29526
|
}
|
|
29497
29527
|
if (dartType.includes("List<")) {
|
|
29498
29528
|
const innerType = dartType.replace("List<", "").replace(">", "").replace("?", "");
|
|
29499
29529
|
return classListTransformer(innerType).fromJsonBody(
|
|
29500
29530
|
fieldName,
|
|
29531
|
+
jsonKey,
|
|
29501
29532
|
dartType.endsWith("?") ? "null" : "[]"
|
|
29502
29533
|
);
|
|
29503
29534
|
}
|
|
29504
29535
|
const classType = dartType.split("?").join("").trim();
|
|
29505
29536
|
return classTransformer(classType, dartType.endsWith("?")).fromJsonBody(
|
|
29506
29537
|
fieldName,
|
|
29538
|
+
jsonKey,
|
|
29507
29539
|
classType
|
|
29508
29540
|
);
|
|
29509
29541
|
}
|
|
@@ -29528,89 +29560,91 @@ const transformers = {
|
|
|
29528
29560
|
toJsonBody: defaultToJsonBody
|
|
29529
29561
|
},
|
|
29530
29562
|
int: {
|
|
29531
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "int", fallback),
|
|
29563
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "int", fallback),
|
|
29532
29564
|
toJsonBody: defaultToJsonBody
|
|
29533
29565
|
},
|
|
29534
29566
|
double: {
|
|
29535
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "double", fallback),
|
|
29567
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "double", fallback),
|
|
29536
29568
|
toJsonBody: defaultToJsonBody
|
|
29537
29569
|
},
|
|
29538
29570
|
String: {
|
|
29539
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "String", fallback),
|
|
29571
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "String", fallback),
|
|
29540
29572
|
toJsonBody: defaultToJsonBody
|
|
29541
29573
|
},
|
|
29542
29574
|
bool: {
|
|
29543
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "bool", fallback),
|
|
29575
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "bool", fallback),
|
|
29544
29576
|
toJsonBody: defaultToJsonBody
|
|
29545
29577
|
},
|
|
29546
29578
|
DateTime: {
|
|
29547
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29548
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29579
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is String ? DateTime.parse(json["${jsonKey}"]) : ${fallback}`,
|
|
29580
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toIso8601String()`
|
|
29549
29581
|
},
|
|
29550
29582
|
"List<null>": {
|
|
29551
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "null", fallback),
|
|
29583
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "null", fallback),
|
|
29552
29584
|
toJsonBody: defaultToJsonBody
|
|
29553
29585
|
},
|
|
29554
29586
|
"List<int>": {
|
|
29555
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "int", fallback),
|
|
29587
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "int", fallback),
|
|
29556
29588
|
toJsonBody: defaultToJsonBody
|
|
29557
29589
|
},
|
|
29558
29590
|
"List<double>": {
|
|
29559
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "double", fallback),
|
|
29591
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "double", fallback),
|
|
29560
29592
|
toJsonBody: defaultToJsonBody
|
|
29561
29593
|
},
|
|
29562
29594
|
"List<String>": {
|
|
29563
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "String", fallback),
|
|
29595
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "String", fallback),
|
|
29564
29596
|
toJsonBody: defaultToJsonBody
|
|
29565
29597
|
},
|
|
29566
29598
|
"List<bool>": {
|
|
29567
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "bool", fallback),
|
|
29599
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "bool", fallback),
|
|
29568
29600
|
toJsonBody: defaultToJsonBody
|
|
29569
29601
|
},
|
|
29570
29602
|
"List<DateTime>": {
|
|
29571
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29572
|
-
(json["${
|
|
29603
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List<String> ?
|
|
29604
|
+
(json["${jsonKey}"] as List<String>)
|
|
29573
29605
|
.map((item) => DateTime.parse(item)).toList() : ${fallback}`,
|
|
29574
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29606
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toIso8601String()).toList()`
|
|
29575
29607
|
},
|
|
29576
29608
|
Uint8List: {
|
|
29577
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29578
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29609
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List ? Uint8List.fromList(json["${jsonKey}"]) : ${fallback}`,
|
|
29610
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toList()`
|
|
29579
29611
|
},
|
|
29580
29612
|
"List<Uint8List>": {
|
|
29581
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29582
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29613
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List && (json["${jsonKey}"] as List).isNotEmpty && (json["${jsonKey}"] as List).first is List ? json["${jsonKey}"] : ${fallback}`,
|
|
29614
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toList()).toList()`
|
|
29583
29615
|
}
|
|
29584
29616
|
};
|
|
29585
|
-
function defaultFromJsonBody(key, typename, fallback) {
|
|
29586
|
-
return `${key}: json["${
|
|
29617
|
+
function defaultFromJsonBody(key, jsonKey, typename, fallback) {
|
|
29618
|
+
return `${key}: json["${jsonKey}"] is ${typename} ? json["${jsonKey}"] : ${fallback}`;
|
|
29587
29619
|
}
|
|
29588
|
-
function defaultListFromJsonBody(key, typename, fallback) {
|
|
29589
|
-
return `${key}: json["${
|
|
29620
|
+
function defaultListFromJsonBody(key, jsonKey, typename, fallback) {
|
|
29621
|
+
return `${key}: json["${jsonKey}"] is List<${typename}> ? json["${jsonKey}"] : ${fallback}`;
|
|
29590
29622
|
}
|
|
29591
|
-
function defaultToJsonBody(key) {
|
|
29592
|
-
return `"${
|
|
29623
|
+
function defaultToJsonBody(key, jsonKey) {
|
|
29624
|
+
return `"${jsonKey}": ${key}`;
|
|
29593
29625
|
}
|
|
29594
29626
|
const classTransformer = (typename, nullable) => {
|
|
29595
29627
|
return {
|
|
29596
|
-
fromJsonBody: (key, fallback) => {
|
|
29628
|
+
fromJsonBody: (key, jsonKey, fallback) => {
|
|
29597
29629
|
if (nullable) {
|
|
29598
|
-
return `${key}: json["${
|
|
29599
|
-
${typename}.fromJson(json["${
|
|
29630
|
+
return `${key}: json["${jsonKey}"] is Map<String, dynamic> ?
|
|
29631
|
+
${typename}.fromJson(json["${jsonKey}"]) : null`;
|
|
29600
29632
|
}
|
|
29601
|
-
return `${key}: ${typename}.fromJson(json["${
|
|
29633
|
+
return `${key}: ${typename}.fromJson(json["${jsonKey}"])`;
|
|
29602
29634
|
},
|
|
29603
|
-
toJsonBody: (key, isNullable) =>
|
|
29635
|
+
toJsonBody: (key, jsonKey, isNullable) => {
|
|
29636
|
+
return `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toJson()`;
|
|
29637
|
+
}
|
|
29604
29638
|
};
|
|
29605
29639
|
};
|
|
29606
29640
|
const classListTransformer = (typename) => {
|
|
29607
29641
|
return {
|
|
29608
|
-
fromJsonBody: (key, fallback) => {
|
|
29609
|
-
return `${key}: json["${
|
|
29610
|
-
(json["${
|
|
29642
|
+
fromJsonBody: (key, jsonKey, fallback) => {
|
|
29643
|
+
return `${key}: json["${jsonKey}"] is List<Map<String, dynamic>> ?
|
|
29644
|
+
(json["${jsonKey}"] as List<Map<String, dynamic>>)
|
|
29611
29645
|
.map((val) => ${typename}.fromJson(val)).toList() : ${fallback}`;
|
|
29612
29646
|
},
|
|
29613
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29647
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toJson()).toList()`
|
|
29614
29648
|
};
|
|
29615
29649
|
};
|
|
29616
29650
|
function isDartType(input) {
|
|
@@ -25,8 +25,8 @@ const assert4__default = /*#__PURE__*/_interopDefaultCompat(assert4);
|
|
|
25
25
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
26
26
|
const v8__default = /*#__PURE__*/_interopDefaultCompat(v8);
|
|
27
27
|
|
|
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.
|
|
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.
|
|
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.dd4e8564.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.dd4e8564.cjs', document.baseURI).href)));
|
|
30
30
|
const __dirname$1 = require$$0.dirname(__filename$2);
|
|
31
31
|
|
|
32
32
|
var __create$1 = Object.create;
|
|
@@ -7791,8 +7791,8 @@ const doc = {
|
|
|
7791
7791
|
utils: utils
|
|
7792
7792
|
};
|
|
7793
7793
|
|
|
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.
|
|
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.
|
|
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.dd4e8564.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.dd4e8564.cjs', document.baseURI).href)));
|
|
7796
7796
|
require$$0.dirname(__filename$1);
|
|
7797
7797
|
|
|
7798
7798
|
var __create = Object.create;
|
|
@@ -29060,7 +29060,9 @@ const dartClientGenerator = defineClientGeneratorPlugin(
|
|
|
29060
29060
|
'Missing "outputFile" cannot generate dart client'
|
|
29061
29061
|
);
|
|
29062
29062
|
}
|
|
29063
|
-
const result = createDartClient(def,
|
|
29063
|
+
const result = createDartClient(def, {
|
|
29064
|
+
clientName: options.clientName
|
|
29065
|
+
});
|
|
29064
29066
|
fs$1.writeFileSync(options.outputFile, result);
|
|
29065
29067
|
require$$1.execSync(`dart format ${options.outputFile}`);
|
|
29066
29068
|
},
|
|
@@ -29069,7 +29071,7 @@ const dartClientGenerator = defineClientGeneratorPlugin(
|
|
|
29069
29071
|
}
|
|
29070
29072
|
);
|
|
29071
29073
|
const generatedModels = [];
|
|
29072
|
-
function createDartClient(appDef,
|
|
29074
|
+
function createDartClient(appDef, opts = { clientName: "Client" }) {
|
|
29073
29075
|
const { models, procedures } = appDef;
|
|
29074
29076
|
const serviceParts = [];
|
|
29075
29077
|
const procedureParts = [];
|
|
@@ -29077,22 +29079,18 @@ function createDartClient(appDef, prefix = "Client") {
|
|
|
29077
29079
|
Object.keys(services).forEach((k) => {
|
|
29078
29080
|
const item = services[k];
|
|
29079
29081
|
if (index.isServiceDefinition(item)) {
|
|
29080
|
-
const serviceName = index.pascalCase(`${
|
|
29082
|
+
const serviceName = index.pascalCase(`${opts.clientName}_${k}_service`);
|
|
29081
29083
|
serviceParts.push({
|
|
29082
29084
|
name: serviceName,
|
|
29083
29085
|
key: k,
|
|
29084
29086
|
content: dartServiceFromServiceDefinition(
|
|
29085
29087
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
29086
29088
|
serviceName,
|
|
29087
|
-
item
|
|
29088
|
-
prefix
|
|
29089
|
-
)
|
|
29089
|
+
item)
|
|
29090
29090
|
});
|
|
29091
29091
|
return;
|
|
29092
29092
|
}
|
|
29093
|
-
procedureParts.push(
|
|
29094
|
-
dartProcedureFromServiceDefinition(prefix, k, item)
|
|
29095
|
-
);
|
|
29093
|
+
procedureParts.push(dartProcedureFromServiceDefinition(k, item));
|
|
29096
29094
|
});
|
|
29097
29095
|
const endpoints = {};
|
|
29098
29096
|
Object.keys(procedures).forEach((key) => {
|
|
@@ -29102,14 +29100,11 @@ function createDartClient(appDef, prefix = "Client") {
|
|
|
29102
29100
|
const modelParts = [];
|
|
29103
29101
|
Object.keys(models).forEach((key) => {
|
|
29104
29102
|
const model = models[key];
|
|
29105
|
-
const typeName =
|
|
29103
|
+
const typeName = index.pascalCase(key);
|
|
29106
29104
|
const objModel = model;
|
|
29107
29105
|
if (!generatedModels.includes(typeName)) {
|
|
29108
29106
|
modelParts.push(
|
|
29109
|
-
dartModelFromJsonSchema(
|
|
29110
|
-
`${prefix}${index.pascalCase(key)}`,
|
|
29111
|
-
objModel
|
|
29112
|
-
)
|
|
29107
|
+
dartModelFromJsonSchema(`${index.pascalCase(key)}`, objModel)
|
|
29113
29108
|
);
|
|
29114
29109
|
generatedModels.push(typeName);
|
|
29115
29110
|
}
|
|
@@ -29119,10 +29114,10 @@ import "dart:convert";
|
|
|
29119
29114
|
import "package:http/http.dart" as http;
|
|
29120
29115
|
import "package:arri_client/arri_client.dart";
|
|
29121
29116
|
|
|
29122
|
-
class ${
|
|
29117
|
+
class ${opts.clientName} {
|
|
29123
29118
|
final String _baseUrl;
|
|
29124
29119
|
final Map<String, String> _headers;
|
|
29125
|
-
const ${
|
|
29120
|
+
const ${opts.clientName}({
|
|
29126
29121
|
String baseUrl = "",
|
|
29127
29122
|
Map<String, String> headers = const {},
|
|
29128
29123
|
}): _headers = headers,
|
|
@@ -29136,7 +29131,7 @@ class ${prefix} {
|
|
|
29136
29131
|
}`
|
|
29137
29132
|
).join("\n ")}
|
|
29138
29133
|
Future<http.Response> rawRequest(
|
|
29139
|
-
${
|
|
29134
|
+
${opts.clientName}Endpoints endpoint, {
|
|
29140
29135
|
Map<String, String>? query,
|
|
29141
29136
|
dynamic body,
|
|
29142
29137
|
Map<String, String>? headers,
|
|
@@ -29145,7 +29140,7 @@ class ${prefix} {
|
|
|
29145
29140
|
return arriRequest(
|
|
29146
29141
|
"$_baseUrl\${endpoint.path}",
|
|
29147
29142
|
method: endpoint.method,
|
|
29148
|
-
headers: headers ??
|
|
29143
|
+
headers: headers ?? _headers,
|
|
29149
29144
|
body: body,
|
|
29150
29145
|
query: query,
|
|
29151
29146
|
encoding: encoding,
|
|
@@ -29155,7 +29150,7 @@ class ${prefix} {
|
|
|
29155
29150
|
${serviceParts.map((item) => item.content).join("\n")}
|
|
29156
29151
|
${modelParts.join("\n")}
|
|
29157
29152
|
|
|
29158
|
-
enum ${
|
|
29153
|
+
enum ${opts.clientName}Endpoints implements Comparable<${opts.clientName}Endpoints>, ArriEndpoint {
|
|
29159
29154
|
${Object.keys(endpoints).map(
|
|
29160
29155
|
(key) => `${index.camelCase(key.split("/").join("_"))}(
|
|
29161
29156
|
path: "${key}",
|
|
@@ -29163,7 +29158,7 @@ enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint
|
|
|
29163
29158
|
)`
|
|
29164
29159
|
).join(",\n ")};
|
|
29165
29160
|
|
|
29166
|
-
const ${
|
|
29161
|
+
const ${opts.clientName}Endpoints({
|
|
29167
29162
|
required this.path, required this.method,
|
|
29168
29163
|
});
|
|
29169
29164
|
@override
|
|
@@ -29172,19 +29167,17 @@ enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint
|
|
|
29172
29167
|
final HttpMethod method;
|
|
29173
29168
|
|
|
29174
29169
|
@override
|
|
29175
|
-
compareTo(${
|
|
29170
|
+
compareTo(${opts.clientName}Endpoints other) => name.compareTo(other.name);
|
|
29176
29171
|
}`;
|
|
29177
29172
|
}
|
|
29178
|
-
function dartServiceFromServiceDefinition(name, def,
|
|
29173
|
+
function dartServiceFromServiceDefinition(name, def, opts) {
|
|
29179
29174
|
const rpcParts = [];
|
|
29180
29175
|
const subServiceParts = [];
|
|
29181
29176
|
const serviceName = `${name}`;
|
|
29182
29177
|
Object.keys(def).forEach((key) => {
|
|
29183
29178
|
const item = def[key];
|
|
29184
29179
|
if (index.isProcedureDefinition(item)) {
|
|
29185
|
-
rpcParts.push(
|
|
29186
|
-
dartProcedureFromServiceDefinition(prefix, key, item)
|
|
29187
|
-
);
|
|
29180
|
+
rpcParts.push(dartProcedureFromServiceDefinition(key, item));
|
|
29188
29181
|
return;
|
|
29189
29182
|
}
|
|
29190
29183
|
const nameParts = name.split("Service");
|
|
@@ -29194,9 +29187,7 @@ function dartServiceFromServiceDefinition(name, def, prefix = "") {
|
|
|
29194
29187
|
);
|
|
29195
29188
|
const subService = dartServiceFromServiceDefinition(
|
|
29196
29189
|
subServiceName,
|
|
29197
|
-
item
|
|
29198
|
-
prefix
|
|
29199
|
-
);
|
|
29190
|
+
item);
|
|
29200
29191
|
subServiceParts.push({
|
|
29201
29192
|
name: subServiceName,
|
|
29202
29193
|
key,
|
|
@@ -29224,18 +29215,18 @@ function dartServiceFromServiceDefinition(name, def, prefix = "") {
|
|
|
29224
29215
|
${subServiceParts.map((sub) => sub.content).join("\n")}
|
|
29225
29216
|
`;
|
|
29226
29217
|
}
|
|
29227
|
-
function dartProcedureFromServiceDefinition(
|
|
29218
|
+
function dartProcedureFromServiceDefinition(key, def, opts) {
|
|
29228
29219
|
let returnType = `Future<String>`;
|
|
29229
29220
|
let returnTypeName = "String";
|
|
29230
29221
|
if (def.response) {
|
|
29231
|
-
returnType = `Future<${
|
|
29232
|
-
returnTypeName = `${
|
|
29222
|
+
returnType = `Future<${def.response}>`;
|
|
29223
|
+
returnTypeName = `${def.response}`;
|
|
29233
29224
|
} else {
|
|
29234
29225
|
returnType = "Future<void>";
|
|
29235
29226
|
}
|
|
29236
29227
|
let paramsInput = "";
|
|
29237
29228
|
if (def.params) {
|
|
29238
|
-
paramsInput = `${
|
|
29229
|
+
paramsInput = `${def.params} params`;
|
|
29239
29230
|
}
|
|
29240
29231
|
let responseParser = "(body) => body;";
|
|
29241
29232
|
switch (returnType) {
|
|
@@ -29277,7 +29268,8 @@ function dartProcedureFromServiceDefinition(clientName, key, def) {
|
|
|
29277
29268
|
);
|
|
29278
29269
|
}`;
|
|
29279
29270
|
}
|
|
29280
|
-
function dartModelFromJsonSchema(
|
|
29271
|
+
function dartModelFromJsonSchema(modelName, schema, opts) {
|
|
29272
|
+
const modelDisplayName = index.pascalCase(`${modelName}`);
|
|
29281
29273
|
const fields = [];
|
|
29282
29274
|
const subModelParts = [];
|
|
29283
29275
|
Object.entries(schema.properties ?? {}).forEach(([key, val]) => {
|
|
@@ -29285,32 +29277,42 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29285
29277
|
return;
|
|
29286
29278
|
}
|
|
29287
29279
|
const [dartType, subTypes] = dartPropertyTypeFromSchema(
|
|
29288
|
-
|
|
29280
|
+
modelName,
|
|
29289
29281
|
key,
|
|
29290
|
-
schema
|
|
29291
|
-
);
|
|
29282
|
+
schema);
|
|
29292
29283
|
if (subTypes?.length) {
|
|
29293
29284
|
for (const sub of subTypes) {
|
|
29294
29285
|
subModelParts.push(sub);
|
|
29295
29286
|
}
|
|
29296
29287
|
}
|
|
29297
|
-
fields.push({ type: dartType, name: key });
|
|
29298
|
-
if (!isDartType(dartType) &&
|
|
29288
|
+
fields.push({ type: dartType, name: index.camelCase(key), jsonKey: key });
|
|
29289
|
+
if (!isDartType(dartType) && index.isJsonSchemaObject(val)) {
|
|
29290
|
+
if (val.$id && generatedModels.includes(val.$id)) {
|
|
29291
|
+
return;
|
|
29292
|
+
}
|
|
29293
|
+
const subModelName = val.$id ? index.pascalCase(val.$id) : index.pascalCase(dartType.replace("?", ""));
|
|
29299
29294
|
subModelParts.push(
|
|
29300
|
-
dartModelFromJsonSchema(
|
|
29295
|
+
dartModelFromJsonSchema(subModelName, val)
|
|
29301
29296
|
);
|
|
29297
|
+
generatedModels.push(subModelName);
|
|
29302
29298
|
}
|
|
29303
29299
|
});
|
|
29304
|
-
return `class ${
|
|
29300
|
+
return `class ${modelDisplayName} {
|
|
29305
29301
|
${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
|
|
29306
|
-
const ${
|
|
29302
|
+
const ${modelDisplayName}({
|
|
29307
29303
|
${fields.map(
|
|
29308
29304
|
(field) => field.type.includes("?") ? `this.${field.name},` : `required this.${field.name},`
|
|
29309
29305
|
).join("\n ")}
|
|
29310
29306
|
});
|
|
29311
|
-
factory ${
|
|
29312
|
-
return ${
|
|
29313
|
-
${fields.map(
|
|
29307
|
+
factory ${modelDisplayName}.fromJson(Map<String, dynamic> json) {
|
|
29308
|
+
return ${modelDisplayName}(
|
|
29309
|
+
${fields.map(
|
|
29310
|
+
(field) => `${dartParsedJsonField(
|
|
29311
|
+
field.name,
|
|
29312
|
+
field.jsonKey,
|
|
29313
|
+
field.type
|
|
29314
|
+
)},`
|
|
29315
|
+
).join("\n ")}
|
|
29314
29316
|
);
|
|
29315
29317
|
}
|
|
29316
29318
|
Map<String, dynamic> toJson() {
|
|
@@ -29320,25 +29322,31 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29320
29322
|
const typeName = field.type.replace("?", "");
|
|
29321
29323
|
if (isDartTypeWithNullables(field.type)) {
|
|
29322
29324
|
const transformer = transformers[typeName];
|
|
29323
|
-
return transformer.toJsonBody(
|
|
29325
|
+
return transformer.toJsonBody(
|
|
29326
|
+
field.name,
|
|
29327
|
+
field.jsonKey,
|
|
29328
|
+
isNullable
|
|
29329
|
+
);
|
|
29324
29330
|
}
|
|
29325
29331
|
if (field.type.includes("List<")) {
|
|
29326
29332
|
return classListTransformer(typeName).toJsonBody(
|
|
29327
29333
|
field.name,
|
|
29334
|
+
field.jsonKey,
|
|
29328
29335
|
isNullable
|
|
29329
29336
|
);
|
|
29330
29337
|
}
|
|
29331
29338
|
return classTransformer(typeName, isNullable).toJsonBody(
|
|
29332
29339
|
field.name,
|
|
29340
|
+
field.jsonKey,
|
|
29333
29341
|
isNullable
|
|
29334
29342
|
);
|
|
29335
29343
|
}).join(",\n ")},
|
|
29336
29344
|
};
|
|
29337
29345
|
}
|
|
29338
|
-
${
|
|
29346
|
+
${modelDisplayName} copyWith({
|
|
29339
29347
|
${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
|
|
29340
29348
|
}) {
|
|
29341
|
-
return ${
|
|
29349
|
+
return ${modelDisplayName}(
|
|
29342
29350
|
${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
|
|
29343
29351
|
);
|
|
29344
29352
|
}
|
|
@@ -29346,7 +29354,7 @@ function dartModelFromJsonSchema(name, schema) {
|
|
|
29346
29354
|
|
|
29347
29355
|
${subModelParts.join("\n")}`;
|
|
29348
29356
|
}
|
|
29349
|
-
function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
29357
|
+
function dartPropertyTypeFromSchema(objectName, propertyName, schema, opts) {
|
|
29350
29358
|
const prop = schema.properties?.[propertyName];
|
|
29351
29359
|
const isOptional = !schema.required?.includes(propertyName);
|
|
29352
29360
|
let finalType = "";
|
|
@@ -29422,9 +29430,7 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29422
29430
|
}
|
|
29423
29431
|
}
|
|
29424
29432
|
if (index.isJsonSchemaObject(prop)) {
|
|
29425
|
-
const joinedPropName = index.pascalCase(
|
|
29426
|
-
`${objectName}_${propertyName}`
|
|
29427
|
-
);
|
|
29433
|
+
const joinedPropName = prop.$id ? index.pascalCase(prop.$id) : index.pascalCase(`${objectName}_${propertyName}`);
|
|
29428
29434
|
finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
|
|
29429
29435
|
}
|
|
29430
29436
|
if (index.isJsonSchemaArray(prop)) {
|
|
@@ -29456,8 +29462,10 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29456
29462
|
break;
|
|
29457
29463
|
case "object": {
|
|
29458
29464
|
const subTypeName = item.$id ?? index.pascalCase(`${objectName}_${propertyName}_item`);
|
|
29459
|
-
const model = dartModelFromJsonSchema(subTypeName, item);
|
|
29460
29465
|
if (!generatedModels.includes(subTypeName)) {
|
|
29466
|
+
const model = dartModelFromJsonSchema(
|
|
29467
|
+
subTypeName,
|
|
29468
|
+
item);
|
|
29461
29469
|
subTypes.push(model);
|
|
29462
29470
|
generatedModels.push(subTypeName);
|
|
29463
29471
|
}
|
|
@@ -29468,28 +29476,49 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
|
|
|
29468
29476
|
}
|
|
29469
29477
|
return [finalType, subTypes.length ? subTypes : void 0];
|
|
29470
29478
|
}
|
|
29471
|
-
function dartParsedJsonField(fieldName, dartType) {
|
|
29479
|
+
function dartParsedJsonField(fieldName, jsonKey, dartType) {
|
|
29472
29480
|
if (isDartTypeWithNullables(dartType)) {
|
|
29473
29481
|
switch (dartType) {
|
|
29474
29482
|
case "String":
|
|
29475
|
-
return transformers.String.fromJsonBody(
|
|
29483
|
+
return transformers.String.fromJsonBody(
|
|
29484
|
+
fieldName,
|
|
29485
|
+
jsonKey,
|
|
29486
|
+
'""'
|
|
29487
|
+
);
|
|
29476
29488
|
case "String?":
|
|
29477
|
-
return transformers.String.fromJsonBody(
|
|
29489
|
+
return transformers.String.fromJsonBody(
|
|
29490
|
+
fieldName,
|
|
29491
|
+
jsonKey,
|
|
29492
|
+
"null"
|
|
29493
|
+
);
|
|
29478
29494
|
case "bool":
|
|
29479
|
-
return transformers.bool.fromJsonBody(
|
|
29495
|
+
return transformers.bool.fromJsonBody(
|
|
29496
|
+
fieldName,
|
|
29497
|
+
jsonKey,
|
|
29498
|
+
"false"
|
|
29499
|
+
);
|
|
29480
29500
|
case "double":
|
|
29481
|
-
return transformers.double.fromJsonBody(
|
|
29501
|
+
return transformers.double.fromJsonBody(
|
|
29502
|
+
fieldName,
|
|
29503
|
+
jsonKey,
|
|
29504
|
+
"0.0"
|
|
29505
|
+
);
|
|
29482
29506
|
case "int":
|
|
29483
|
-
return transformers.int.fromJsonBody(fieldName, "0");
|
|
29507
|
+
return transformers.int.fromJsonBody(fieldName, jsonKey, "0");
|
|
29484
29508
|
case "null":
|
|
29485
|
-
return transformers.null.fromJsonBody(fieldName, "");
|
|
29509
|
+
return transformers.null.fromJsonBody(fieldName, jsonKey, "");
|
|
29486
29510
|
case "DateTime":
|
|
29487
29511
|
return transformers.DateTime.fromJsonBody(
|
|
29488
29512
|
fieldName,
|
|
29513
|
+
jsonKey,
|
|
29489
29514
|
"DateTime(0)"
|
|
29490
29515
|
);
|
|
29491
29516
|
case "DateTime?":
|
|
29492
|
-
return transformers.DateTime.fromJsonBody(
|
|
29517
|
+
return transformers.DateTime.fromJsonBody(
|
|
29518
|
+
fieldName,
|
|
29519
|
+
jsonKey,
|
|
29520
|
+
"null"
|
|
29521
|
+
);
|
|
29493
29522
|
case "List<String>":
|
|
29494
29523
|
case "List<bool>":
|
|
29495
29524
|
case "List<double>":
|
|
@@ -29497,26 +29526,29 @@ function dartParsedJsonField(fieldName, dartType) {
|
|
|
29497
29526
|
case "List<null>":
|
|
29498
29527
|
return defaultListFromJsonBody(
|
|
29499
29528
|
fieldName,
|
|
29529
|
+
jsonKey,
|
|
29500
29530
|
dartType.replace("List<", "").replace(">", ""),
|
|
29501
29531
|
"[]"
|
|
29502
29532
|
);
|
|
29503
29533
|
default:
|
|
29504
|
-
return `${fieldName}: json["${
|
|
29534
|
+
return `${fieldName}: json["${jsonKey}"] is ${dartType.replace(
|
|
29505
29535
|
"?",
|
|
29506
29536
|
""
|
|
29507
|
-
)} ? json["${
|
|
29537
|
+
)} ? json["${jsonKey}"] : null`;
|
|
29508
29538
|
}
|
|
29509
29539
|
}
|
|
29510
29540
|
if (dartType.includes("List<")) {
|
|
29511
29541
|
const innerType = dartType.replace("List<", "").replace(">", "").replace("?", "");
|
|
29512
29542
|
return classListTransformer(innerType).fromJsonBody(
|
|
29513
29543
|
fieldName,
|
|
29544
|
+
jsonKey,
|
|
29514
29545
|
dartType.endsWith("?") ? "null" : "[]"
|
|
29515
29546
|
);
|
|
29516
29547
|
}
|
|
29517
29548
|
const classType = dartType.split("?").join("").trim();
|
|
29518
29549
|
return classTransformer(classType, dartType.endsWith("?")).fromJsonBody(
|
|
29519
29550
|
fieldName,
|
|
29551
|
+
jsonKey,
|
|
29520
29552
|
classType
|
|
29521
29553
|
);
|
|
29522
29554
|
}
|
|
@@ -29541,89 +29573,91 @@ const transformers = {
|
|
|
29541
29573
|
toJsonBody: defaultToJsonBody
|
|
29542
29574
|
},
|
|
29543
29575
|
int: {
|
|
29544
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "int", fallback),
|
|
29576
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "int", fallback),
|
|
29545
29577
|
toJsonBody: defaultToJsonBody
|
|
29546
29578
|
},
|
|
29547
29579
|
double: {
|
|
29548
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "double", fallback),
|
|
29580
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "double", fallback),
|
|
29549
29581
|
toJsonBody: defaultToJsonBody
|
|
29550
29582
|
},
|
|
29551
29583
|
String: {
|
|
29552
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "String", fallback),
|
|
29584
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "String", fallback),
|
|
29553
29585
|
toJsonBody: defaultToJsonBody
|
|
29554
29586
|
},
|
|
29555
29587
|
bool: {
|
|
29556
|
-
fromJsonBody: (key, fallback) => defaultFromJsonBody(key, "bool", fallback),
|
|
29588
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultFromJsonBody(key, jsonKey, "bool", fallback),
|
|
29557
29589
|
toJsonBody: defaultToJsonBody
|
|
29558
29590
|
},
|
|
29559
29591
|
DateTime: {
|
|
29560
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29561
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29592
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is String ? DateTime.parse(json["${jsonKey}"]) : ${fallback}`,
|
|
29593
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toIso8601String()`
|
|
29562
29594
|
},
|
|
29563
29595
|
"List<null>": {
|
|
29564
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "null", fallback),
|
|
29596
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "null", fallback),
|
|
29565
29597
|
toJsonBody: defaultToJsonBody
|
|
29566
29598
|
},
|
|
29567
29599
|
"List<int>": {
|
|
29568
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "int", fallback),
|
|
29600
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "int", fallback),
|
|
29569
29601
|
toJsonBody: defaultToJsonBody
|
|
29570
29602
|
},
|
|
29571
29603
|
"List<double>": {
|
|
29572
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "double", fallback),
|
|
29604
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "double", fallback),
|
|
29573
29605
|
toJsonBody: defaultToJsonBody
|
|
29574
29606
|
},
|
|
29575
29607
|
"List<String>": {
|
|
29576
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "String", fallback),
|
|
29608
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "String", fallback),
|
|
29577
29609
|
toJsonBody: defaultToJsonBody
|
|
29578
29610
|
},
|
|
29579
29611
|
"List<bool>": {
|
|
29580
|
-
fromJsonBody: (key, fallback) => defaultListFromJsonBody(key, "bool", fallback),
|
|
29612
|
+
fromJsonBody: (key, jsonKey, fallback) => defaultListFromJsonBody(key, jsonKey, "bool", fallback),
|
|
29581
29613
|
toJsonBody: defaultToJsonBody
|
|
29582
29614
|
},
|
|
29583
29615
|
"List<DateTime>": {
|
|
29584
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29585
|
-
(json["${
|
|
29616
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List<String> ?
|
|
29617
|
+
(json["${jsonKey}"] as List<String>)
|
|
29586
29618
|
.map((item) => DateTime.parse(item)).toList() : ${fallback}`,
|
|
29587
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29619
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toIso8601String()).toList()`
|
|
29588
29620
|
},
|
|
29589
29621
|
Uint8List: {
|
|
29590
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29591
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29622
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List ? Uint8List.fromList(json["${jsonKey}"]) : ${fallback}`,
|
|
29623
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toList()`
|
|
29592
29624
|
},
|
|
29593
29625
|
"List<Uint8List>": {
|
|
29594
|
-
fromJsonBody: (key, fallback) => `${key}: json["${
|
|
29595
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29626
|
+
fromJsonBody: (key, jsonKey, fallback) => `${key}: json["${jsonKey}"] is List && (json["${jsonKey}"] as List).isNotEmpty && (json["${jsonKey}"] as List).first is List ? json["${jsonKey}"] : ${fallback}`,
|
|
29627
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toList()).toList()`
|
|
29596
29628
|
}
|
|
29597
29629
|
};
|
|
29598
|
-
function defaultFromJsonBody(key, typename, fallback) {
|
|
29599
|
-
return `${key}: json["${
|
|
29630
|
+
function defaultFromJsonBody(key, jsonKey, typename, fallback) {
|
|
29631
|
+
return `${key}: json["${jsonKey}"] is ${typename} ? json["${jsonKey}"] : ${fallback}`;
|
|
29600
29632
|
}
|
|
29601
|
-
function defaultListFromJsonBody(key, typename, fallback) {
|
|
29602
|
-
return `${key}: json["${
|
|
29633
|
+
function defaultListFromJsonBody(key, jsonKey, typename, fallback) {
|
|
29634
|
+
return `${key}: json["${jsonKey}"] is List<${typename}> ? json["${jsonKey}"] : ${fallback}`;
|
|
29603
29635
|
}
|
|
29604
|
-
function defaultToJsonBody(key) {
|
|
29605
|
-
return `"${
|
|
29636
|
+
function defaultToJsonBody(key, jsonKey) {
|
|
29637
|
+
return `"${jsonKey}": ${key}`;
|
|
29606
29638
|
}
|
|
29607
29639
|
const classTransformer = (typename, nullable) => {
|
|
29608
29640
|
return {
|
|
29609
|
-
fromJsonBody: (key, fallback) => {
|
|
29641
|
+
fromJsonBody: (key, jsonKey, fallback) => {
|
|
29610
29642
|
if (nullable) {
|
|
29611
|
-
return `${key}: json["${
|
|
29612
|
-
${typename}.fromJson(json["${
|
|
29643
|
+
return `${key}: json["${jsonKey}"] is Map<String, dynamic> ?
|
|
29644
|
+
${typename}.fromJson(json["${jsonKey}"]) : null`;
|
|
29613
29645
|
}
|
|
29614
|
-
return `${key}: ${typename}.fromJson(json["${
|
|
29646
|
+
return `${key}: ${typename}.fromJson(json["${jsonKey}"])`;
|
|
29615
29647
|
},
|
|
29616
|
-
toJsonBody: (key, isNullable) =>
|
|
29648
|
+
toJsonBody: (key, jsonKey, isNullable) => {
|
|
29649
|
+
return `"${jsonKey}": ${key}${isNullable ? "?" : ""}.toJson()`;
|
|
29650
|
+
}
|
|
29617
29651
|
};
|
|
29618
29652
|
};
|
|
29619
29653
|
const classListTransformer = (typename) => {
|
|
29620
29654
|
return {
|
|
29621
|
-
fromJsonBody: (key, fallback) => {
|
|
29622
|
-
return `${key}: json["${
|
|
29623
|
-
(json["${
|
|
29655
|
+
fromJsonBody: (key, jsonKey, fallback) => {
|
|
29656
|
+
return `${key}: json["${jsonKey}"] is List<Map<String, dynamic>> ?
|
|
29657
|
+
(json["${jsonKey}"] as List<Map<String, dynamic>>)
|
|
29624
29658
|
.map((val) => ${typename}.fromJson(val)).toList() : ${fallback}`;
|
|
29625
29659
|
},
|
|
29626
|
-
toJsonBody: (key, isNullable) => `"${
|
|
29660
|
+
toJsonBody: (key, jsonKey, isNullable) => `"${jsonKey}": ${key}${isNullable ? "?" : ""}.map((val) => val.toJson()).toList()`
|
|
29627
29661
|
};
|
|
29628
29662
|
};
|
|
29629
29663
|
function isDartType(input) {
|