New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

api-core

Package Overview
Dependencies
Maintainers
1
Versions
225
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-core - npm Package Compare versions

Comparing version 0.19.7 to 0.20.0

2

dist/index.d.ts

@@ -20,2 +20,2 @@ export { ApiEdgeDefinition, ApiEdge, ApiEdgeMetadata } from "./src/edge/ApiEdgeDefinition";

export { ApiAction, ApiActionTriggerKind } from "./src/query/ApiAction";
export { Api, ApiInfo } from "./src/Api";
export { Api, ApiInfo, ApiMetadata, ApiResolver, LocalApiResolver } from "./src/Api";

@@ -71,2 +71,3 @@ "use strict";

exports.Api = Api_1.Api;
exports.LocalApiResolver = Api_1.LocalApiResolver;
//# sourceMappingURL=index.js.map

@@ -27,2 +27,18 @@ import { ApiEdgeDefinition, ApiEdgeMetadata } from "./edge/ApiEdgeDefinition";

}
export interface ApiResolver {
resolveEdge(name: string, plural: boolean): Promise<ApiEdgeDefinition | undefined>;
resolveRelation(name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationOfEdge(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationTo(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationFrom(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
}
export declare class LocalApiResolver implements ApiResolver {
private readonly api;
constructor(api: Api);
resolveEdge(name: string, plural: boolean): Promise<ApiEdgeDefinition | undefined>;
resolveRelation(name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationOfEdge(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationFrom(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
resolveRelationTo(edge: string, name: string): Promise<ApiEdgeRelation | undefined>;
}
export declare class Api {

@@ -39,5 +55,10 @@ static defaultIdPostfix: string;

private queryBuilder;
private resolver;
constructor(version: string, ...edges: ApiEdgeDefinition[]);
findEdge: (name: string | null | undefined) => ApiEdgeDefinition | undefined;
parseRequest: (requestParts: string[], type?: ApiRequestType | null) => ApiRequest;
findEdge: (name: string, plural?: boolean) => Promise<ApiEdgeDefinition | undefined>;
findRelation(name: string): Promise<ApiEdgeRelation | undefined>;
findRelationOfEdge(edge: string | ApiEdgeDefinition, name: string): Promise<ApiEdgeRelation | undefined>;
findRelationTo(edge: string | ApiEdgeDefinition, name: string): Promise<ApiEdgeRelation | undefined>;
findRelationFrom(edge: string | ApiEdgeDefinition, name: string): Promise<ApiEdgeRelation | undefined>;
parseRequest: (requestParts: string[], type?: ApiRequestType | null) => Promise<ApiRequest>;
buildQuery: (request: ApiRequest) => ApiQuery;

@@ -49,4 +70,4 @@ edge(edge: ApiEdgeDefinition): this;

metadata: () => ApiMetadata;
static fromMetadata(metadata: ApiMetadata): Api;
static fromMetadata(metadata: ApiMetadata): Promise<Api>;
prepare(): Promise<void>;
}

@@ -17,2 +17,28 @@ "use strict";

const pkg = require('../../package.json');
class LocalApiResolver {
constructor(api) {
this.api = api;
}
resolveEdge(name, plural) {
if (plural) {
return Promise.resolve(this.api.edges.find(edge => edge.pluralName == name));
}
else {
return Promise.resolve(this.api.edges.find(edge => edge.name == name));
}
}
resolveRelation(name) {
return Promise.resolve(this.api.relations.find(relation => relation.name === name));
}
resolveRelationOfEdge(edge, name) {
return Promise.resolve(this.api.relations.find(relation => relation.name === name && (relation.from.pluralName === edge || relation.to.pluralName === edge)));
}
resolveRelationFrom(edge, name) {
return Promise.resolve(this.api.relations.find(relation => relation.name === name && relation.from.pluralName === edge));
}
resolveRelationTo(edge, name) {
return Promise.resolve(this.api.relations.find(relation => relation.name === name && relation.to.pluralName === edge));
}
}
exports.LocalApiResolver = LocalApiResolver;
class Api {

@@ -23,11 +49,11 @@ constructor(version, ...edges) {

this.actions = [];
this.findEdge = (name) => {
return this.edges.find((edge) => edge.pluralName == name);
this.findEdge = (name, plural = true) => {
return this.resolver.resolveEdge(name, plural);
};
this.parseRequest = (requestParts, type = null) => {
const result = this.parser.parse(requestParts);
this.parseRequest = (requestParts, type = null) => __awaiter(this, void 0, void 0, function* () {
const result = yield this.parser.parse(requestParts);
if (type)
result.type = type;
return result;
};
});
this.buildQuery = (request) => {

@@ -59,3 +85,19 @@ const query = this.queryBuilder.build(request);

this.queryBuilder = new ApiQueryBuilder_1.ApiQueryBuilder(this);
this.resolver = new LocalApiResolver(this);
}
findRelation(name) {
return this.resolver.resolveRelation(name);
}
findRelationOfEdge(edge, name) {
const edgeName = edge.pluralName || edge;
return this.resolver.resolveRelationOfEdge(edgeName, name);
}
findRelationTo(edge, name) {
const edgeName = edge.pluralName || edge;
return this.resolver.resolveRelationTo(edgeName, name);
}
findRelationFrom(edge, name) {
const edgeName = edge.pluralName || edge;
return this.resolver.resolveRelationFrom(edgeName, name);
}
edge(edge) {

@@ -74,11 +116,13 @@ this.edges.push(edge);

static fromMetadata(metadata) {
const api = new Api(metadata.version);
api.info = metadata.info;
for (let edge of metadata.edges) {
api.edge(new ExternalApiEdge_1.ExternalApiEdge(edge));
}
for (let relation of metadata.relations) {
api.relation(ApiEdgeRelation_1.ApiEdgeRelation.fromJSON(relation, api));
}
return api;
return __awaiter(this, void 0, void 0, function* () {
const api = new Api(metadata.version);
api.info = metadata.info;
for (let edge of metadata.edges) {
api.edge(new ExternalApiEdge_1.ExternalApiEdge(edge));
}
for (let relation of metadata.relations) {
api.relation(yield ApiEdgeRelation_1.ApiEdgeRelation.fromJSON(relation, api));
}
return api;
});
}

@@ -85,0 +129,0 @@ prepare() {

@@ -60,3 +60,3 @@ import { ApiEdgeRelation } from "../relations/ApiEdgeRelation";

metadata: () => ApiEdgeMetadata;
relation: (name: string) => ApiEdgeRelation | null;
relation: (name: string) => Promise<ApiEdgeRelation | undefined>;
get(key: string): any;

@@ -113,3 +113,3 @@ set(key: string, value: any): any;

action: (name: string, execute: (scope: ApiQueryScope) => Promise<ApiQueryScope>, targetTypes?: ApiEdgeQueryType, triggerKind?: ApiEdgeActionTriggerKind, triggers?: ApiEdgeActionTrigger, triggerNames?: string[]) => ApiEdge;
relation: (name: string) => ApiEdgeRelation | null;
relation: (name: string) => Promise<ApiEdgeRelation | undefined>;
edgeMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, requiresData?: boolean): ApiEdge;

@@ -116,0 +116,0 @@ edgeMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, parameters?: string[], requiresData?: boolean): ApiEdge;

@@ -56,5 +56,3 @@ "use strict";

};
this.relation = (name) => {
return this.relations.find(r => r.name === name) || null;
};
this.relation = (name) => this.api.findRelationOfEdge(this.pluralName, name);
this.extension = {};

@@ -61,0 +59,0 @@ this.get = (key) => this.extension[key];

@@ -30,3 +30,3 @@ import { ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter } from "./ApiEdgeQueryFilter";

toJSON: () => ExportedApiEdgeQueryContext;
static fromJSON: (obj: ExportedApiEdgeQueryContext, api: Api) => ApiEdgeQueryContext;
static fromJSON: (obj: ExportedApiEdgeQueryContext, api: Api) => Promise<ApiEdgeQueryContext>;
constructor(id?: string | null, fields?: string[]);

@@ -33,0 +33,0 @@ paginate: (skip: number, limit: number) => this;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -75,7 +83,10 @@ const ApiEdgeQueryFilter_1 = require("./ApiEdgeQueryFilter");

}
ApiEdgeQueryContext.fromJSON = (obj, api) => {
ApiEdgeQueryContext.fromJSON = (obj, api) => __awaiter(this, void 0, void 0, function* () {
const context = new ApiEdgeQueryContext();
context.id = obj.id;
context.fields = obj.fields;
context.populatedRelations = obj.populatedRelations.map(name => api.relations.find(r => r.name === name));
context.populatedRelations = [];
for (let name of obj.populatedRelations) {
context.populatedRelations.push(yield api.findRelation(name));
}
context.pagination = obj.pagination;

@@ -86,4 +97,4 @@ context.sortBy = obj.sortBy;

return context;
};
});
exports.ApiEdgeQueryContext = ApiEdgeQueryContext;
//# sourceMappingURL=ApiEdgeQueryContext.js.map

@@ -34,3 +34,3 @@ import { ApiEdgeDefinition } from "../edge/ApiEdgeDefinition";

};
static fromJSON(obj: ExportedApiEdgeRelation, api: Api): ApiEdgeRelation;
static fromJSON(obj: ExportedApiEdgeRelation, api: Api): Promise<ApiEdgeRelation>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -21,9 +29,11 @@ exports.ApiEdgeRelationTypes = {};

static fromJSON(obj, api) {
const Relation = exports.ApiEdgeRelationTypes[obj.type];
const relation = new Relation(api.edges.find(edge => edge.name == obj.from), api.edges.find(edge => edge.name == obj.to));
relation.relationId = obj.relationId;
relation.relatedId = obj.relatedId;
relation.name = obj.name;
relation.hasPair = obj.hasPair;
return relation;
return __awaiter(this, void 0, void 0, function* () {
const Relation = exports.ApiEdgeRelationTypes[obj.type];
const relation = new Relation(yield api.findEdge(obj.from, false), yield api.findEdge(obj.to, false));
relation.relationId = obj.relationId;
relation.relatedId = obj.relatedId;
relation.name = obj.name;
relation.hasPair = obj.hasPair;
return relation;
});
}

@@ -30,0 +40,0 @@ }

@@ -9,3 +9,3 @@ import { ApiRequestPath, ApiRequest } from "./ApiRequest";

private findMethodByName;
parse(segments: string[]): ApiRequestPath;
parse(segments: string[]): Promise<ApiRequestPath>;
}

@@ -16,3 +16,3 @@ export declare class ApiRequestParser {

constructor(api: Api);
parse(segments: string[]): ApiRequest;
parse(segments: string[]): Promise<ApiRequest>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,3 +24,3 @@ const ApiRequest_1 = require("./ApiRequest");

findRelationByName(edge, name) {
return edge.relations.find((rel) => rel.name === name);
return this.api.findRelationOfEdge(edge, name);
}

@@ -30,55 +38,57 @@ findMethodByName(edge, name, forEntry) {

parse(segments) {
let requestPath = new ApiRequest_1.ApiRequestPath();
let lastEdge = null, lastRelation = null, wasEntry = false;
while (segments.length) {
let segment = segments.shift();
if (lastEdge) {
let relation = this.findRelationByName(lastEdge, segment);
if (relation) {
if (relation instanceof OneToOneRelation_1.OneToOneRelation) {
requestPath.add(new ApiRequest_1.RelatedFieldPathSegment(lastEdge, relation));
lastEdge = relation.to;
lastRelation = relation;
wasEntry = true;
return __awaiter(this, void 0, void 0, function* () {
let requestPath = new ApiRequest_1.ApiRequestPath();
let lastEdge = null, lastRelation = null, wasEntry = false;
while (segments.length) {
let segment = segments.shift() || '';
if (lastEdge) {
let relation = yield this.findRelationByName(lastEdge, segment);
if (relation) {
if (relation instanceof OneToOneRelation_1.OneToOneRelation) {
requestPath.add(new ApiRequest_1.RelatedFieldPathSegment(lastEdge, relation));
lastEdge = relation.to;
lastRelation = relation;
wasEntry = true;
}
else if (wasEntry && relation instanceof OneToManyRelation_1.OneToManyRelation) {
lastEdge = relation.to;
lastRelation = relation;
wasEntry = false;
}
else {
throw new ApiEdgeError_1.ApiEdgeError(400, "Unsupported Relation: " + segment);
}
}
else if (wasEntry && relation instanceof OneToManyRelation_1.OneToManyRelation) {
lastEdge = relation.to;
lastRelation = relation;
wasEntry = false;
}
else {
throw new ApiEdgeError_1.ApiEdgeError(400, "Unsupported Relation: " + segment);
let method = this.findMethodByName(lastEdge, segment, wasEntry);
if (method) {
requestPath.add(new ApiRequest_1.MethodPathSegment(lastEdge, method));
wasEntry = true;
}
else if (!wasEntry) {
requestPath.add(new ApiRequest_1.EntryPathSegment(lastEdge, "" + segment, lastRelation));
wasEntry = true;
}
else {
throw new ApiEdgeError_1.ApiEdgeError(400, `Missing Relation/Method: ${lastEdge.name} -> ${segment}`);
}
}
}
else {
let method = this.findMethodByName(lastEdge, segment, wasEntry);
if (method) {
requestPath.add(new ApiRequest_1.MethodPathSegment(lastEdge, method));
wasEntry = true;
let edge = yield this.findEdgeByName(segment);
if (edge) {
lastEdge = edge;
wasEntry = false;
}
else if (!wasEntry) {
requestPath.add(new ApiRequest_1.EntryPathSegment(lastEdge, "" + segment, lastRelation));
wasEntry = true;
}
else {
throw new ApiEdgeError_1.ApiEdgeError(400, `Missing Relation/Method: ${lastEdge.name} -> ${segment}`);
throw new ApiEdgeError_1.ApiEdgeError(400, "Missing Edge: " + segment);
}
}
}
else {
let edge = this.findEdgeByName(segment);
if (edge) {
lastEdge = edge;
wasEntry = false;
}
else {
throw new ApiEdgeError_1.ApiEdgeError(400, "Missing Edge: " + segment);
}
if (lastEdge && !wasEntry) {
requestPath.add(new ApiRequest_1.EdgePathSegment(lastEdge, lastRelation));
lastEdge = null;
}
}
if (lastEdge && !wasEntry) {
requestPath.add(new ApiRequest_1.EdgePathSegment(lastEdge, lastRelation));
lastEdge = null;
}
return requestPath;
return requestPath;
});
}

@@ -93,5 +103,7 @@ }

parse(segments) {
let request = new ApiRequest_1.ApiRequest(this.api);
request.path = this.pathParser.parse(segments);
return request;
return __awaiter(this, void 0, void 0, function* () {
let request = new ApiRequest_1.ApiRequest(this.api);
request.path = yield this.pathParser.parse(segments);
return request;
});
}

@@ -98,0 +110,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -64,4 +72,4 @@ const ApiEdgeError_1 = require("../src/query/ApiEdgeError");

});
tap.test('/schools', (t) => {
const request = api.parseRequest(['schools']), query = api.buildQuery(request);
tap.test('/schools', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools']), query = api.buildQuery(request);
t.equal(query.steps.length, 2, 'should build a 2 step query');

@@ -93,5 +101,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextQueryStep);

});
});
tap.test('/schools/s2', (t) => {
const request = api.parseRequest(['schools', 's2']), query = api.buildQuery(request);
}));
tap.test('/schools/s2', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2']), query = api.buildQuery(request);
t.equal(query.steps.length, 3, 'should build a 3 step query');

@@ -116,5 +124,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextLiveQueryStep);

});
});
tap.test('/schools/s5', (t) => {
const request = api.parseRequest(['schools', 's5']), query = api.buildQuery(request);
}));
tap.test('/schools/s5', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's5']), query = api.buildQuery(request);
query.execute()

@@ -131,5 +139,5 @@ .then(() => {

});
});
tap.test('/schools/s1/classes', (t) => {
const request = api.parseRequest(['schools', 's1', 'classes']), query = api.buildQuery(request);
}));
tap.test('/schools/s1/classes', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's1', 'classes']), query = api.buildQuery(request);
t.equal(query.steps.length, 5, 'should build a 5 step query');

@@ -159,5 +167,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextLiveQueryStep, 'EXTEND');

});
});
tap.test('/schools/s1/classes/c1', (t) => {
const request = api.parseRequest(['schools', 's1', 'classes', 'c1']), query = api.buildQuery(request);
}));
tap.test('/schools/s1/classes/c1', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's1', 'classes', 'c1']), query = api.buildQuery(request);
t.equal(query.steps.length, 6, 'should build a 6 step query');

@@ -186,5 +194,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextLiveQueryStep, 'EXTEND');

});
});
tap.test('/students/s2/class', (t) => {
const request = api.parseRequest(['students', 's2', 'class']), query = api.buildQuery(request);
}));
tap.test('/students/s2/class', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['students', 's2', 'class']), query = api.buildQuery(request);
t.equal(query.steps.length, 5, 'should build a 5 step query');

@@ -212,5 +220,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextLiveQueryStep, 'EXTEND');

});
});
tap.test('/schools/s1/classes/c2', (t) => {
const request = api.parseRequest(['schools', 's1', 'classes', 'c2']), query = api.buildQuery(request);
}));
tap.test('/schools/s1/classes/c2', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's1', 'classes', 'c2']), query = api.buildQuery(request);
query.execute()

@@ -227,5 +235,5 @@ .then(() => {

});
});
tap.test('POST /schools', (t) => {
const request = api.parseRequest(['schools']);
}));
tap.test('POST /schools', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools']);
request.type = ApiRequest_1.ApiRequestType.Create;

@@ -252,5 +260,5 @@ const body = request.body = {

});
});
tap.test('DELETE /schools/s3', (t) => {
const request = api.parseRequest(['schools', 's3']);
}));
tap.test('DELETE /schools/s3', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's3']);
request.type = ApiRequest_1.ApiRequestType.Delete;

@@ -271,5 +279,5 @@ const query = api.buildQuery(request);

});
});
tap.test('DELETE /students/s2/class', (t) => {
const request = api.parseRequest(['students', 's2', 'class']);
}));
tap.test('DELETE /students/s2/class', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['students', 's2', 'class']);
request.type = ApiRequest_1.ApiRequestType.Delete;

@@ -287,5 +295,5 @@ try {

}
});
tap.test('PATCH /schools/s2', (t) => {
const request = api.parseRequest(['schools', 's2']);
}));
tap.test('PATCH /schools/s2', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2']);
request.type = ApiRequest_1.ApiRequestType.Patch;

@@ -316,5 +324,5 @@ request.body = {

});
});
tap.test('PUT /schools/s2', (t) => {
const request = api.parseRequest(['schools', 's2']);
}));
tap.test('PUT /schools/s2', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2']);
request.type = ApiRequest_1.ApiRequestType.Update;

@@ -345,5 +353,5 @@ request.body = {

});
});
tap.test('GET /students/s2/rename', (t) => {
const request = api.parseRequest(['students', 's2', 'rename']);
}));
tap.test('GET /students/s2/rename', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['students', 's2', 'rename']);
request.type = ApiRequest_1.ApiRequestType.Read;

@@ -360,5 +368,5 @@ try {

t.end();
});
tap.test('/students/s2/withHungarianName', (t) => {
const request = api.parseRequest(['students', 's2', 'withHungarianName']), query = api.buildQuery(request);
}));
tap.test('/students/s2/withHungarianName', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['students', 's2', 'withHungarianName']), query = api.buildQuery(request);
t.equal(query.steps.length, 5, 'should build an 5 step query');

@@ -387,5 +395,5 @@ t.ok(query.steps[0] instanceof builder.ExtendContextLiveQueryStep, 'EXTEND');

});
});
tap.test('POST /students/s2/rename', (t) => {
const request = api.parseRequest(['students', 's2', 'rename']);
}));
tap.test('POST /students/s2/rename', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['students', 's2', 'rename']);
request.type = ApiRequest_1.ApiRequestType.Update;

@@ -416,3 +424,3 @@ request.body = { name: "Test David" };

});
});
}));
//# sourceMappingURL=query-builder.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -35,4 +43,4 @@ const tap = require('tap');

});
tap.test('POST /schools/s2/students', (t) => {
const request = api.parseRequest(['schools', 's2', 'students']);
tap.test('POST /schools/s2/students', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students']);
request.type = ApiRequest_1.ApiRequestType.Create;

@@ -68,5 +76,5 @@ request.body = {

});
});
tap.test('POST /schools/s2/classes/c1/students', (t) => {
const request = api.parseRequest(['schools', 's2', 'classes', 'c1', 'students']);
}));
tap.test('POST /schools/s2/classes/c1/students', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'classes', 'c1', 'students']);
request.type = ApiRequest_1.ApiRequestType.Create;

@@ -104,5 +112,5 @@ request.body = {

});
});
tap.test('POST /schools/s2/students (invalid body)', (t) => {
const request = api.parseRequest(['schools', 's2', 'students']);
}));
tap.test('POST /schools/s2/students (invalid body)', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students']);
request.type = ApiRequest_1.ApiRequestType.Create;

@@ -139,5 +147,5 @@ request.body = {

});
});
tap.test('POST /schools/s2/classes/c1/students (invalid body)', (t) => {
const request = api.parseRequest(['schools', 's2', 'classes', 'c1', 'students']);
}));
tap.test('POST /schools/s2/classes/c1/students (invalid body)', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'classes', 'c1', 'students']);
request.type = ApiRequest_1.ApiRequestType.Create;

@@ -177,5 +185,5 @@ request.body = {

});
});
tap.test('PATCH /schools/s2/students/s7', (t) => {
const request = api.parseRequest(['schools', 's2', 'students', 's7']);
}));
tap.test('PATCH /schools/s2/students/s7', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students', 's7']);
request.type = ApiRequest_1.ApiRequestType.Patch;

@@ -211,5 +219,5 @@ request.body = {

});
});
tap.test('PATCH /schools/s2/students/s7 (invalid body)', (t) => {
const request = api.parseRequest(['schools', 's2', 'students', 's7']);
}));
tap.test('PATCH /schools/s2/students/s7 (invalid body)', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students', 's7']);
request.type = ApiRequest_1.ApiRequestType.Patch;

@@ -246,5 +254,5 @@ request.body = {

});
});
tap.test('PUT /schools/s2/students/s7', (t) => {
const request = api.parseRequest(['schools', 's2', 'students', 's7']);
}));
tap.test('PUT /schools/s2/students/s7', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students', 's7']);
request.type = ApiRequest_1.ApiRequestType.Update;

@@ -284,5 +292,5 @@ request.body = {

});
});
tap.test('PUT /schools/s2/students/s7 (invalid body)', (t) => {
const request = api.parseRequest(['schools', 's2', 'students', 's7']);
}));
tap.test('PUT /schools/s2/students/s7 (invalid body)', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students', 's7']);
request.type = ApiRequest_1.ApiRequestType.Update;

@@ -322,5 +330,5 @@ request.body = {

});
});
tap.test('DELETE /schools/s2/students/s7', (t) => {
const request = api.parseRequest(['schools', 's2', 'students', 's7']);
}));
tap.test('DELETE /schools/s2/students/s7', (t) => __awaiter(this, void 0, void 0, function* () {
const request = yield api.parseRequest(['schools', 's2', 'students', 's7']);
request.type = ApiRequest_1.ApiRequestType.Delete;

@@ -344,3 +352,3 @@ const query = api.buildQuery(request);

});
});
}));
//# sourceMappingURL=related-change-queries.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -55,7 +63,7 @@ const tap = require('tap');

.relation(collectionRelation));
tap.test('path should be empty when the input array is empty', (t) => {
const path = parser.parse([]);
tap.test('path should be empty when the input array is empty', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse([]);
t.equal(path.segments.length, 0);
t.end();
});
}));
tap.test('parser should not allow missing edges', (t) => {

@@ -74,4 +82,4 @@ t.throws(() => { parser.parse(['test']); }, 'Missing Edge: test', 'should not allow missing start edge');

});
tap.test('parser should parse single edge segment request', (t) => {
const path = parser.parse(['entries']);
tap.test('parser should parse single edge segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries']);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -82,5 +90,5 @@ t.ok(path.segments[0] instanceof request.EdgePathSegment, 'should have an edge path segment');

t.end();
});
tap.test('parser should parse single entry segment request', (t) => {
const path = parser.parse(['entries', '42']);
}));
tap.test('parser should parse single entry segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', '42']);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -92,5 +100,5 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

t.end();
});
tap.test('parser should parse single edge method segment request', (t) => {
const path = parser.parse(['entries', 'method']);
}));
tap.test('parser should parse single edge method segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', 'method']);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -101,5 +109,5 @@ t.ok(path.segments[0] instanceof request.MethodPathSegment, 'should have a method path segment');

t.end();
});
tap.test('parser should parse single related entry segment request', (t) => {
const path = parser.parse(['entries', '42', 'relatedEntry']);
}));
tap.test('parser should parse single related entry segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', '42', 'relatedEntry']);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -114,5 +122,5 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

t.end();
});
tap.test('parser should parse single entry method segment request', (t) => {
const path = parser.parse(['entries', '42', 'entryMethod']);
}));
tap.test('parser should parse single entry method segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', '42', 'entryMethod']);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -127,5 +135,5 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

t.end();
});
tap.test('parser should parse single related entry method segment request', (t) => {
const path = parser.parse(['entries', '42', 'relatedEntry', 'relatedEntryMethod']);
}));
tap.test('parser should parse single related entry method segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', '42', 'relatedEntry', 'relatedEntryMethod']);
t.equal(path.segments.length, 3, 'should have two segments');

@@ -143,5 +151,5 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

t.end();
});
tap.test('parser should parse single related collection segment request', (t) => {
const path = parser.parse(['entries', '42', 'relatedCollection']);
}));
tap.test('parser should parse single related collection segment request', (t) => __awaiter(this, void 0, void 0, function* () {
const path = yield parser.parse(['entries', '42', 'relatedCollection']);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -156,3 +164,3 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

t.end();
});
}));
tap.test('unsupported relation should cause error', (t) => {

@@ -171,8 +179,8 @@ const unsupportedRelation = function () {

});
tap.test('request parser should work too', (t) => {
tap.test('request parser should work too', (t) => __awaiter(this, void 0, void 0, function* () {
const requestParser = new ApiRequestParser_1.ApiRequestParser(new Api_1.Api('1.0'));
const request = requestParser.parse([]);
const request = yield requestParser.parse([]);
t.equal(request.path.segments.length, 0);
t.end();
});
}));
//# sourceMappingURL=request-parser.js.map

@@ -31,2 +31,2 @@ export {ApiEdgeDefinition, ApiEdge, ApiEdgeMetadata} from "./src/edge/ApiEdgeDefinition";

export {Api, ApiInfo} from "./src/Api";
export {Api, ApiInfo, ApiMetadata, ApiResolver, LocalApiResolver} from "./src/Api";
{
"name": "api-core",
"version": "0.19.7",
"version": "0.20.0",
"description": "Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -34,2 +34,61 @@ import {ApiEdgeDefinition, ApiEdgeMetadata} from "./edge/ApiEdgeDefinition";

export interface ApiResolver {
resolveEdge(name: string, plural: boolean): Promise<ApiEdgeDefinition|undefined>;
resolveRelation(name: string): Promise<ApiEdgeRelation|undefined>;
resolveRelationOfEdge(edge: string, name: string): Promise<ApiEdgeRelation|undefined>;
resolveRelationTo(edge: string, name: string): Promise<ApiEdgeRelation|undefined>;
resolveRelationFrom(edge: string, name: string): Promise<ApiEdgeRelation|undefined>;
}
export class LocalApiResolver implements ApiResolver {
private readonly api: Api;
constructor(api: Api) {
this.api = api
}
resolveEdge(name: string, plural: boolean) {
if(plural) {
return Promise.resolve(
this.api.edges.find(edge => edge.pluralName == name)
)
}
else {
return Promise.resolve(
this.api.edges.find(edge => edge.name == name)
)
}
}
resolveRelation(name: string) {
return Promise.resolve(
this.api.relations.find(relation => relation.name === name)
)
}
resolveRelationOfEdge(edge: string, name: string) {
return Promise.resolve(
this.api.relations.find(relation =>
relation.name === name && (relation.from.pluralName === edge || relation.to.pluralName === edge)
)
)
}
resolveRelationFrom(edge: string, name: string) {
return Promise.resolve(
this.api.relations.find(relation =>
relation.name === name && relation.from.pluralName === edge
)
)
}
resolveRelationTo(edge: string, name: string) {
return Promise.resolve(
this.api.relations.find(relation =>
relation.name === name && relation.to.pluralName === edge
)
)
}
}
export class Api {

@@ -48,2 +107,3 @@ static defaultIdPostfix: string = "Id";

private queryBuilder: ApiQueryBuilder;
private resolver: ApiResolver;

@@ -55,10 +115,30 @@ constructor(version: string, ...edges: ApiEdgeDefinition[]) {

this.queryBuilder = new ApiQueryBuilder(this);
this.resolver = new LocalApiResolver(this)
}
findEdge = (name: string|null|undefined) => {
return this.edges.find((edge: ApiEdgeDefinition) => edge.pluralName == name)
findEdge = (name: string, plural = true) => {
return this.resolver.resolveEdge(name, plural)
};
parseRequest = (requestParts: string[], type: ApiRequestType|null = null) => {
const result = this.parser.parse(requestParts);
findRelation(name: string) {
return this.resolver.resolveRelation(name)
}
findRelationOfEdge(edge: string|ApiEdgeDefinition, name: string) {
const edgeName = (edge as any).pluralName || edge;
return this.resolver.resolveRelationOfEdge(edgeName, name)
}
findRelationTo(edge: string|ApiEdgeDefinition, name: string) {
const edgeName = (edge as any).pluralName || edge;
return this.resolver.resolveRelationTo(edgeName, name)
}
findRelationFrom(edge: string|ApiEdgeDefinition, name: string) {
const edgeName = (edge as any).pluralName || edge;
return this.resolver.resolveRelationFrom(edgeName, name)
}
parseRequest = async (requestParts: string[], type: ApiRequestType|null = null) => {
const result = await this.parser.parse(requestParts);
if(type) result.type = type;

@@ -109,3 +189,3 @@ return result

static fromMetadata(metadata: ApiMetadata): Api {
static async fromMetadata(metadata: ApiMetadata): Promise<Api> {
const api = new Api(metadata.version);

@@ -120,3 +200,3 @@ api.info = metadata.info;

for(let relation of metadata.relations) {
api.relation(ApiEdgeRelation.fromJSON(relation, api))
api.relation(await ApiEdgeRelation.fromJSON(relation, api))
}

@@ -123,0 +203,0 @@

@@ -62,3 +62,3 @@ import {ApiEdgeRelation} from "../relations/ApiEdgeRelation";

metadata: () => ApiEdgeMetadata
relation: (name: string) => ApiEdgeRelation|null;
relation: (name: string) => Promise<ApiEdgeRelation|undefined>;

@@ -141,5 +141,3 @@ get(key: string): any;

relation = (name: string) => {
return this.relations.find(r => r.name === name) || null
};
relation = (name: string) => this.api.findRelationOfEdge(this.pluralName, name);

@@ -146,0 +144,0 @@ edgeMethod(name: string,

@@ -63,9 +63,10 @@ import {ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter} from "./ApiEdgeQueryFilter";

static fromJSON = (obj: ExportedApiEdgeQueryContext, api: Api) => {
static fromJSON = async (obj: ExportedApiEdgeQueryContext, api: Api) => {
const context = new ApiEdgeQueryContext();
context.id = obj.id;
context.fields = obj.fields;
context.populatedRelations = obj.populatedRelations.map(
name => api.relations.find(r => r.name === name) as OneToOneRelation
);
context.populatedRelations = [];
for(let name of obj.populatedRelations) {
context.populatedRelations.push(await api.findRelation(name) as OneToOneRelation)
}
context.pagination = obj.pagination;

@@ -72,0 +73,0 @@ context.sortBy = obj.sortBy;

@@ -44,7 +44,7 @@ import {ApiEdgeDefinition} from "../edge/ApiEdgeDefinition";

static fromJSON(obj: ExportedApiEdgeRelation, api: Api): ApiEdgeRelation {
static async fromJSON(obj: ExportedApiEdgeRelation, api: Api): Promise<ApiEdgeRelation> {
const Relation = ApiEdgeRelationTypes[obj.type];
const relation = new Relation(
api.edges.find(edge => edge.name == obj.from) as any,
api.edges.find(edge => edge.name == obj.to) as any
await api.findEdge(obj.from, false) as ApiEdgeDefinition,
await api.findEdge(obj.to, false) as ApiEdgeDefinition
);

@@ -51,0 +51,0 @@ relation.relationId = obj.relationId;

@@ -20,8 +20,8 @@ import {ApiEdgeDefinition} from "../edge/ApiEdgeDefinition";

private findEdgeByName(name: string|null|undefined): ApiEdgeDefinition|undefined {
private findEdgeByName(name: string) {
return this.api.findEdge(name);
}
private findRelationByName(edge: ApiEdgeDefinition, name: string|null|undefined): ApiEdgeRelation|undefined {
return edge.relations.find((rel: ApiEdgeRelation) => rel.name === name);
private findRelationByName(edge: ApiEdgeDefinition, name: string) {
return this.api.findRelationOfEdge(edge, name)
}

@@ -44,3 +44,3 @@

parse(segments: string[]): ApiRequestPath {
async parse(segments: string[]): Promise<ApiRequestPath> {
let requestPath = new ApiRequestPath();

@@ -52,6 +52,6 @@

while(segments.length) {
let segment = segments.shift();
let segment = segments.shift() || '';
if(lastEdge) {
let relation: ApiEdgeRelation|undefined = this.findRelationByName(lastEdge, segment);
let relation: ApiEdgeRelation|undefined = await this.findRelationByName(lastEdge, segment);
if(relation) {

@@ -91,3 +91,3 @@ if(relation instanceof OneToOneRelation) {

else {
let edge = this.findEdgeByName(segment);
let edge = await this.findEdgeByName(segment);

@@ -123,7 +123,7 @@ if(edge) {

parse(segments: string[]): ApiRequest {
async parse(segments: string[]): Promise<ApiRequest> {
let request = new ApiRequest(this.api);
request.path = this.pathParser.parse(segments);
request.path = await this.pathParser.parse(segments);
return request;
}
}

@@ -75,4 +75,4 @@ import {ApiEdgeError} from "../src/query/ApiEdgeError";

tap.test('/schools', (t: any) => {
const request = api.parseRequest([ 'schools' ]),
tap.test('/schools', async (t: any) => {
const request = await api.parseRequest([ 'schools' ]),
query = api.buildQuery(request);

@@ -110,4 +110,4 @@

tap.test('/schools/s2', (t: any) => {
const request = api.parseRequest([ 'schools', 's2' ]),
tap.test('/schools/s2', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2' ]),
query = api.buildQuery(request);

@@ -138,4 +138,4 @@

tap.test('/schools/s5', (t: any) => {
const request = api.parseRequest([ 'schools', 's5' ]),
tap.test('/schools/s5', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's5' ]),
query = api.buildQuery(request);

@@ -156,4 +156,4 @@

tap.test('/schools/s1/classes', (t: any) => {
const request = api.parseRequest([ 'schools', 's1', 'classes' ]),
tap.test('/schools/s1/classes', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's1', 'classes' ]),
query = api.buildQuery(request);

@@ -189,4 +189,4 @@

tap.test('/schools/s1/classes/c1', (t: any) => {
const request = api.parseRequest([ 'schools', 's1', 'classes', 'c1' ]),
tap.test('/schools/s1/classes/c1', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's1', 'classes', 'c1' ]),
query = api.buildQuery(request);

@@ -221,4 +221,4 @@

tap.test('/students/s2/class', (t: any) => {
const request = api.parseRequest([ 'students', 's2', 'class' ]),
tap.test('/students/s2/class', async (t: any) => {
const request = await api.parseRequest([ 'students', 's2', 'class' ]),
query = api.buildQuery(request);

@@ -251,4 +251,4 @@

tap.test('/schools/s1/classes/c2', (t: any) => {
const request = api.parseRequest([ 'schools', 's1', 'classes', 'c2' ]),
tap.test('/schools/s1/classes/c2', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's1', 'classes', 'c2' ]),
query = api.buildQuery(request);

@@ -269,4 +269,4 @@

tap.test('POST /schools', (t: any) => {
const request = api.parseRequest([ 'schools' ]);
tap.test('POST /schools', async (t: any) => {
const request = await api.parseRequest([ 'schools' ]);
request.type = ApiRequestType.Create;

@@ -297,4 +297,4 @@ const body = request.body = {

tap.test('DELETE /schools/s3', (t: any) => {
const request = api.parseRequest([ 'schools', 's3' ]);
tap.test('DELETE /schools/s3', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's3' ]);
request.type = ApiRequestType.Delete;

@@ -319,4 +319,4 @@ const query = api.buildQuery(request);

tap.test('DELETE /students/s2/class', (t: any) => {
const request = api.parseRequest([ 'students', 's2', 'class' ]);
tap.test('DELETE /students/s2/class', async (t: any) => {
const request = await api.parseRequest([ 'students', 's2', 'class' ]);
request.type = ApiRequestType.Delete;

@@ -337,4 +337,4 @@

tap.test('PATCH /schools/s2', (t: any) => {
const request = api.parseRequest([ 'schools', 's2' ]);
tap.test('PATCH /schools/s2', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2' ]);
request.type = ApiRequestType.Patch;

@@ -370,4 +370,4 @@ request.body = {

tap.test('PUT /schools/s2', (t: any) => {
const request = api.parseRequest([ 'schools', 's2' ]);
tap.test('PUT /schools/s2', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2' ]);
request.type = ApiRequestType.Update;

@@ -403,4 +403,4 @@ request.body = {

tap.test('GET /students/s2/rename', (t: any) => {
const request = api.parseRequest([ 'students', 's2', 'rename' ]);
tap.test('GET /students/s2/rename', async (t: any) => {
const request = await api.parseRequest([ 'students', 's2', 'rename' ]);
request.type = ApiRequestType.Read;

@@ -420,4 +420,4 @@

tap.test('/students/s2/withHungarianName', (t: any) => {
const request = api.parseRequest([ 'students', 's2', 'withHungarianName' ]),
tap.test('/students/s2/withHungarianName', async (t: any) => {
const request = await api.parseRequest([ 'students', 's2', 'withHungarianName' ]),
query = api.buildQuery(request);

@@ -451,4 +451,4 @@

tap.test('POST /students/s2/rename', (t: any) => {
const request = api.parseRequest([ 'students', 's2', 'rename' ]);
tap.test('POST /students/s2/rename', async (t: any) => {
const request = await api.parseRequest([ 'students', 's2', 'rename' ]);
request.type = ApiRequestType.Update;

@@ -455,0 +455,0 @@ request.body = { name: "Test David" };

@@ -44,4 +44,4 @@ const tap = require('tap');

tap.test('POST /schools/s2/students', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students' ]);
tap.test('POST /schools/s2/students', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students' ]);
request.type = ApiRequestType.Create;

@@ -81,4 +81,4 @@ request.body = {

tap.test('POST /schools/s2/classes/c1/students', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'classes', 'c1', 'students' ]);
tap.test('POST /schools/s2/classes/c1/students', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'classes', 'c1', 'students' ]);
request.type = ApiRequestType.Create;

@@ -120,4 +120,4 @@ request.body = {

tap.test('POST /schools/s2/students (invalid body)', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students' ]);
tap.test('POST /schools/s2/students (invalid body)', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students' ]);
request.type = ApiRequestType.Create;

@@ -158,4 +158,4 @@ request.body = {

tap.test('POST /schools/s2/classes/c1/students (invalid body)', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'classes', 'c1', 'students' ]);
tap.test('POST /schools/s2/classes/c1/students (invalid body)', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'classes', 'c1', 'students' ]);
request.type = ApiRequestType.Create;

@@ -199,4 +199,4 @@ request.body = {

tap.test('PATCH /schools/s2/students/s7', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
tap.test('PATCH /schools/s2/students/s7', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
request.type = ApiRequestType.Patch;

@@ -237,4 +237,4 @@ request.body = {

tap.test('PATCH /schools/s2/students/s7 (invalid body)', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
tap.test('PATCH /schools/s2/students/s7 (invalid body)', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
request.type = ApiRequestType.Patch;

@@ -276,4 +276,4 @@ request.body = {

tap.test('PUT /schools/s2/students/s7', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
tap.test('PUT /schools/s2/students/s7', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
request.type = ApiRequestType.Update;

@@ -318,4 +318,4 @@ request.body = {

tap.test('PUT /schools/s2/students/s7 (invalid body)', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
tap.test('PUT /schools/s2/students/s7 (invalid body)', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
request.type = ApiRequestType.Update;

@@ -360,4 +360,4 @@ request.body = {

tap.test('DELETE /schools/s2/students/s7', (t: any) => {
const request = api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
tap.test('DELETE /schools/s2/students/s7', async (t: any) => {
const request = await api.parseRequest([ 'schools', 's2', 'students', 's7' ]);
request.type = ApiRequestType.Delete;

@@ -364,0 +364,0 @@ const query = api.buildQuery(request);

@@ -65,4 +65,4 @@ const tap = require('tap');

tap.test('path should be empty when the input array is empty', (t: any) => {
const path = parser.parse([]);
tap.test('path should be empty when the input array is empty', async (t: any) => {
const path = await parser.parse([]);
t.equal(path.segments.length, 0);

@@ -93,4 +93,4 @@ t.end()

tap.test('parser should parse single edge segment request', (t: any) => {
const path = parser.parse([ 'entries' ]);
tap.test('parser should parse single edge segment request', async (t: any) => {
const path = await parser.parse([ 'entries' ]);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -103,4 +103,4 @@ t.ok(path.segments[0] instanceof request.EdgePathSegment, 'should have an edge path segment');

tap.test('parser should parse single entry segment request', (t: any) => {
const path = parser.parse([ 'entries', '42' ]);
tap.test('parser should parse single entry segment request', async (t: any) => {
const path = await parser.parse([ 'entries', '42' ]);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -114,4 +114,4 @@ t.ok(path.segments[0] instanceof request.EntryPathSegment, 'should have an entry path segment');

tap.test('parser should parse single edge method segment request', (t: any) => {
const path = parser.parse([ 'entries', 'method' ]);
tap.test('parser should parse single edge method segment request', async (t: any) => {
const path = await parser.parse([ 'entries', 'method' ]);
t.equal(path.segments.length, 1, 'should have one segment');

@@ -124,4 +124,4 @@ t.ok(path.segments[0] instanceof request.MethodPathSegment, 'should have a method path segment');

tap.test('parser should parse single related entry segment request', (t: any) => {
const path = parser.parse([ 'entries', '42', 'relatedEntry' ]);
tap.test('parser should parse single related entry segment request', async (t: any) => {
const path = await parser.parse([ 'entries', '42', 'relatedEntry' ]);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -141,4 +141,4 @@

tap.test('parser should parse single entry method segment request', (t: any) => {
const path = parser.parse([ 'entries', '42', 'entryMethod' ]);
tap.test('parser should parse single entry method segment request', async (t: any) => {
const path = await parser.parse([ 'entries', '42', 'entryMethod' ]);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -158,4 +158,4 @@

tap.test('parser should parse single related entry method segment request', (t: any) => {
const path = parser.parse([ 'entries', '42', 'relatedEntry', 'relatedEntryMethod' ]);
tap.test('parser should parse single related entry method segment request', async (t: any) => {
const path = await parser.parse([ 'entries', '42', 'relatedEntry', 'relatedEntryMethod' ]);
t.equal(path.segments.length, 3, 'should have two segments');

@@ -179,4 +179,4 @@

tap.test('parser should parse single related collection segment request', (t: any) => {
const path = parser.parse([ 'entries', '42', 'relatedCollection' ]);
tap.test('parser should parse single related collection segment request', async (t: any) => {
const path = await parser.parse([ 'entries', '42', 'relatedCollection' ]);
t.equal(path.segments.length, 2, 'should have two segments');

@@ -214,7 +214,7 @@

tap.test('request parser should work too', (t: any) => {
tap.test('request parser should work too', async (t: any) => {
const requestParser = new ApiRequestParser(new Api('1.0'));
const request = requestParser.parse([]);
const request = await requestParser.parse([]);
t.equal(request.path.segments.length, 0);
t.end()
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc