Skip to content

Commit

Permalink
Fix __parser and collection
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomvh committed Jun 12, 2024
1 parent 3652135 commit acba4b2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 65 deletions.
3 changes: 1 addition & 2 deletions projects/angular-odata/src/lib/models/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { finalize, map, switchMap } from 'rxjs/operators';
import { DEFAULT_VERSION } from '../constants';
import { ODataHelper } from '../helper';
import {
EntityKey,
ODataActionOptions,
ODataEntitiesAnnotations,
ODataEntityAnnotations,
Expand Down Expand Up @@ -1019,7 +1018,7 @@ export class ODataCollection<T, M extends ODataModel<T>>
options: ODataFunctionOptions<R> = {}
): Observable<R | ODataModel<R> | ODataCollection<R, ODataModel<R>> | null> {
const resource = this.resource();
if (!(resource instanceof ODataEntityResource))
if (!(resource instanceof ODataEntitySetResource))
return throwError(
() =>
new Error(
Expand Down
114 changes: 51 additions & 63 deletions projects/angular-odata/src/lib/resources/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { ODataOptions } from './types';

export type EntityKey<T> =
| {
readonly [P in keyof T]?: T[P];
}
readonly [P in keyof T]?: T[P];
}
| QueryCustomType
| string
| number;
Expand Down Expand Up @@ -171,8 +171,8 @@ export class ODataResource<T> {
return test === 'path'
? otherPath === selfPath
: test === 'params'
? Types.isEqual(selfParams, otherParams)
: otherPath === selfPath && Types.isEqual(selfParams, otherParams);
? Types.isEqual(selfParams, otherParams)
: otherPath === selfPath && Types.isEqual(selfParams, otherParams);
}

pathAndParams(
Expand Down Expand Up @@ -230,7 +230,7 @@ export class ODataResource<T> {
});
}

private __serializeParser(
private __parser(
value: any,
options?: ParserOptions,
resourceType?: string
Expand All @@ -249,22 +249,10 @@ export class ODataResource<T> {
return undefined;
}

private __deserializeParser(
value: any,
options?: ParserOptions,
resourceType?: string
): Parser<T> | undefined {
const type =
options !== undefined && Types.isPlainObject(value)
? ODataHelper[options.version || DEFAULT_VERSION].type(value)
: resourceType;
return (type !== undefined) ? this.api.parserForType<T>(type) : undefined;
}

deserialize(value: any, options?: ParserOptions): any {
const resourceType = this.incomingType();
const _d = (value: any, options?: ParserOptions) => {
const parser = this.__deserializeParser(value, options, resourceType);
const parser = this.__parser(value, options, resourceType);
return parser !== undefined ? parser.deserialize(value, options) : value;
};
return Array.isArray(value)
Expand All @@ -275,7 +263,7 @@ export class ODataResource<T> {
serialize(value: any, options?: ParserOptions): any {
const resourceType = this.outgoingType();
const _s = (value: any, options?: ParserOptions) => {
const parser = this.__serializeParser(value, options, resourceType);
const parser = this.__parser(value, options, resourceType);
return parser !== undefined ? parser.serialize(value, options) : value;
};
return Array.isArray(value)
Expand All @@ -286,7 +274,7 @@ export class ODataResource<T> {
encode(value: any, options?: ParserOptions): any {
const resourceType = this.outgoingType();
const _e = (value: any, options?: ParserOptions) => {
const parser = this.__serializeParser(value, options, resourceType);
const parser = this.__parser(value, options, resourceType);
return parser !== undefined ? parser.encode(value, options) : value;
};
return Array.isArray(value)
Expand Down Expand Up @@ -325,7 +313,7 @@ export class ODataResource<T> {
f: (q: ODataPathSegmentsHandler<T>, s?: ODataStructuredType<T>) => void
) {
const type = this.outgoingType();
f(new ODataPathSegmentsHandler<T>(this.pathSegments),
f(new ODataPathSegmentsHandler<T>(this.pathSegments),
type !== undefined ? this.api.structuredType<T>(type) : undefined
);
return this;
Expand All @@ -340,7 +328,7 @@ export class ODataResource<T> {
f: (q: ODataQueryOptionsHandler<T>, s?: ODataStructuredType<T>) => void
) {
const type = this.outgoingType();
f(new ODataQueryOptionsHandler<T>(this.queryOptions),
f(new ODataQueryOptionsHandler<T>(this.queryOptions),
type !== undefined ? this.api.structuredType<T>(type) : undefined
);
return this;
Expand All @@ -351,7 +339,7 @@ export class ODataResource<T> {
builder: ApplyExpressionBuilder<T>,
current?: ApplyExpression<T>
) => ApplyExpression<T>,
{type, fields}: {type?: string, fields?: { [P in keyof R]?: StructuredTypeFieldConfig }} = {}): ODataResource<R> {
{ type, fields }: { type?: string, fields?: { [P in keyof R]?: StructuredTypeFieldConfig } } = {}): ODataResource<R> {
const query = this.cloneQuery<any>();
const handler = new ODataQueryOptionsHandler<T>(query);
handler.apply(opts);
Expand Down Expand Up @@ -393,14 +381,14 @@ export class ODataResource<T> {
options: ODataOptions & {
etag?: string;
responseType?:
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
withCount?: boolean;
bodyQueryOptions?: QueryOption[];
} = {}
Expand All @@ -412,14 +400,14 @@ export class ODataResource<T> {
body: any,
options: ODataOptions & {
responseType?:
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
withCount?: boolean;
} = {}
): Observable<any> {
Expand All @@ -431,14 +419,14 @@ export class ODataResource<T> {
options: ODataOptions & {
etag?: string;
responseType?:
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
withCount?: boolean;
} = {}
): Observable<any> {
Expand All @@ -450,14 +438,14 @@ export class ODataResource<T> {
options: ODataOptions & {
etag?: string;
responseType?:
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
withCount?: boolean;
} = {}
): Observable<any> {
Expand All @@ -468,14 +456,14 @@ export class ODataResource<T> {
options: ODataOptions & {
etag?: string;
responseType?:
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
| 'arraybuffer'
| 'blob'
| 'json'
| 'text'
| 'value'
| 'property'
| 'entity'
| 'entities';
withCount?: boolean;
} = {}
): Observable<any> {
Expand Down

0 comments on commit acba4b2

Please sign in to comment.