Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomvh committed Sep 25, 2024
1 parent 0103ebb commit 9a5f506
Show file tree
Hide file tree
Showing 52 changed files with 629 additions and 433 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@angular/platform-browser-dynamic": "^18.1.0",
"@angular/router": "^18.1.0",
"jsdom": "^24.1.0",
"prettier": "^3.3.3",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class ApiConfig extends Base {
return url('./files/api-config');
}
public override variables(): { [name: string]: any } {
return {
return {
serviceRootUrl: this.options.serviceRootUrl,
metadataUrl: this.options.metadata,
apiConfigName: this.options.name,
version: this.options.version,
creation: this.options.creation,
};
};
}
public override name() {
return strings.classify(this.options.name) + 'Config';
Expand Down
82 changes: 41 additions & 41 deletions projects/angular-odata/schematics/apigen/angular/base.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { strings } from "@angular-devkit/core";
import { getRandomName } from "../../random";
import { Import } from "./import";
import { url, Source } from "@angular-devkit/schematics";
import { Schema as ApiGenSchema } from "../schema";
import { strings } from '@angular-devkit/core';
import { getRandomName } from '../../random';
import { Import } from './import';
import { url, Source } from '@angular-devkit/schematics';
import { Schema as ApiGenSchema } from '../schema';
import {
BINDING_PARAMETER_NAME,
CsdlCallable,
CsdlFunction,
CsdlParameter,
} from "../metadata/csdl/csdl-function-action";
import { makeRelativePath, toTypescriptType } from "../utils";
import { ODataMetadata } from "../metadata";
} from '../metadata/csdl/csdl-function-action';
import { makeRelativePath, toTypescriptType } from '../utils';
import { ODataMetadata } from '../metadata';

export class Callable {
callables: CsdlCallable[] = [];
Expand Down Expand Up @@ -85,25 +85,25 @@ export class Callable {
const { binding, required, optional } = this.parameters();
const parameters = [...required, ...optional];
const bindingType =
binding !== undefined ? toTypescriptType(binding.Type) : "";
binding !== undefined ? toTypescriptType(binding.Type) : '';
const returnType = this.returnType();
const retType =
returnType === undefined ? "null" : toTypescriptType(returnType.Type);
const bindingMethod = !binding?.Collection ? "entity" : "entities";
const baseMethod = isFunction ? "function" : "action";
returnType === undefined ? 'null' : toTypescriptType(returnType.Type);
const bindingMethod = !binding?.Collection ? 'entity' : 'entities';
const baseMethod = isFunction ? 'function' : 'action';
const keyParameter = !binding?.Collection
? `key: EntityKey<${bindingType}>`
: "";
const key = !binding?.Collection ? `key` : "";
: '';
const key = !binding?.Collection ? `key` : '';
const parametersType =
parameters.length === 0
? "null"
? 'null'
: `{${parameters
.map((p) => {
const op = optional.includes(p);
return `${p.Name}${op ? "?" : ""}: ${toTypescriptType(p.Type)}`;
return `${p.Name}${op ? '?' : ''}: ${toTypescriptType(p.Type)}`;
})
.join(", ")}}`;
.join(', ')}}`;
return `public ${methodName}(${keyParameter}) {
return this.${bindingMethod}(${key}).${baseMethod}<${parametersType}, ${retType}>('${this.fullName()}');
}`;
Expand All @@ -119,22 +119,22 @@ export class Callable {
const methodName = strings.classify(this.callable.Name);
const responseType =
returnType === undefined
? "none"
? 'none'
: returnType?.Collection
? "entities"
: returnType?.Type.startsWith("Edm.")
? "property"
: "entity";
? 'entities'
: returnType?.Type.startsWith('Edm.')
? 'property'
: 'entity';
const retType =
returnType === undefined ? "null" : toTypescriptType(returnType.Type);
returnType === undefined ? 'null' : toTypescriptType(returnType.Type);

const bindingType =
binding !== undefined ? toTypescriptType(binding.Type) : "";
const baseMethod = isFunction ? "callFunction" : "callAction";
binding !== undefined ? toTypescriptType(binding.Type) : '';
const baseMethod = isFunction ? 'callFunction' : 'callAction';
const parametersCall =
parameters.length === 0
? "null"
: `{${parameters.map((p) => p.Name).join(", ")}}`;
? 'null'
: `{${parameters.map((p) => p.Name).join(', ')}}`;

// Method arguments
let args = !binding?.Collection ? [`key: EntityKey<${bindingType}>`] : [];
Expand All @@ -151,20 +151,20 @@ export class Callable {
: optional.map((p) => `${p.Name}?: ${toTypescriptType(p.Type)}`)),
];
const optionsType =
returnType !== undefined && returnType.Type.startsWith("Edm.")
returnType !== undefined && returnType.Type.startsWith('Edm.')
? isFunction
? "ODataOptions & {alias?: boolean}"
: "ODataOptions"
? 'ODataOptions & {alias?: boolean}'
: 'ODataOptions'
: isFunction
? `ODataFunctionOptions<${retType}>`
: `ODataActionOptions<${retType}>`;
args.push(`options?: ${optionsType}`);

// Key parameter
const key = !binding?.Collection ? `key` : "";
const key = !binding?.Collection ? `key` : '';

// Render
return `public call${methodName}(${args.join(", ")}) {
return `public call${methodName}(${args.join(', ')}) {
return this.${baseMethod}(${parametersCall}, this.${methodResourceName}(${key}), '${responseType}', options);
}`;
}
Expand All @@ -185,7 +185,7 @@ export abstract class Base {
public path(): string {
const directory = this.directory();
const filename = this.fileName();
return directory !== "" ? directory + `/${filename}` : filename;
return directory !== '' ? directory + `/${filename}` : filename;
}

public imports(): Import[] {
Expand Down Expand Up @@ -242,19 +242,19 @@ export class Index extends Base {
super(options);
}
public override template(): Source {
return url("./files/index");
return url('./files/index');
}
public override variables(): { [name: string]: any } {
return { ...this.options };
}
public override name() {
return "";
return '';
}
public override fileName() {
return "index";
return 'index';
}
public override directory() {
return "";
return '';
}
public override fullName() {
return this.name();
Expand All @@ -272,19 +272,19 @@ export class Metadata extends Base {
super(options);
}
public override template(): Source {
return url("./files/metadata");
return url('./files/metadata');
}
public override variables(): { [name: string]: any } {
return { content: JSON.stringify(this.meta.toJson(), null, 2) };
}
public override name() {
return "";
return '';
}
public override fileName() {
return "metadata";
return 'metadata';
}
public override directory() {
return "";
return '';
}
public override fullName() {
return this.name();
Expand Down
8 changes: 5 additions & 3 deletions projects/angular-odata/schematics/apigen/angular/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class EntityProperty {

type() {
let type = toTypescriptType(this.edmType.Type);
type += (this.edmType.Collection ? '[]' : '');
type += (this.edmType.Nullable ? ' | null' : '');
type += this.edmType.Collection ? '[]' : '';
type += this.edmType.Nullable ? ' | null' : '';
return type;
}
}
Expand All @@ -40,7 +40,9 @@ export class Entity extends Base {
}
public override variables(): { [name: string]: any } {
return {
type: this.name() + (this.edmType instanceof CsdlEntityType ? "EntityType" : "ComplexType"),
type:
this.name() +
(this.edmType instanceof CsdlEntityType ? 'EntityType' : 'ComplexType'),
baseType: this.edmType.BaseType,
properties: [
...(this.edmType.Property ?? []).map((p) => new EntityProperty(p)),
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-odata/schematics/apigen/angular/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Enum extends Base {
}
public override variables(): { [name: string]: any } {
return {
type: this.name() + "EnumType",
type: this.name() + 'EnumType',
values: (this.edmType.Member ?? []).map((m) => new EnumValue(m)),
};
}
Expand Down
32 changes: 16 additions & 16 deletions projects/angular-odata/schematics/apigen/angular/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { strings } from "@angular-devkit/core";
import { Base } from "./base";
import { CsdlEntityContainer } from "../metadata/csdl/csdl-entity-container";
import { CsdlSingleton } from "../metadata/csdl/csdl-singleton";
import { CsdlEntitySet } from "../metadata/csdl/csdl-entity-set";
import { url, Source } from "@angular-devkit/schematics";
import { Schema as ApiGenSchema } from "../schema";
import { strings } from '@angular-devkit/core';
import { Base } from './base';
import { CsdlEntityContainer } from '../metadata/csdl/csdl-entity-container';
import { CsdlSingleton } from '../metadata/csdl/csdl-singleton';
import { CsdlEntitySet } from '../metadata/csdl/csdl-entity-set';
import { url, Source } from '@angular-devkit/schematics';
import { Schema as ApiGenSchema } from '../schema';

export class Service extends Base {
constructor(
Expand All @@ -15,10 +15,10 @@ export class Service extends Base {
}
public override template(): Source {
return this.edmElement instanceof CsdlEntitySet
? url("./files/entityset-service")
? url('./files/entityset-service')
: this.edmElement instanceof CsdlSingleton
? url("./files/singleton-service")
: url("./files/entitycontainer-service");
? url('./files/singleton-service')
: url('./files/entitycontainer-service');
}
public override variables(): { [name: string]: any } {
return {
Expand All @@ -37,17 +37,17 @@ export class Service extends Base {
? this.edmElement.EntityType
: this.edmElement instanceof CsdlSingleton
? this.edmElement.Type
: "";
: '';
}

public override name() {
return strings.classify(this.edmElement.name()) + "Service";
return strings.classify(this.edmElement.name()) + 'Service';
}
public override fileName() {
return strings.dasherize(this.edmElement.name()) + ".service";
return strings.dasherize(this.edmElement.name()) + '.service';
}
public override directory() {
return this.edmElement.namespace().replace(/\./g, "/");
return this.edmElement.namespace().replace(/\./g, '/');
}
public override fullName() {
return this.edmElement.fullName();
Expand All @@ -61,12 +61,12 @@ export class Service extends Base {
}
for (var call of this.callables ?? []) {
const ret = call.returnType();
if (ret !== undefined && !ret.Type.startsWith("Edm.")) {
if (ret !== undefined && !ret.Type.startsWith('Edm.')) {
imports.push(ret.Type);
}
const { binding, required, optional } = call.parameters();
for (let param of [...required, ...optional]) {
if (!param.Type.startsWith("Edm.")) {
if (!param.Type.startsWith('Edm.')) {
imports.push(param.Type);
}
}
Expand Down
30 changes: 15 additions & 15 deletions projects/angular-odata/schematics/apigen/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strings, normalize } from "@angular-devkit/core";
import { strings, normalize } from '@angular-devkit/core';
import {
apply,
SchematicContext,
Expand All @@ -10,23 +10,23 @@ import {
mergeWith,
MergeStrategy,
SchematicsException,
} from "@angular-devkit/schematics";
} from '@angular-devkit/schematics';
import {
createDefaultPath,
getWorkspace,
} from "@schematics/angular/utility/workspace";
import { parseName } from "@schematics/angular/utility/parse-name";
} from '@schematics/angular/utility/workspace';
import { parseName } from '@schematics/angular/utility/parse-name';

import { Schema as ApiGenSchema } from "./schema";
import { ODataMetadataParser } from "./metadata/parser";
import { toTypescriptType } from "./utils";
import { Module } from "./angular/module";
import { ApiConfig } from "./angular/api-config";
import { Enum } from "./angular/enum";
import { Base, Callable, Index, Metadata } from "./angular/base";
import { Entity } from "./angular/entity";
import { Service } from "./angular/service";
import { CsdlAction, CsdlFunction } from "./metadata/csdl/csdl-function-action";
import { Schema as ApiGenSchema } from './schema';
import { ODataMetadataParser } from './metadata/parser';
import { toTypescriptType } from './utils';
import { Module } from './angular/module';
import { ApiConfig } from './angular/api-config';
import { Enum } from './angular/enum';
import { Base, Callable, Index, Metadata } from './angular/base';
import { Entity } from './angular/entity';
import { Service } from './angular/service';
import { CsdlAction, CsdlFunction } from './metadata/csdl/csdl-function-action';

const utils = {
toTypescriptType,
Expand All @@ -51,7 +51,7 @@ export function apigen(options: ApiGenSchema) {
options.name = parsedPath.name;
options.path = parsedPath.path;

const modulePath = options.path + "/" + strings.dasherize(options.name);
const modulePath = options.path + '/' + strings.dasherize(options.name);

return fetch(options.metadata)
.then((resp) => resp.text())
Expand Down
Loading

0 comments on commit 9a5f506

Please sign in to comment.