Comparing version 0.26.5 to 3.0.0
@@ -1,2 +0,3 @@ | ||
export { ApiEdgeDefinition, ApiEdge, ApiEdgeMetadata } from "./src/edge/ApiEdgeDefinition"; | ||
export { ApiEdgeDefinition, ApiEdge } from "./src/edge/ApiEdgeDefinition"; | ||
export { ApiEdgeMetadata } from "./src/edge/ApiEdgeMetadata"; | ||
export { ExternalApiEdge, ExternalApiProvider } from "./src/edge/ExternalApiEdge"; | ||
@@ -9,3 +10,3 @@ export { ApiEdgeQueryType } from "./src/edge/ApiEdgeQueryType"; | ||
export { ApiEdgeQuery } from "./src/edge/ApiEdgeQuery"; | ||
export { ApiEdgeMethod, ApiEdgeMethodScope } from "./src/edge/ApiEdgeMethod"; | ||
export { ApiEdgeMethod, ApiEdgeMethodScope, ApiEdgeMethodOutput } from "./src/edge/ApiEdgeMethod"; | ||
export { ApiEdgeError } from "./src/query/ApiEdgeError"; | ||
@@ -12,0 +13,0 @@ export { ApiEdgeRelation, ApiEdgeRelationConstructor, ApiEdgeRelationTypes } from "./src/relations/ApiEdgeRelation"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LocalApiResolver = exports.LazyApiEdge = exports.ApiActionTriggerKind = exports.ApiAction = exports.ApiEdgeActionTriggerKind = exports.ApiEdgeActionTrigger = exports.ApiEdgeAction = exports.RelateChangeQueryStep = exports.SetResponseQueryStep = exports.SetBodyQueryStep = exports.RelateQueryStep = exports.QueryEdgeQueryStep = exports.ProvideIdQueryStep = exports.ExtendContextQueryStep = exports.CallMethodQueryStep = exports.ApiQueryBuilder = exports.ApiQuery = exports.ApiRequestPathParser = exports.RelatedFieldPathSegment = exports.PathSegment = exports.MethodPathSegment = exports.EntryPathSegment = exports.EdgePathSegment = exports.ApiRequestType = exports.ApiRequestPath = exports.ApiRequest = exports.OneToManyRelation = exports.OneToOneRelation = exports.ApiEdgeRelationTypes = exports.ApiEdgeRelation = exports.ApiEdgeError = exports.ApiEdgeMethodOutput = exports.ApiEdgeMethodScope = exports.ApiEdgeMethod = exports.ApiEdgeQuery = exports.JSONDate = exports.SchemaReference = exports.SubSchema = exports.Mixed = exports.ApiEdgeSchemaTransformation = exports.ApiEdgeSchema = exports.ApiEdgeQueryFilterType = exports.ApiEdgeQueryFilter = exports.ApiEdgeQueryStreamResponse = exports.ApiEdgeQueryResponse = exports.ApiEdgeQueryContext = exports.ApiEdgeQueryType = exports.ExternalApiProvider = exports.ExternalApiEdge = exports.ApiEdge = void 0; | ||
exports.Api = void 0; | ||
var ApiEdgeDefinition_1 = require("./src/edge/ApiEdgeDefinition"); | ||
@@ -30,2 +32,3 @@ Object.defineProperty(exports, "ApiEdge", { enumerable: true, get: function () { return ApiEdgeDefinition_1.ApiEdge; } }); | ||
Object.defineProperty(exports, "ApiEdgeMethodScope", { enumerable: true, get: function () { return ApiEdgeMethod_1.ApiEdgeMethodScope; } }); | ||
Object.defineProperty(exports, "ApiEdgeMethodOutput", { enumerable: true, get: function () { return ApiEdgeMethod_1.ApiEdgeMethodOutput; } }); | ||
var ApiEdgeError_1 = require("./src/query/ApiEdgeError"); | ||
@@ -32,0 +35,0 @@ Object.defineProperty(exports, "ApiEdgeError", { enumerable: true, get: function () { return ApiEdgeError_1.ApiEdgeError; } }); |
@@ -1,2 +0,3 @@ | ||
import { ApiEdgeDefinition, ApiEdgeMetadata } from "./edge/ApiEdgeDefinition"; | ||
import { ApiEdgeDefinition } from "./edge/ApiEdgeDefinition"; | ||
import { ApiEdgeMetadata } from "./edge/ApiEdgeMetadata"; | ||
import { ApiRequest, ApiRequestType } from "./request/ApiRequest"; | ||
@@ -22,3 +23,2 @@ import { ApiQuery, ApiQueryScope } from "./query/ApiQuery"; | ||
export interface ApiMetadata { | ||
'api-core': string; | ||
info: ApiInfo; | ||
@@ -28,3 +28,8 @@ version: string; | ||
relations: ExportedApiEdgeRelation[]; | ||
services: ApiService[]; | ||
} | ||
export interface ApiService { | ||
name: string; | ||
version: string; | ||
} | ||
export declare class Api { | ||
@@ -35,3 +40,3 @@ static defaultIdPostfix: string; | ||
info?: ApiInfo; | ||
version: string; | ||
service: ApiService; | ||
edges: ApiEdgeDefinition[]; | ||
@@ -43,3 +48,3 @@ relations: ApiEdgeRelation[]; | ||
resolver: ApiResolver; | ||
constructor(version: string, ...edges: ApiEdgeDefinition[]); | ||
constructor(service: ApiService, ...edges: ApiEdgeDefinition[]); | ||
findEdge: (name: string, plural?: boolean) => Promise<ApiEdgeDefinition | undefined>; | ||
@@ -59,2 +64,5 @@ findRelation(name: string): Promise<ApiEdgeRelation | undefined>; | ||
prepare(): Promise<void>; | ||
private extension; | ||
get: (key: string) => any; | ||
set: (key: string, value: any) => any; | ||
} |
@@ -20,101 +20,101 @@ "use strict"; | ||
const pkg = require('../../package.json'); | ||
let Api = (() => { | ||
class Api { | ||
constructor(version, ...edges) { | ||
this.edges = []; | ||
this.relations = []; | ||
this.actions = []; | ||
this.findEdge = (name, plural = true) => { | ||
return this.resolver.resolveEdge(name, plural); | ||
}; | ||
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) => { | ||
const query = this.queryBuilder.build(request); | ||
query.request = request; | ||
return query; | ||
}; | ||
this.use = (action) => { | ||
this.actions.unshift(action); | ||
return this; | ||
}; | ||
this.action = (name, execute, triggerKind = ApiAction_1.ApiActionTriggerKind.OnInput) => { | ||
this.actions.unshift(new ApiAction_1.ApiAction(name, execute, triggerKind)); | ||
return this; | ||
}; | ||
this.metadata = () => { | ||
return { | ||
'api-core': pkg.version, | ||
info: this.info || { title: 'API' }, | ||
version: this.version, | ||
edges: this.edges | ||
.filter(edge => !edge.external) | ||
.map(edge => edge.metadata()), | ||
relations: this.relations | ||
.map(relation => relation.toJSON()) | ||
}; | ||
}; | ||
this.version = version; | ||
this.edges = edges; | ||
this.parser = new ApiRequestParser_1.ApiRequestParser(this); | ||
this.queryBuilder = new ApiQueryBuilder_1.ApiQueryBuilder(this); | ||
this.resolver = new LocalApiResolver_1.LocalApiResolver(this); | ||
} | ||
findRelation(name) { | ||
return this.resolver.resolveRelation(name); | ||
} | ||
findRelationOfEdge(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationOfEdge(edgeName, name); | ||
} | ||
findRelationTo(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationTo(edgeName, name); | ||
} | ||
findRelationFrom(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationFrom(edgeName, name); | ||
} | ||
edge(edge) { | ||
this.edges.push(edge); | ||
edge.api = this; | ||
class Api { | ||
constructor(service, ...edges) { | ||
this.edges = []; | ||
this.relations = []; | ||
this.actions = []; | ||
this.findEdge = (name, plural = true) => { | ||
return this.resolver.resolveEdge(name, plural); | ||
}; | ||
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) => { | ||
const query = this.queryBuilder.build(request); | ||
query.request = request; | ||
return query; | ||
}; | ||
this.use = (action) => { | ||
this.actions.unshift(action); | ||
return this; | ||
} | ||
; | ||
relation(relation) { | ||
relation.from.relations.push(relation); | ||
relation.to.relations.push(relation); | ||
this.relations.push(relation); | ||
}; | ||
this.action = (name, execute, triggerKind = ApiAction_1.ApiActionTriggerKind.OnInput) => { | ||
this.actions.unshift(new ApiAction_1.ApiAction(name, execute, triggerKind)); | ||
return this; | ||
} | ||
static fromMetadata(metadata) { | ||
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; | ||
}); | ||
} | ||
prepare() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (let edge of this.edges) { | ||
yield edge.prepare(this); | ||
} | ||
}); | ||
} | ||
}; | ||
this.metadata = () => { | ||
return { | ||
info: this.info || { title: 'API' }, | ||
version: pkg.version, | ||
services: [this.service], | ||
edges: this.edges | ||
.filter(edge => !edge.external) | ||
.map(edge => edge.metadata()), | ||
relations: this.relations | ||
.map(relation => relation.toJSON()) | ||
}; | ||
}; | ||
this.extension = {}; | ||
this.get = (key) => this.extension[key]; | ||
this.set = (key, value) => this.extension[key] = value; | ||
this.service = service; | ||
this.edges = edges; | ||
this.parser = new ApiRequestParser_1.ApiRequestParser(this); | ||
this.queryBuilder = new ApiQueryBuilder_1.ApiQueryBuilder(this); | ||
this.resolver = new LocalApiResolver_1.LocalApiResolver(this); | ||
} | ||
Api.defaultIdPostfix = "Id"; | ||
Api.defaultIdField = "id"; | ||
return Api; | ||
})(); | ||
findRelation(name) { | ||
return this.resolver.resolveRelation(name); | ||
} | ||
findRelationOfEdge(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationOfEdge(edgeName, name); | ||
} | ||
findRelationTo(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationTo(edgeName, name); | ||
} | ||
findRelationFrom(edge, name) { | ||
const edgeName = edge.name || edge; | ||
return this.resolver.resolveRelationFrom(edgeName, name); | ||
} | ||
edge(edge) { | ||
this.edges.push(edge); | ||
edge.api = this; | ||
return this; | ||
} | ||
; | ||
relation(relation) { | ||
relation.from.relations.push(relation); | ||
relation.to.relations.push(relation); | ||
this.relations.push(relation); | ||
return this; | ||
} | ||
static fromMetadata(metadata) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const api = new Api(metadata.services[0] || {}); | ||
api.info = metadata.info; | ||
for (let edge of metadata.edges) { | ||
api.edge(new ExternalApiEdge_1.ExternalApiEdge(edge, api)); | ||
} | ||
for (let relation of metadata.relations) { | ||
api.relation(yield ApiEdgeRelation_1.ApiEdgeRelation.fromJSON(relation, api)); | ||
} | ||
return api; | ||
}); | ||
} | ||
prepare() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (let edge of this.edges) { | ||
yield edge.prepare(this); | ||
} | ||
}); | ||
} | ||
} | ||
exports.Api = Api; | ||
Api.defaultIdPostfix = "Id"; | ||
Api.defaultIdField = "id"; | ||
//# sourceMappingURL=Api.js.map |
@@ -12,24 +12,3 @@ import { ApiEdgeRelation } from "../relations/ApiEdgeRelation"; | ||
import { ApiEdgeQuery } from "./ApiEdgeQuery"; | ||
export interface ApiEdgeMetadata { | ||
name: string; | ||
pluralName: string; | ||
idField: string; | ||
fields: string[]; | ||
methods: { | ||
name: string; | ||
type: ApiRequestType; | ||
parameters: string[]; | ||
}[]; | ||
typings?: { | ||
[key: string]: any; | ||
}; | ||
allowGet: boolean; | ||
allowList: boolean; | ||
allowCreate: boolean; | ||
allowUpdate: boolean; | ||
allowPatch: boolean; | ||
allowRemove: boolean; | ||
allowExists: boolean; | ||
external: boolean; | ||
} | ||
import { ApiEdgeMetadata } from "./ApiEdgeMetadata"; | ||
export interface ApiEdgeDefinition { | ||
@@ -36,0 +15,0 @@ name: string; |
@@ -29,2 +29,3 @@ import { ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter } from "./ApiEdgeQueryFilter"; | ||
identity: any; | ||
method: string; | ||
clone: () => ApiEdgeQueryContext; | ||
@@ -31,0 +32,0 @@ toJSON: () => ExportedApiEdgeQueryContext; |
@@ -15,91 +15,88 @@ "use strict"; | ||
const ApiEdgeQueryParameter_1 = require("./ApiEdgeQueryParameter"); | ||
let ApiEdgeQueryContext = (() => { | ||
class ApiEdgeQueryContext { | ||
constructor(id = null, fields = []) { | ||
this.fields = []; | ||
this.populatedRelations = []; | ||
this.sortBy = []; | ||
this.filters = []; | ||
this.parameters = []; | ||
this.clone = () => { | ||
let temp = new ApiEdgeQueryContext(); | ||
temp.id = this.id; | ||
temp.identity = this.identity; | ||
this.fields.forEach(f => temp.fields.push(f)); | ||
this.populatedRelations.forEach(f => temp.populatedRelations.push(f)); | ||
this.filters.forEach(f => temp.filters.push(f.clone())); | ||
this.parameters.forEach(f => temp.parameters.push(f.clone())); | ||
this.sortBy.forEach(f => temp.sortBy.push([f[0], f[1]])); | ||
if (this.pagination) { | ||
temp.pagination = { | ||
skip: this.pagination.skip, | ||
limit: this.pagination.limit | ||
}; | ||
} | ||
return temp; | ||
}; | ||
this.toJSON = () => { | ||
return { | ||
id: this.id, | ||
fields: this.fields, | ||
populatedRelations: this.populatedRelations.map(relation => relation.name), | ||
pagination: this.pagination, | ||
sortBy: this.sortBy, | ||
filters: this.filters, | ||
parameters: this.parameters | ||
class ApiEdgeQueryContext { | ||
constructor(id = null, fields = []) { | ||
this.fields = []; | ||
this.populatedRelations = []; | ||
this.sortBy = []; | ||
this.filters = []; | ||
this.parameters = []; | ||
this.clone = () => { | ||
let temp = new ApiEdgeQueryContext(); | ||
temp.id = this.id; | ||
temp.identity = this.identity; | ||
this.fields.forEach(f => temp.fields.push(f)); | ||
this.populatedRelations.forEach(f => temp.populatedRelations.push(f)); | ||
this.filters.forEach(f => temp.filters.push(f.clone())); | ||
this.parameters.forEach(f => temp.parameters.push(f.clone())); | ||
this.sortBy.forEach(f => temp.sortBy.push([f[0], f[1]])); | ||
if (this.pagination) { | ||
temp.pagination = { | ||
skip: this.pagination.skip, | ||
limit: this.pagination.limit | ||
}; | ||
} | ||
return temp; | ||
}; | ||
this.toJSON = () => { | ||
return { | ||
id: this.id, | ||
fields: this.fields, | ||
populatedRelations: this.populatedRelations.map(relation => relation.name), | ||
pagination: this.pagination, | ||
sortBy: this.sortBy, | ||
filters: this.filters, | ||
parameters: this.parameters | ||
}; | ||
this.paginate = (skip, limit) => { | ||
this.pagination = { | ||
skip, limit | ||
}; | ||
return this; | ||
}; | ||
this.paginate = (skip, limit) => { | ||
this.pagination = { | ||
skip, limit | ||
}; | ||
this.sort = (fieldName, ascending = true) => { | ||
this.sortBy.push([fieldName, (ascending ? 1 : -1)]); | ||
return this; | ||
}; | ||
this.id = id; | ||
this.fields = fields; | ||
} | ||
populate(relation) { | ||
this.populatedRelations.push(relation); | ||
return this; | ||
} | ||
field(field) { | ||
this.fields.push(field); | ||
}; | ||
this.sort = (fieldName, ascending = true) => { | ||
this.sortBy.push([fieldName, (ascending ? 1 : -1)]); | ||
return this; | ||
}; | ||
this.id = id; | ||
this.fields = fields; | ||
} | ||
populate(relation) { | ||
this.populatedRelations.push(relation); | ||
return this; | ||
} | ||
field(field) { | ||
this.fields.push(field); | ||
return this; | ||
} | ||
filter(field, type, value) { | ||
this.filters.push(new ApiEdgeQueryFilter_1.ApiEdgeQueryFilter(field, type, value)); | ||
return this; | ||
} | ||
parameter(key, value) { | ||
if (typeof value === "undefined") { | ||
const param = this.parameters.find(p => p.key === key); | ||
return param ? param.value : null; | ||
} | ||
filter(field, type, value) { | ||
this.filters.push(new ApiEdgeQueryFilter_1.ApiEdgeQueryFilter(field, type, value)); | ||
else { | ||
this.parameters.push(new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return this; | ||
} | ||
parameter(key, value) { | ||
if (typeof value === "undefined") { | ||
const param = this.parameters.find(p => p.key === key); | ||
return param ? param.value : null; | ||
} | ||
else { | ||
this.parameters.push(new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return this; | ||
} | ||
} | ||
} | ||
ApiEdgeQueryContext.fromJSON = (obj, api) => __awaiter(void 0, void 0, void 0, function* () { | ||
const context = new ApiEdgeQueryContext(); | ||
context.id = obj.id; | ||
context.fields = obj.fields; | ||
context.populatedRelations = []; | ||
for (let name of obj.populatedRelations) { | ||
context.populatedRelations.push(yield api.findRelation(name)); | ||
} | ||
context.pagination = obj.pagination; | ||
context.sortBy = obj.sortBy; | ||
context.filters = obj.filters.map(({ field, type, value }) => new ApiEdgeQueryFilter_1.ApiEdgeQueryFilter(field, type, value)); | ||
context.parameters = obj.parameters.map(({ key, value }) => new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return context; | ||
}); | ||
return ApiEdgeQueryContext; | ||
})(); | ||
} | ||
exports.ApiEdgeQueryContext = ApiEdgeQueryContext; | ||
ApiEdgeQueryContext.fromJSON = (obj, api) => __awaiter(void 0, void 0, void 0, function* () { | ||
const context = new ApiEdgeQueryContext(); | ||
context.id = obj.id; | ||
context.fields = obj.fields; | ||
context.populatedRelations = []; | ||
for (let name of obj.populatedRelations) { | ||
context.populatedRelations.push(yield api.findRelation(name)); | ||
} | ||
context.pagination = obj.pagination; | ||
context.sortBy = obj.sortBy; | ||
context.filters = obj.filters.map(({ field, type, value }) => new ApiEdgeQueryFilter_1.ApiEdgeQueryFilter(field, type, value)); | ||
context.parameters = obj.parameters.map(({ key, value }) => new ApiEdgeQueryParameter_1.ApiEdgeQueryParameter(key, value)); | ||
return context; | ||
}); | ||
//# sourceMappingURL=ApiEdgeQueryContext.js.map |
@@ -49,3 +49,3 @@ "use strict"; | ||
let output = []; | ||
fields.forEach((field) => { | ||
for (const field of fields) { | ||
const transformedFields = this.fieldMatrix[field]; | ||
@@ -55,5 +55,9 @@ if (transformedFields) { | ||
} | ||
else | ||
output.push(field); | ||
}); | ||
else { | ||
if (this.renameMatrix[field]) | ||
output.push(this.renameMatrix[field]); | ||
else | ||
output.push(field); | ||
} | ||
} | ||
return output; | ||
@@ -60,0 +64,0 @@ }; |
@@ -5,5 +5,7 @@ import { ApiEdgeQueryContext } from "./ApiEdgeQueryContext"; | ||
import { ApiQueryScope } from "../query/ApiQuery"; | ||
import { Api } from "../Api"; | ||
export declare abstract class ExternalApiProvider { | ||
protected metadata: any; | ||
protected constructor(metadata: any); | ||
protected api: Api; | ||
protected constructor(metadata: any, api: Api); | ||
abstract getEntry: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; | ||
@@ -21,5 +23,6 @@ abstract listEntries: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; | ||
export declare class ExternalApiEdge extends ApiEdge { | ||
constructor(metadata: any, provider?: ExternalApiProvider); | ||
constructor(metadata: any, api: Api, provider?: ExternalApiProvider); | ||
url: string; | ||
provider: ExternalApiProvider; | ||
api: Api; | ||
getEntry: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; | ||
@@ -26,0 +29,0 @@ listEntries: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; |
@@ -19,4 +19,5 @@ "use strict"; | ||
class ExternalApiProvider { | ||
constructor(metadata) { | ||
constructor(metadata, api) { | ||
this.metadata = metadata; | ||
this.api = api; | ||
} | ||
@@ -26,3 +27,3 @@ edge() { | ||
yield this.prepare(); | ||
return new ExternalApiEdge(this.metadata, this); | ||
return new ExternalApiEdge(this.metadata, this.api, this); | ||
}); | ||
@@ -33,3 +34,3 @@ } | ||
class ExternalApiEdge extends ApiEdgeDefinition_1.ApiEdge { | ||
constructor(metadata, provider) { | ||
constructor(metadata, api, provider) { | ||
super(); | ||
@@ -57,2 +58,3 @@ this.getEntry = (context) => { | ||
}); | ||
this.api = api; | ||
this.name = metadata.name; | ||
@@ -59,0 +61,0 @@ this.pluralName = metadata.pluralName; |
@@ -153,2 +153,3 @@ "use strict"; | ||
this.query.context = scope.context; | ||
this.query.context.populatedRelations = []; | ||
this.query.context.identity = scope.identity; | ||
@@ -172,2 +173,3 @@ this.query.execute().then((response) => { | ||
debug(`[${scope.query.id}]`, this.inspect()); | ||
scope.context.method = this.method.name; | ||
this.method.execute(scope) | ||
@@ -174,0 +176,0 @@ .then((response) => { |
@@ -47,5 +47,5 @@ import { ApiEdgeDefinition } from "../edge/ApiEdgeDefinition"; | ||
prepare: () => Promise<void>; | ||
metadata: () => import("../edge/ApiEdgeDefinition").ApiEdgeMetadata; | ||
metadata: () => import("../..").ApiEdgeMetadata; | ||
get(key: string): any; | ||
set(key: string, value: any): any; | ||
} |
@@ -9,41 +9,38 @@ "use strict"; | ||
const Class_1 = require("../model/Class"); | ||
let RawDataProvider = (() => { | ||
class RawDataProvider { | ||
} | ||
RawDataProvider.schools = [ | ||
School_1.School.create("s1", "First School", "16, Test street, North Pole, HA23535", "435234523"), | ||
School_1.School.create("s2", "Second School", "12, Test street, North Pole, HA23535", "456345283") | ||
]; | ||
RawDataProvider.courseTypes = [ | ||
CourseType_1.CourseType.create("ct1", "Mathematics"), | ||
CourseType_1.CourseType.create("ct2", "Science"), | ||
CourseType_1.CourseType.create("ct3", "Sport"), | ||
CourseType_1.CourseType.create("ct4", "English"), | ||
CourseType_1.CourseType.create("ct5", "Biology") | ||
]; | ||
RawDataProvider.courses = [ | ||
Course_1.Course.create("c1", "Maths A1", "ct1", "c1"), | ||
Course_1.Course.create("c2", "Advanced English", "ct4", ""), | ||
Course_1.Course.create("c3", "English", "ct4", "c2"), | ||
Course_1.Course.create("c4", "Daily Sport", "ct3", "c2"), | ||
Course_1.Course.create("c5", "Biology A2", "ct5", "c2"), | ||
Course_1.Course.create("c6", "Science A1", "ct3", "c1"), | ||
]; | ||
RawDataProvider.classes = [ | ||
Class_1.Class.create("c1", "A", 1, "Room 1", "s1"), | ||
Class_1.Class.create("c2", "A", 1, "Room 1", "s2"), | ||
Class_1.Class.create("c3", "B", 1, "Room 2", "s2") | ||
]; | ||
RawDataProvider.students = [ | ||
Student_1.Student.create("s1", "Peter", "Test", "peter.test@gmail.com", "123456789", "s1", "c1"), | ||
Student_1.Student.create("s2", "Dave", "Test", "dave.test@gmail.com", "347633445", "s1", "c1"), | ||
Student_1.Student.create("s3", "Gabe", "Test", "gabe.test@gmail.com", "453612674", "s2", "c2"), | ||
Student_1.Student.create("s3", "Fred", "Test", "fred.test@gmail.com", "982364432", "s2", "c2"), | ||
Student_1.Student.create("s4", "Kate", "Test", "kate.test@gmail.com", "645723475", "s2", "c3"), | ||
Student_1.Student.create("s5", "Mark", "Test", "mark.test@gmail.com", "865232467", "s2", "c3"), | ||
Student_1.Student.create("s6", "Anna", "Test", "anna.test@gmail.com", "234885357", "s1", "c3") | ||
]; | ||
return RawDataProvider; | ||
})(); | ||
class RawDataProvider { | ||
} | ||
exports.RawDataProvider = RawDataProvider; | ||
RawDataProvider.schools = [ | ||
School_1.School.create("s1", "First School", "16, Test street, North Pole, HA23535", "435234523"), | ||
School_1.School.create("s2", "Second School", "12, Test street, North Pole, HA23535", "456345283") | ||
]; | ||
RawDataProvider.courseTypes = [ | ||
CourseType_1.CourseType.create("ct1", "Mathematics"), | ||
CourseType_1.CourseType.create("ct2", "Science"), | ||
CourseType_1.CourseType.create("ct3", "Sport"), | ||
CourseType_1.CourseType.create("ct4", "English"), | ||
CourseType_1.CourseType.create("ct5", "Biology") | ||
]; | ||
RawDataProvider.courses = [ | ||
Course_1.Course.create("c1", "Maths A1", "ct1", "c1"), | ||
Course_1.Course.create("c2", "Advanced English", "ct4", ""), | ||
Course_1.Course.create("c3", "English", "ct4", "c2"), | ||
Course_1.Course.create("c4", "Daily Sport", "ct3", "c2"), | ||
Course_1.Course.create("c5", "Biology A2", "ct5", "c2"), | ||
Course_1.Course.create("c6", "Science A1", "ct3", "c1"), | ||
]; | ||
RawDataProvider.classes = [ | ||
Class_1.Class.create("c1", "A", 1, "Room 1", "s1"), | ||
Class_1.Class.create("c2", "A", 1, "Room 1", "s2"), | ||
Class_1.Class.create("c3", "B", 1, "Room 2", "s2") | ||
]; | ||
RawDataProvider.students = [ | ||
Student_1.Student.create("s1", "Peter", "Test", "peter.test@gmail.com", "123456789", "s1", "c1"), | ||
Student_1.Student.create("s2", "Dave", "Test", "dave.test@gmail.com", "347633445", "s1", "c1"), | ||
Student_1.Student.create("s3", "Gabe", "Test", "gabe.test@gmail.com", "453612674", "s2", "c2"), | ||
Student_1.Student.create("s3", "Fred", "Test", "fred.test@gmail.com", "982364432", "s2", "c2"), | ||
Student_1.Student.create("s4", "Kate", "Test", "kate.test@gmail.com", "645723475", "s2", "c3"), | ||
Student_1.Student.create("s5", "Mark", "Test", "mark.test@gmail.com", "865232467", "s2", "c3"), | ||
Student_1.Student.create("s6", "Anna", "Test", "anna.test@gmail.com", "234885357", "s1", "c3") | ||
]; | ||
//# sourceMappingURL=RawDataProvider.js.map |
@@ -27,3 +27,3 @@ "use strict"; | ||
tap.test('creating the API should work', (t) => { | ||
api = new Api_1.Api('1.0') | ||
api = new Api_1.Api({ name: 'test-service', version: '1.0' }) | ||
.edge(studentEdge) | ||
@@ -30,0 +30,0 @@ .edge(classEdge) |
@@ -26,3 +26,3 @@ "use strict"; | ||
tap.test('creating the API should work', (t) => { | ||
api = new Api_1.Api('1.0') | ||
api = new Api_1.Api({ name: 'test-service', version: '1.0' }) | ||
.edge(studentEdge) | ||
@@ -29,0 +29,0 @@ .edge(classEdge) |
@@ -58,3 +58,3 @@ "use strict"; | ||
const collectionRelation = new OneToManyRelation_1.OneToManyRelation(edge, relatedCollectionEdge); | ||
const parser = new ApiRequestParser_1.ApiRequestPathParser(new Api_1.Api('1.0') | ||
const parser = new ApiRequestParser_1.ApiRequestPathParser(new Api_1.Api({ name: 'test-service', version: '1.0' }) | ||
.edge(edge) | ||
@@ -165,3 +165,3 @@ .edge(relatedEdge) | ||
}; | ||
const badParser = new ApiRequestParser_1.ApiRequestPathParser(new Api_1.Api('1.0') | ||
const badParser = new ApiRequestParser_1.ApiRequestPathParser(new Api_1.Api({ name: 'test-service', version: '1.0' }) | ||
.edge(edge) | ||
@@ -174,3 +174,3 @@ .edge(relatedEdge) | ||
tap.test('request parser should work too', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const requestParser = new ApiRequestParser_1.ApiRequestParser(new Api_1.Api('1.0')); | ||
const requestParser = new ApiRequestParser_1.ApiRequestParser(new Api_1.Api({ name: 'test-service', version: '1.0' })); | ||
const request = yield requestParser.parse([]); | ||
@@ -177,0 +177,0 @@ t.equal(request.path.segments.length, 0); |
@@ -1,2 +0,3 @@ | ||
export {ApiEdgeDefinition, ApiEdge, ApiEdgeMetadata} from "./src/edge/ApiEdgeDefinition"; | ||
export {ApiEdgeDefinition, ApiEdge} from "./src/edge/ApiEdgeDefinition"; | ||
export {ApiEdgeMetadata} from "./src/edge/ApiEdgeMetadata"; | ||
export {ExternalApiEdge, ExternalApiProvider} from "./src/edge/ExternalApiEdge"; | ||
@@ -9,3 +10,3 @@ export {ApiEdgeQueryType} from "./src/edge/ApiEdgeQueryType"; | ||
export {ApiEdgeQuery} from "./src/edge/ApiEdgeQuery"; | ||
export {ApiEdgeMethod, ApiEdgeMethodScope} from "./src/edge/ApiEdgeMethod"; | ||
export {ApiEdgeMethod, ApiEdgeMethodScope, ApiEdgeMethodOutput} from "./src/edge/ApiEdgeMethod"; | ||
export {ApiEdgeError} from "./src/query/ApiEdgeError"; | ||
@@ -36,2 +37,2 @@ | ||
export {Api, ApiInfo, ApiMetadata} from "./src/Api"; | ||
export {Api, ApiInfo, ApiMetadata} from "./src/Api"; |
{ | ||
"name": "api-core", | ||
"version": "0.26.5", | ||
"version": "3.0.0", | ||
"description": "Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels", | ||
@@ -64,2 +64,2 @@ "main": "dist/index.js", | ||
} | ||
} | ||
} |
@@ -150,7 +150,7 @@ ### API Core | ||
const api10 | ||
= new Api('1.0') | ||
= new Api({name: 'test-service', version: '1.0'}) | ||
.edge(studentEdge); | ||
const api11 | ||
= new Api('1.1') | ||
= new Api({name: 'test-service', version: '1.1'}) | ||
.edge(studentEdge) | ||
@@ -157,0 +157,0 @@ .edge(classEdge) |
@@ -1,2 +0,3 @@ | ||
import {ApiEdgeDefinition, ApiEdgeMetadata} from "./edge/ApiEdgeDefinition"; | ||
import {ApiEdgeDefinition} from "./edge/ApiEdgeDefinition"; | ||
import {ApiEdgeMetadata} from "./edge/ApiEdgeMetadata"; | ||
import {ApiRequestParser} from "./request/ApiRequestParser"; | ||
@@ -29,3 +30,2 @@ import {ApiQueryBuilder} from "./query/ApiQueryBuilder"; | ||
export interface ApiMetadata { | ||
'api-core': string | ||
info: ApiInfo | ||
@@ -35,4 +35,10 @@ version: string | ||
relations: ExportedApiEdgeRelation[] | ||
services: ApiService[] | ||
} | ||
export interface ApiService { | ||
name: string | ||
version: string | ||
} | ||
export class Api { | ||
@@ -44,3 +50,3 @@ static defaultIdPostfix: string = "Id"; | ||
info?: ApiInfo; | ||
version: string; | ||
service: ApiService; | ||
@@ -54,4 +60,4 @@ edges: ApiEdgeDefinition[] = []; | ||
constructor(version: string, ...edges: ApiEdgeDefinition[]) { | ||
this.version = version; | ||
constructor(service: ApiService, ...edges: ApiEdgeDefinition[]) { | ||
this.service = service; | ||
this.edges = edges; | ||
@@ -125,5 +131,5 @@ this.parser = new ApiRequestParser(this); | ||
return { | ||
'api-core': pkg.version, | ||
info: this.info || { title: 'API' }, | ||
version: this.version, | ||
version: pkg.version, | ||
services: [ this.service ], | ||
edges: this.edges | ||
@@ -138,3 +144,3 @@ .filter(edge => !edge.external) | ||
static async fromMetadata(metadata: ApiMetadata): Promise<Api> { | ||
const api = new Api(metadata.version); | ||
const api = new Api(metadata.services[0] || {}); | ||
api.info = metadata.info; | ||
@@ -144,3 +150,3 @@ | ||
//if(edge.external) continue; -- TODO | ||
api.edge(new ExternalApiEdge(edge)) | ||
api.edge(new ExternalApiEdge(edge, api)) | ||
} | ||
@@ -161,2 +167,5 @@ | ||
private extension: { [key: string]: any } = {}; | ||
get = (key: string) => this.extension[key]; | ||
set = (key: string, value: any) => this.extension[key] = value; | ||
} |
@@ -13,20 +13,4 @@ import {ApiEdgeRelation} from "../relations/ApiEdgeRelation"; | ||
import {ApiEdgeQuery} from "./ApiEdgeQuery"; | ||
import {ApiEdgeMetadata} from "./ApiEdgeMetadata"; | ||
export interface ApiEdgeMetadata { | ||
name: string; | ||
pluralName: string; | ||
idField: string; | ||
fields: string[]; | ||
methods: { name: string, type: ApiRequestType, parameters: string[] }[]; | ||
typings?: { [key: string]: any }; | ||
allowGet: boolean; | ||
allowList: boolean; | ||
allowCreate: boolean; | ||
allowUpdate: boolean; | ||
allowPatch: boolean; | ||
allowRemove: boolean; | ||
allowExists: boolean; | ||
external: boolean; | ||
} | ||
export interface ApiEdgeDefinition { | ||
@@ -33,0 +17,0 @@ name: string; |
@@ -31,2 +31,3 @@ import {ApiEdgeQueryFilter, ApiEdgeQueryFilterType, ExportedApiEdgeQueryFilter} from "./ApiEdgeQueryFilter"; | ||
identity: any; | ||
method: string; | ||
@@ -33,0 +34,0 @@ clone = () => { |
@@ -68,3 +68,3 @@ const parse = require('obj-parse'), | ||
let output: string[] = []; | ||
fields.forEach((field: string) => { | ||
for (const field of fields) { | ||
const transformedFields = this.fieldMatrix[field]; | ||
@@ -74,4 +74,9 @@ if(transformedFields) { | ||
} | ||
else output.push(field) | ||
}); | ||
else { | ||
if (this.renameMatrix[field]) | ||
output.push(this.renameMatrix[field]); | ||
else | ||
output.push(field); | ||
} | ||
} | ||
return output | ||
@@ -167,3 +172,3 @@ }; | ||
schemaField | ||
); | ||
) | ||
} | ||
@@ -190,2 +195,2 @@ } | ||
} | ||
} | ||
} |
@@ -8,8 +8,11 @@ import {ApiEdgeQueryContext} from "./ApiEdgeQueryContext"; | ||
import {ApiQueryScope} from "../query/ApiQuery"; | ||
import {Api} from "../Api"; | ||
export abstract class ExternalApiProvider { | ||
protected metadata: any; | ||
protected api: Api; | ||
protected constructor(metadata: any) { | ||
this.metadata = metadata | ||
protected constructor(metadata: any, api: Api) { | ||
this.metadata = metadata; | ||
this.api = api; | ||
} | ||
@@ -30,3 +33,3 @@ | ||
await this.prepare(); | ||
return new ExternalApiEdge(this.metadata, this) | ||
return new ExternalApiEdge(this.metadata, this.api, this) | ||
} | ||
@@ -36,5 +39,7 @@ } | ||
export class ExternalApiEdge extends ApiEdge { | ||
constructor(metadata: any, provider?: ExternalApiProvider) { | ||
constructor(metadata: any, api: Api, provider?: ExternalApiProvider) { | ||
super(); | ||
this.api = api; | ||
this.name = metadata.name; | ||
@@ -70,3 +75,4 @@ this.pluralName = metadata.pluralName; | ||
this.url = metadata.url; | ||
if(provider) this.provider = provider; | ||
if(provider) | ||
this.provider = provider; | ||
} | ||
@@ -76,2 +82,3 @@ | ||
provider: ExternalApiProvider; | ||
api: Api; | ||
@@ -105,2 +112,2 @@ getEntry = (context: ApiEdgeQueryContext): Promise<ApiEdgeQueryResponse> => { | ||
}; | ||
} | ||
} |
@@ -186,2 +186,3 @@ import {ApiQuery, ApiQueryScope, QueryStep} from "./ApiQuery"; | ||
this.query.context = scope.context; | ||
this.query.context.populatedRelations = []; // prevent embed step to run on external query --- it shall only run at the original executor | ||
this.query.context.identity = scope.identity; | ||
@@ -212,2 +213,3 @@ | ||
debug(`[${scope.query.id}]`, this.inspect()); | ||
scope.context.method = this.method.name; | ||
@@ -520,7 +522,7 @@ this.method.execute(scope) | ||
private addMethodActions(triggerKind: ApiEdgeActionTriggerKind, | ||
query: ApiQuery, | ||
method: ApiEdgeMethod, | ||
queryType: ApiEdgeQueryType, | ||
edge: ApiEdgeDefinition, | ||
output: boolean = false) { | ||
query: ApiQuery, | ||
method: ApiEdgeMethod, | ||
queryType: ApiEdgeQueryType, | ||
edge: ApiEdgeDefinition, | ||
output: boolean = false) { | ||
const trigger = ApiEdgeActionTrigger.Method; | ||
@@ -527,0 +529,0 @@ |
@@ -25,3 +25,3 @@ import {ApiEdgeError} from "../src/query/ApiEdgeError"; | ||
tap.test('creating the API should work', (t: any) => { | ||
api = new Api('1.0') | ||
api = new Api({name: 'test-service', version: '1.0'}) | ||
.edge(studentEdge) | ||
@@ -28,0 +28,0 @@ .edge(classEdge) |
@@ -24,3 +24,3 @@ const tap = require('tap'); | ||
tap.test('creating the API should work', (t: any) => { | ||
api = new Api('1.0') | ||
api = new Api({name: 'test-service', version: '1.0'}) | ||
.edge(studentEdge) | ||
@@ -27,0 +27,0 @@ .edge(classEdge) |
@@ -57,3 +57,3 @@ const tap = require('tap'); | ||
const parser = new ApiRequestPathParser( | ||
new Api('1.0') | ||
new Api({name: 'test-service', version: '1.0'}) | ||
.edge(edge) | ||
@@ -197,4 +197,4 @@ .edge(relatedEdge) | ||
const badParser = new ApiRequestPathParser( | ||
new Api('1.0') | ||
.edge(edge) | ||
new Api({name: 'test-service', version: '1.0'}) | ||
.edge(edge) | ||
.edge(relatedEdge) | ||
@@ -209,6 +209,6 @@ .relation(new unsupportedRelation) | ||
tap.test('request parser should work too', async (t: any) => { | ||
const requestParser = new ApiRequestParser(new Api('1.0')); | ||
const requestParser = new ApiRequestParser(new Api({name: 'test-service', version: '1.0'})); | ||
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
712103
180
8663
0