Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions package-lock.json

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

17 changes: 16 additions & 1 deletion packages/adapter-typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@
"access": "public",
"tag": "beta"
},
"keywords": [],
"keywords": [
"query",
"json",
"json-api",
"api",
"rest",
"api-utils",
"typeorm",
"include",
"pagination",
"sort",
"fields",
"filter",
"relations",
"typescript"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Tada5hi/rapiq.git",
Expand Down
24 changes: 22 additions & 2 deletions packages/codec-url/test/unit/simple-fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import {
Field,
FieldOperator,
Fields,
} from '@rapiq/core';
import { SimpleURLDecoder, SimpleURLEncoder } from '../../src/simple';

// todo: operator missing

describe('fields', () => {
let encoder : SimpleURLEncoder;
let decoder : SimpleURLDecoder;
Expand Down Expand Up @@ -45,4 +44,25 @@ describe('fields', () => {

expect(value).toEqual(decoded);
});

it('should encode operators & resolve them on decode', async () => {
const value = new Fields([
new Field('id', FieldOperator.INCLUDE),
new Field('name', FieldOperator.EXCLUDE),
new Field('realm.name', FieldOperator.EXCLUDE),
]);

const encoded = encoder.encodeFields(value);
// fields[__DEFAULT__]=+id,-name&fields[realm]=-name
expect(encoded).toEqual('fields%5B__DEFAULT__%5D=%2Bid%2C-name&fields%5Brealm%5D=-name');

// the operator prefixes are deltas against the receiving schema's
// defaults: a schemaless decode resolves them via Fields.execute,
// so an opt-in include flattens to a plain field and an exclusion
// with no default set to subtract from drops.
const decoded = decoder.decodeFields(encoded!);
expect(decoded).toEqual(new Fields([
new Field('id'),
]));
});
});
3 changes: 0 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,5 @@
"homepage": "https://github.com/Tada5hi/rapiq#readme",
"dependencies": {
"pathtrace": "^2.2.2"
},
"devDependencies": {
"@ucast/sql": "^1.0.0-alpha.12"
}
}
3 changes: 1 addition & 2 deletions packages/core/src/parser/parameter/filters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import type { Relations } from '../../../parameter';
import type { FiltersSchema, Schema } from '../../../schema';
import type { ObjectLiteral } from '../../../types';
import type { IParserOptions } from '../../types';

export type FiltersParseOptions<
RECORD extends ObjectLiteral = ObjectLiteral,
> = IParserOptions & {
> = {
relations?: Relations,
schema?: string | Schema<RECORD> | FiltersSchema<RECORD>,
throwOnFailure?: boolean,
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { PendingKeyValidation } from './parameter/validate';

export type ParseParameterOptions<
RECORD extends ObjectLiteral = ObjectLiteral,
> = IParserOptions & {
> = {
schema?: Schema<RECORD> | string,
relations?: Relations,
strict?: boolean,
Expand Down Expand Up @@ -71,15 +71,10 @@ export type ParseQueryOptions<
context?: unknown,
};

export type IParserOptions = {
/** @deprecated Call parseAsync() instead of selecting execution mode in options. */
async?: boolean,
};

export interface IParser<
Input = any,
Output = any,
Options extends IParserOptions = IParserOptions,
Options extends ObjectLiteral = ObjectLiteral,
> {
parse(input: Input, options?: Options): Output;

Expand Down
2 changes: 0 additions & 2 deletions packages/parser-simple/src/parameter/filters/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ export class SimpleFiltersParser extends BaseParser<
data: TempType,
scope: ResolutionScope<`${Parameter.FILTERS}`, RECORD>,
) : IFilter[] {
// todo: currentKey.value === DEFAULT_ID && empty data =>build defaults otherwise

const output : IFilter[] = [];

let keys = Object.keys(data.attributes);
Expand Down
4 changes: 2 additions & 2 deletions packages/parser-simple/test/unit/parser/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ describe('src/filter/index.ts', () => {
),
);

// todo: should be "role"."id" instead of "user_roles"."role.id"
// with deep nested include
// deep nested include: the IR keeps the full dotted path;
// column aliasing is the adapters' concern (buildRelationAlias)
output = parseFlat({ id: 1, 'realm.item.id': 4 }, { schema: 'user' });
expect(output).toEqual(
new Filters(
Expand Down
Loading