arri 0.0.10 → 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.
@@ -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.24f662c0.cjs');
32
+ require('../shared/arri.dd4e8564.cjs');
33
33
  require('fs/promises');
34
34
  require('child_process');
35
35
  require('node:http');
@@ -27,7 +27,7 @@ import 'node:module';
27
27
  import 'node:assert';
28
28
  import 'node:v8';
29
29
  import 'node:util';
30
- import '../shared/arri.5b1d01a1.mjs';
30
+ import '../shared/arri.d491643b.mjs';
31
31
  import 'fs/promises';
32
32
  import 'child_process';
33
33
  import 'node:http';
@@ -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.24f662c0.cjs');
34
+ require('../shared/arri.dd4e8564.cjs');
35
35
  require('fs/promises');
36
36
  require('child_process');
37
37
  require('node:http');
@@ -29,7 +29,7 @@ import 'node:module';
29
29
  import 'node:assert';
30
30
  import 'node:v8';
31
31
  import 'node:util';
32
- import '../shared/arri.5b1d01a1.mjs';
32
+ import '../shared/arri.d491643b.mjs';
33
33
  import 'fs/promises';
34
34
  import 'child_process';
35
35
  import 'node:http';
@@ -35,7 +35,7 @@ require('v8');
35
35
  require('node:module');
36
36
  require('node:assert');
37
37
  require('node:v8');
38
- require('../shared/arri.24f662c0.cjs');
38
+ require('../shared/arri.dd4e8564.cjs');
39
39
  require('fs/promises');
40
40
  require('child_process');
41
41
  require('node:http');
@@ -33,7 +33,7 @@ import 'v8';
33
33
  import 'node:module';
34
34
  import 'node:assert';
35
35
  import 'node:v8';
36
- import '../shared/arri.5b1d01a1.mjs';
36
+ import '../shared/arri.d491643b.mjs';
37
37
  import 'fs/promises';
38
38
  import 'child_process';
39
39
  import 'node:http';
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.24f662c0.cjs');
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.5b1d01a1.mjs';
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
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const index = require('./shared/arri.8e602d87.cjs');
4
- const dart = require('./shared/arri.24f662c0.cjs');
4
+ const dart = require('./shared/arri.dd4e8564.cjs');
5
5
  const fs = require('fs');
6
6
  require('module');
7
7
  require('url');
@@ -24,11 +24,14 @@ interface DartClientGeneratorOptions {
24
24
  outputFile: string;
25
25
  }
26
26
  declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
27
- declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
28
- declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
29
- declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
30
- declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
31
- declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
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];
32
35
  declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
33
36
  declare const dartTypeMap: {
34
37
  readonly integer: "int";
@@ -24,11 +24,14 @@ interface DartClientGeneratorOptions {
24
24
  outputFile: string;
25
25
  }
26
26
  declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
27
- declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
28
- declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
29
- declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
30
- declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
31
- declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
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];
32
35
  declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
33
36
  declare const dartTypeMap: {
34
37
  readonly integer: "int";
package/dist/codegen.d.ts CHANGED
@@ -24,11 +24,14 @@ interface DartClientGeneratorOptions {
24
24
  outputFile: string;
25
25
  }
26
26
  declare const dartClientGenerator: ClientGeneratorPlugin<DartClientGeneratorOptions>;
27
- declare function createDartClient(appDef: ApplicationDefinition, prefix?: string): string;
28
- declare function dartServiceFromServiceDefinition(name: string, def: ServiceDefinition, prefix?: string): string;
29
- declare function dartProcedureFromServiceDefinition(clientName: string, key: string, def: ProcedureDefinition): string;
30
- declare function dartModelFromJsonSchema(name: string, schema: JsonSchemaObject): string;
31
- declare function dartPropertyTypeFromSchema(objectName: string, propertyName: string, schema: JsonSchemaObject): [DartType | string, string[] | undefined];
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];
32
35
  declare function dartParsedJsonField(fieldName: string, jsonKey: string, dartType: string): string;
33
36
  declare const dartTypeMap: {
34
37
  readonly integer: "int";
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.5b1d01a1.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.5b1d01a1.mjs';
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, d as isJsonSchemaObject, f as isJsonSchemaArray } from './arri.1f1b9dfc.mjs';
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, options.clientName);
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, prefix = "Client") {
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(`${prefix}_${k}_service`);
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 = `${prefix}${pascalCase(key)}`;
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 ${prefix} {
29104
+ class ${opts.clientName} {
29110
29105
  final String _baseUrl;
29111
29106
  final Map<String, String> _headers;
29112
- const ${prefix}({
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
- ${prefix}Endpoints endpoint, {
29121
+ ${opts.clientName}Endpoints endpoint, {
29127
29122
  Map<String, String>? query,
29128
29123
  dynamic body,
29129
29124
  Map<String, String>? headers,
@@ -29142,7 +29137,7 @@ class ${prefix} {
29142
29137
  ${serviceParts.map((item) => item.content).join("\n")}
29143
29138
  ${modelParts.join("\n")}
29144
29139
 
29145
- enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint {
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 ${prefix}Endpoints({
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(${prefix}Endpoints other) => name.compareTo(other.name);
29157
+ compareTo(${opts.clientName}Endpoints other) => name.compareTo(other.name);
29163
29158
  }`;
29164
29159
  }
29165
- function dartServiceFromServiceDefinition(name, def, prefix = "") {
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(clientName, key, def) {
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<${clientName}${def.response}>`;
29219
- returnTypeName = `${clientName}${def.response}`;
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 = `${clientName}${def.params} params`;
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(name, schema) {
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,31 +29264,35 @@ function dartModelFromJsonSchema(name, schema) {
29272
29264
  return;
29273
29265
  }
29274
29266
  const [dartType, subTypes] = dartPropertyTypeFromSchema(
29275
- name,
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
29275
  fields.push({ type: dartType, name: camelCase(key), jsonKey: key });
29285
- if (!isDartType(dartType) && "type" in val && val.type === "object") {
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(dartType.replace("?", ""), val)
29282
+ dartModelFromJsonSchema(subModelName, val)
29288
29283
  );
29284
+ generatedModels.push(subModelName);
29289
29285
  }
29290
29286
  });
29291
- return `class ${name} {
29287
+ return `class ${modelDisplayName} {
29292
29288
  ${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
29293
- const ${name}({
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 ${name}.fromJson(Map<String, dynamic> json) {
29299
- return ${name}(
29294
+ factory ${modelDisplayName}.fromJson(Map<String, dynamic> json) {
29295
+ return ${modelDisplayName}(
29300
29296
  ${fields.map(
29301
29297
  (field) => `${dartParsedJsonField(
29302
29298
  field.name,
@@ -29334,10 +29330,10 @@ function dartModelFromJsonSchema(name, schema) {
29334
29330
  }).join(",\n ")},
29335
29331
  };
29336
29332
  }
29337
- ${name} copyWith({
29333
+ ${modelDisplayName} copyWith({
29338
29334
  ${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
29339
29335
  }) {
29340
- return ${name}(
29336
+ return ${modelDisplayName}(
29341
29337
  ${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
29342
29338
  );
29343
29339
  }
@@ -29345,7 +29341,7 @@ function dartModelFromJsonSchema(name, schema) {
29345
29341
 
29346
29342
  ${subModelParts.join("\n")}`;
29347
29343
  }
29348
- function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29344
+ function dartPropertyTypeFromSchema(objectName, propertyName, schema, opts) {
29349
29345
  const prop = schema.properties?.[propertyName];
29350
29346
  const isOptional = !schema.required?.includes(propertyName);
29351
29347
  let finalType = "";
@@ -29421,9 +29417,7 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29421
29417
  }
29422
29418
  }
29423
29419
  if (isJsonSchemaObject(prop)) {
29424
- const joinedPropName = pascalCase(
29425
- `${objectName}_${propertyName}`
29426
- );
29420
+ const joinedPropName = prop.$id ? pascalCase(prop.$id) : pascalCase(`${objectName}_${propertyName}`);
29427
29421
  finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
29428
29422
  }
29429
29423
  if (isJsonSchemaArray(prop)) {
@@ -29455,8 +29449,10 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29455
29449
  break;
29456
29450
  case "object": {
29457
29451
  const subTypeName = item.$id ?? pascalCase(`${objectName}_${propertyName}_item`);
29458
- const model = dartModelFromJsonSchema(subTypeName, item);
29459
29452
  if (!generatedModels.includes(subTypeName)) {
29453
+ const model = dartModelFromJsonSchema(
29454
+ subTypeName,
29455
+ item);
29460
29456
  subTypes.push(model);
29461
29457
  generatedModels.push(subTypeName);
29462
29458
  }
@@ -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.24f662c0.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.24f662c0.cjs', document.baseURI).href)));
28
+ const require$2 = require$$2.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/arri.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.24f662c0.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.24f662c0.cjs', document.baseURI).href)));
7794
+ const require$1 = require$$2.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared/arri.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, options.clientName);
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, prefix = "Client") {
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(`${prefix}_${k}_service`);
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 = `${prefix}${index.pascalCase(key)}`;
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 ${prefix} {
29117
+ class ${opts.clientName} {
29123
29118
  final String _baseUrl;
29124
29119
  final Map<String, String> _headers;
29125
- const ${prefix}({
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
- ${prefix}Endpoints endpoint, {
29134
+ ${opts.clientName}Endpoints endpoint, {
29140
29135
  Map<String, String>? query,
29141
29136
  dynamic body,
29142
29137
  Map<String, String>? headers,
@@ -29155,7 +29150,7 @@ class ${prefix} {
29155
29150
  ${serviceParts.map((item) => item.content).join("\n")}
29156
29151
  ${modelParts.join("\n")}
29157
29152
 
29158
- enum ${prefix}Endpoints implements Comparable<${prefix}Endpoints>, ArriEndpoint {
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 ${prefix}Endpoints({
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(${prefix}Endpoints other) => name.compareTo(other.name);
29170
+ compareTo(${opts.clientName}Endpoints other) => name.compareTo(other.name);
29176
29171
  }`;
29177
29172
  }
29178
- function dartServiceFromServiceDefinition(name, def, prefix = "") {
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(clientName, key, def) {
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<${clientName}${def.response}>`;
29232
- returnTypeName = `${clientName}${def.response}`;
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 = `${clientName}${def.params} params`;
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(name, schema) {
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,31 +29277,35 @@ function dartModelFromJsonSchema(name, schema) {
29285
29277
  return;
29286
29278
  }
29287
29279
  const [dartType, subTypes] = dartPropertyTypeFromSchema(
29288
- name,
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
29288
  fields.push({ type: dartType, name: index.camelCase(key), jsonKey: key });
29298
- if (!isDartType(dartType) && "type" in val && val.type === "object") {
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(dartType.replace("?", ""), val)
29295
+ dartModelFromJsonSchema(subModelName, val)
29301
29296
  );
29297
+ generatedModels.push(subModelName);
29302
29298
  }
29303
29299
  });
29304
- return `class ${name} {
29300
+ return `class ${modelDisplayName} {
29305
29301
  ${fields.map((field) => `final ${field.type} ${field.name};`).join("\n ")}
29306
- const ${name}({
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 ${name}.fromJson(Map<String, dynamic> json) {
29312
- return ${name}(
29307
+ factory ${modelDisplayName}.fromJson(Map<String, dynamic> json) {
29308
+ return ${modelDisplayName}(
29313
29309
  ${fields.map(
29314
29310
  (field) => `${dartParsedJsonField(
29315
29311
  field.name,
@@ -29347,10 +29343,10 @@ function dartModelFromJsonSchema(name, schema) {
29347
29343
  }).join(",\n ")},
29348
29344
  };
29349
29345
  }
29350
- ${name} copyWith({
29346
+ ${modelDisplayName} copyWith({
29351
29347
  ${fields.map((field) => `${field.type.replace("?", "")}? ${field.name},`).join("\n ")}
29352
29348
  }) {
29353
- return ${name}(
29349
+ return ${modelDisplayName}(
29354
29350
  ${fields.map((field) => `${field.name}: ${field.name} ?? this.${field.name},`).join("\n ")}
29355
29351
  );
29356
29352
  }
@@ -29358,7 +29354,7 @@ function dartModelFromJsonSchema(name, schema) {
29358
29354
 
29359
29355
  ${subModelParts.join("\n")}`;
29360
29356
  }
29361
- function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29357
+ function dartPropertyTypeFromSchema(objectName, propertyName, schema, opts) {
29362
29358
  const prop = schema.properties?.[propertyName];
29363
29359
  const isOptional = !schema.required?.includes(propertyName);
29364
29360
  let finalType = "";
@@ -29434,9 +29430,7 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29434
29430
  }
29435
29431
  }
29436
29432
  if (index.isJsonSchemaObject(prop)) {
29437
- const joinedPropName = index.pascalCase(
29438
- `${objectName}_${propertyName}`
29439
- );
29433
+ const joinedPropName = prop.$id ? index.pascalCase(prop.$id) : index.pascalCase(`${objectName}_${propertyName}`);
29440
29434
  finalType = isOptional ? `${joinedPropName}?` : joinedPropName;
29441
29435
  }
29442
29436
  if (index.isJsonSchemaArray(prop)) {
@@ -29468,8 +29462,10 @@ function dartPropertyTypeFromSchema(objectName, propertyName, schema) {
29468
29462
  break;
29469
29463
  case "object": {
29470
29464
  const subTypeName = item.$id ?? index.pascalCase(`${objectName}_${propertyName}_item`);
29471
- const model = dartModelFromJsonSchema(subTypeName, item);
29472
29465
  if (!generatedModels.includes(subTypeName)) {
29466
+ const model = dartModelFromJsonSchema(
29467
+ subTypeName,
29468
+ item);
29473
29469
  subTypes.push(model);
29474
29470
  generatedModels.push(subTypeName);
29475
29471
  }
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "chokidar": "^3.5.3",
23
23
  "listhen": "^1.4.3"
24
24
  },
25
- "version": "0.0.10",
25
+ "version": "0.0.11",
26
26
  "repository": {
27
27
  "url": "https://github.com/modiimedia/arri"
28
28
  }