Comparing version 4.5.0 to 5.0.0
@@ -149,3 +149,3 @@ "use strict"; | ||
__decorate([ | ||
typeorm_1.OneToMany(function (type) { return presentation_1.Presentation; }, function (presentation) { return presentation.audience; }), | ||
typeorm_1.ManyToMany(function (type) { return presentation_1.Presentation; }, function (presentation) { return presentation.audience; }), | ||
__metadata("design:type", Array) | ||
@@ -152,0 +152,0 @@ ], Identity.prototype, "receivedPresentations", void 0); |
@@ -11,3 +11,3 @@ import { BaseEntity } from 'typeorm'; | ||
issuer: Identity; | ||
audience: Identity; | ||
audience: Identity[]; | ||
id?: String; | ||
@@ -14,0 +14,0 @@ issuanceDate: Date; |
@@ -63,7 +63,8 @@ "use strict"; | ||
__decorate([ | ||
typeorm_1.ManyToOne(function (type) { return identity_1.Identity; }, function (identity) { return identity.receivedPresentations; }, { | ||
typeorm_1.ManyToMany(function (type) { return identity_1.Identity; }, function (identity) { return identity.receivedPresentations; }, { | ||
cascade: ['insert'], | ||
eager: true, | ||
}), | ||
__metadata("design:type", identity_1.Identity) | ||
typeorm_1.JoinTable(), | ||
__metadata("design:type", Array) | ||
], Presentation.prototype, "audience", void 0); | ||
@@ -70,0 +71,0 @@ __decorate([ |
@@ -51,4 +51,4 @@ import { Agent } from '../agent'; | ||
}, ctx: Context) => Promise<Message>; | ||
messages: (_: any, args: FindArgs, ctx: Context) => Promise<Message[]>; | ||
messagesCount: (_: any, args: FindArgs, ctx: Context) => Promise<any>; | ||
messages: (_: any, args: FindArgs, ctx: Context) => Promise<any[]>; | ||
messagesCount: (_: any, args: FindArgs, ctx: Context) => Promise<number>; | ||
presentation: (_: any, { hash }: { | ||
@@ -58,3 +58,3 @@ hash: any; | ||
presentations: (_: any, args: FindArgs, ctx: Context) => Promise<Presentation[]>; | ||
presentationsCount: (_: any, args: FindArgs, ctx: Context) => Promise<any>; | ||
presentationsCount: (_: any, args: FindArgs, ctx: Context) => Promise<number>; | ||
credential: (_: any, { hash }: { | ||
@@ -64,3 +64,3 @@ hash: any; | ||
credentials: (_: any, args: FindArgs, ctx: Context) => Promise<Credential[]>; | ||
credentialsCount: (_: any, args: FindArgs, ctx: Context) => Promise<any>; | ||
credentialsCount: (_: any, args: FindArgs, ctx: Context) => Promise<number>; | ||
claim: (_: any, { hash }: { | ||
@@ -70,3 +70,3 @@ hash: any; | ||
claims: (_: any, args: FindArgs, ctx: Context) => Promise<Claim[]>; | ||
claimsCount: (_: any, args: FindArgs, ctx: Context) => Promise<any>; | ||
claimsCount: (_: any, args: FindArgs, ctx: Context) => Promise<number>; | ||
}; | ||
@@ -93,3 +93,3 @@ Identity: { | ||
}; | ||
export declare const typeDefs = "\n enum WhereOperation {\n Not\n LessThan\n LessThanOrEqual\n MoreThan\n MoreThanOrEqual\n Equal\n Like\n Between\n In\n Any\n IsNull\n }\n\n enum OrderDirection {\n ASC\n DESC\n }\n\n enum MessagesColumns {\n saveDate\n updateDate\n createdAt\n expiresAt\n threadId\n type\n replyTo\n replyUrl\n from\n to\n }\n\n input MessagesWhere {\n column: MessagesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input MessagesOrder {\n column: MessagesColumns!\n direction: OrderDirection!\n }\n\n input MessagesInput {\n where: [MessagesWhere]\n order: [MessagesOrder]\n take: Int\n skip: Int\n }\n\n\n\n enum IdentitiesColumns {\n saveDate\n updateDate\n did\n provider\n }\n\n input IdentitiesWhere {\n column: IdentitiesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input IdentitiesOrder {\n column: IdentitiesColumns!\n direction: OrderDirection!\n }\n\n input IdentitiesInput {\n where: [IdentitiesWhere]\n order: [IdentitiesOrder]\n take: Int\n skip: Int\n }\n\n\n enum PresentationsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n audience\n }\n\n input PresentationsWhere {\n column: PresentationsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input PresentationsOrder {\n column: PresentationsColumns!\n direction: OrderDirection!\n }\n\n input PresentationsInput {\n where: [PresentationsWhere]\n order: [PresentationsOrder]\n take: Int\n skip: Int\n }\n\n\n enum CredentialsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n subject\n }\n\n input CredentialsWhere {\n column: CredentialsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input CredentialsOrder {\n column: CredentialsColumns!\n direction: OrderDirection!\n }\n\n input CredentialsInput {\n where: [CredentialsWhere]\n order: [CredentialsOrder]\n take: Int\n skip: Int\n }\n\n\n enum ClaimsColumns {\n issuanceDate\n expirationDate\n context\n credentialType\n type\n value\n issuer\n subject\n }\n\n input ClaimsWhere {\n column: ClaimsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input ClaimsOrder {\n column: ClaimsColumns!\n direction: OrderDirection!\n }\n\n input ClaimsInput {\n where: [ClaimsWhere]\n order: [ClaimsOrder]\n take: Int\n skip: Int\n }\n\n\n\n extend type Query {\n identity(did: String!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n messagesCount(input: MessagesInput): Int\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n presentationsCount(input: PresentationsInput): Int\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n credentialsCount(input: CredentialsInput): Int\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n claimsCount(input: ClaimsInput): Int\n }\n\n input MetaDataInput {\n type: String!\n value: String\n }\n extend type Mutation {\n handleMessage(raw: String!, meta: [MetaDataInput], save: Boolean = true): Message\n }\n\n\n extend type Identity {\n shortDid: String!\n latestClaimValue(type: String): String\n saveDate: Date!\n updateDate: Date!\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n audience: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n subject: Identity\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity\n credential: Credential!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n credentialType: [String]\n type: String!\n value: String!\n isObj: Boolean\n } \n"; | ||
export declare const typeDefs = "\n enum WhereOperation {\n Not\n LessThan\n LessThanOrEqual\n MoreThan\n MoreThanOrEqual\n Equal\n Like\n Between\n In\n Any\n IsNull\n }\n\n enum OrderDirection {\n ASC\n DESC\n }\n\n enum MessagesColumns {\n saveDate\n updateDate\n createdAt\n expiresAt\n threadId\n type\n replyTo\n replyUrl\n from\n to\n }\n\n input MessagesWhere {\n column: MessagesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input MessagesOrder {\n column: MessagesColumns!\n direction: OrderDirection!\n }\n\n input MessagesInput {\n where: [MessagesWhere]\n order: [MessagesOrder]\n take: Int\n skip: Int\n }\n\n\n\n enum IdentitiesColumns {\n saveDate\n updateDate\n did\n provider\n }\n\n input IdentitiesWhere {\n column: IdentitiesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input IdentitiesOrder {\n column: IdentitiesColumns!\n direction: OrderDirection!\n }\n\n input IdentitiesInput {\n where: [IdentitiesWhere]\n order: [IdentitiesOrder]\n take: Int\n skip: Int\n }\n\n\n enum PresentationsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n audience\n }\n\n input PresentationsWhere {\n column: PresentationsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input PresentationsOrder {\n column: PresentationsColumns!\n direction: OrderDirection!\n }\n\n input PresentationsInput {\n where: [PresentationsWhere]\n order: [PresentationsOrder]\n take: Int\n skip: Int\n }\n\n\n enum CredentialsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n subject\n }\n\n input CredentialsWhere {\n column: CredentialsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input CredentialsOrder {\n column: CredentialsColumns!\n direction: OrderDirection!\n }\n\n input CredentialsInput {\n where: [CredentialsWhere]\n order: [CredentialsOrder]\n take: Int\n skip: Int\n }\n\n\n enum ClaimsColumns {\n issuanceDate\n expirationDate\n context\n credentialType\n type\n value\n issuer\n subject\n }\n\n input ClaimsWhere {\n column: ClaimsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input ClaimsOrder {\n column: ClaimsColumns!\n direction: OrderDirection!\n }\n\n input ClaimsInput {\n where: [ClaimsWhere]\n order: [ClaimsOrder]\n take: Int\n skip: Int\n }\n\n\n\n extend type Query {\n identity(did: String!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n messagesCount(input: MessagesInput): Int\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n presentationsCount(input: PresentationsInput): Int\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n credentialsCount(input: CredentialsInput): Int\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n claimsCount(input: ClaimsInput): Int\n }\n\n input MetaDataInput {\n type: String!\n value: String\n }\n extend type Mutation {\n handleMessage(raw: String!, meta: [MetaDataInput], save: Boolean = true): Message\n }\n\n\n extend type Identity {\n shortDid: String!\n latestClaimValue(type: String): String\n saveDate: Date!\n updateDate: Date!\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n audience: [Identity]!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n subject: Identity\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity\n credential: Credential!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n credentialType: [String]\n type: String!\n value: String!\n isObj: Boolean\n } \n"; | ||
//# sourceMappingURL=graphql-core.d.ts.map |
@@ -49,2 +49,18 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -68,2 +84,38 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
var identity_1 = require("../entities/identity"); | ||
function opToSQL(item) { | ||
var _a, _b; | ||
switch (item.op) { | ||
case 'IsNull': | ||
return ['IS NULL', '']; | ||
case 'Like': | ||
if (((_a = item.value) === null || _a === void 0 ? void 0 : _a.length) != 1) | ||
throw Error('Operation Equal requires one value'); | ||
return ['LIKE :value', item.value[0]]; | ||
case 'Equal': | ||
if (((_b = item.value) === null || _b === void 0 ? void 0 : _b.length) != 1) | ||
throw Error('Operation Equal requires one value'); | ||
return ['= :value', item.value[0]]; | ||
case 'Any': | ||
case 'Between': | ||
case 'LessThan': | ||
case 'LessThanOrEqual': | ||
case 'MoreThan': | ||
case 'MoreThanOrEqual': | ||
throw new Error(item.op + " not compatable with DID argument"); | ||
case 'In': | ||
default: | ||
return ['IN (:...value)', item.value]; | ||
} | ||
} | ||
function addAudienceQuery(input, qb) { | ||
if (!Array.isArray(input.where)) { | ||
return qb; | ||
} | ||
var audienceWhere = input.where.find(function (item) { return item.column === "audience"; }); | ||
if (!audienceWhere) { | ||
return qb; | ||
} | ||
var _a = __read(opToSQL(audienceWhere), 2), op = _a[0], value = _a[1]; | ||
return qb.andWhere("audience.did " + op, { value: value }); | ||
} | ||
function createWhereObject(input) { | ||
@@ -77,2 +129,5 @@ var e_1, _a; | ||
var item = _k.value; | ||
if (item.column === "audience") { | ||
continue; | ||
} | ||
switch (item.op) { | ||
@@ -127,3 +182,2 @@ case 'Any': | ||
} | ||
return where; | ||
} | ||
@@ -138,2 +192,3 @@ } | ||
} | ||
return where; | ||
} | ||
@@ -151,3 +206,3 @@ } | ||
var item = _c.value; | ||
qb = qb.orderBy(qb.connection.driver.escape(tablename) + "." + qb.connection.driver.escape(item.column), item.direction); | ||
qb = qb.orderBy(qb.connection.driver.escape("" + item.column), item.direction); | ||
} | ||
@@ -174,3 +229,3 @@ } | ||
} | ||
var messages = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var messagesQuery = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
@@ -197,34 +252,23 @@ return __generator(this, function (_a) { | ||
} | ||
return [2 /*return*/, qb.getMany()]; | ||
return [2 /*return*/, qb]; | ||
} | ||
}); | ||
}); }; | ||
var messages = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, messagesQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getMany()]; | ||
} | ||
}); | ||
}); }; | ||
var messagesCount = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
where = createWhereObject(args.input); | ||
return [4 /*yield*/, ctx.agent.dbConnection]; | ||
case 1: | ||
qb = (_a.sent()) | ||
.getRepository(message_1.Message) | ||
.createQueryBuilder('message') | ||
.leftJoinAndSelect('message.from', 'from') | ||
.leftJoinAndSelect('message.to', 'to') | ||
.where(where); | ||
qb = decorateQB(qb, 'message', args.input); | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('message.to = :ident', { ident: ctx.authenticatedDid }).orWhere('message.from = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}); | ||
})); | ||
} | ||
return [4 /*yield*/, qb.select('COUNT(message.id)').getRawOne()]; | ||
case 2: return [2 /*return*/, (_a.sent())['COUNT("message"."id")']]; | ||
case 0: return [4 /*yield*/, messagesQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getCount()]; | ||
} | ||
}); | ||
}); }; | ||
var presentations = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var presentationsQuery = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
@@ -244,5 +288,6 @@ return __generator(this, function (_a) { | ||
qb = decorateQB(qb, 'presentation', args.input); | ||
qb = addAudienceQuery(args.input, qb); | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('presentation.audience = :ident', { | ||
qb.where('audience.did = :ident', { | ||
ident: ctx.authenticatedDid, | ||
@@ -252,33 +297,23 @@ }).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }); | ||
} | ||
return [2 /*return*/, qb.getMany()]; | ||
return [2 /*return*/, qb]; | ||
} | ||
}); | ||
}); }; | ||
var presentations = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, presentationsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getMany()]; | ||
} | ||
}); | ||
}); }; | ||
var presentationsCount = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
where = createWhereObject(args.input); | ||
return [4 /*yield*/, ctx.agent.dbConnection]; | ||
case 1: | ||
qb = (_a.sent()) | ||
.getRepository(presentation_1.Presentation) | ||
.createQueryBuilder('presentation') | ||
.leftJoinAndSelect('presentation.issuer', 'issuer') | ||
.leftJoinAndSelect('presentation.audience', 'audience') | ||
.where(where); | ||
qb = decorateQB(qb, 'presentation', args.input); | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('presentation.audience = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }); | ||
})); | ||
} | ||
return [2 /*return*/, qb.select('COUNT(presentation.hash)').getRawOne()]; | ||
case 0: return [4 /*yield*/, presentationsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getCount()]; | ||
} | ||
}); | ||
}); }; | ||
var credentials = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var credentialsQuery = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
@@ -305,33 +340,23 @@ return __generator(this, function (_a) { | ||
} | ||
return [2 /*return*/, qb.getMany()]; | ||
return [2 /*return*/, qb]; | ||
} | ||
}); | ||
}); }; | ||
var credentials = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, credentialsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getMany()]; | ||
} | ||
}); | ||
}); }; | ||
var credentialsCount = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
where = createWhereObject(args.input); | ||
return [4 /*yield*/, ctx.agent.dbConnection]; | ||
case 1: | ||
qb = (_a.sent()) | ||
.getRepository(credential_1.Credential) | ||
.createQueryBuilder('credential') | ||
.leftJoinAndSelect('credential.issuer', 'issuer') | ||
.leftJoinAndSelect('credential.subject', 'subject') | ||
.where(where); | ||
qb = decorateQB(qb, 'credential', args.input); | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('credential.issuer = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}); | ||
})); | ||
} | ||
return [2 /*return*/, qb.select('COUNT(credential.hash)').getRawOne()]; | ||
case 0: return [4 /*yield*/, credentialsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getCount()]; | ||
} | ||
}); | ||
}); }; | ||
var claims = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var claimsQuery = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
@@ -359,30 +384,19 @@ return __generator(this, function (_a) { | ||
} | ||
return [2 /*return*/, qb.getMany()]; | ||
return [2 /*return*/, qb]; | ||
} | ||
}); | ||
}); }; | ||
var claims = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, claimsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getMany()]; | ||
} | ||
}); | ||
}); }; | ||
var claimsCount = function (_, args, ctx) { return __awaiter(void 0, void 0, void 0, function () { | ||
var where, qb; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
where = createWhereObject(args.input); | ||
return [4 /*yield*/, ctx.agent.dbConnection]; | ||
case 1: | ||
qb = (_a.sent()) | ||
.getRepository(claim_1.Claim) | ||
.createQueryBuilder('claim') | ||
.leftJoinAndSelect('claim.issuer', 'issuer') | ||
.leftJoinAndSelect('claim.subject', 'subject') | ||
.where(where); | ||
qb = decorateQB(qb, 'claim', args.input); | ||
qb = qb.leftJoinAndSelect('claim.credential', 'credential'); | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('claim.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('claim.issuer = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}); | ||
})); | ||
} | ||
return [2 /*return*/, qb.select('COUNT(claim.hash)').getRawOne()]; | ||
case 0: return [4 /*yield*/, claimsQuery(_, args, ctx)]; | ||
case 1: return [2 /*return*/, (_a.sent()).getCount()]; | ||
} | ||
@@ -477,3 +491,3 @@ }); | ||
qb = qb.andWhere(new typeorm_1.Brackets(function (qb) { | ||
qb.where('presentation.audience = :ident', { | ||
qb.where('audience.did = :ident', { | ||
ident: ctx.authenticatedDid, | ||
@@ -680,3 +694,3 @@ }).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }); | ||
}; | ||
exports.typeDefs = "\n enum WhereOperation {\n Not\n LessThan\n LessThanOrEqual\n MoreThan\n MoreThanOrEqual\n Equal\n Like\n Between\n In\n Any\n IsNull\n }\n\n enum OrderDirection {\n ASC\n DESC\n }\n\n enum MessagesColumns {\n saveDate\n updateDate\n createdAt\n expiresAt\n threadId\n type\n replyTo\n replyUrl\n from\n to\n }\n\n input MessagesWhere {\n column: MessagesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input MessagesOrder {\n column: MessagesColumns!\n direction: OrderDirection!\n }\n\n input MessagesInput {\n where: [MessagesWhere]\n order: [MessagesOrder]\n take: Int\n skip: Int\n }\n\n\n\n enum IdentitiesColumns {\n saveDate\n updateDate\n did\n provider\n }\n\n input IdentitiesWhere {\n column: IdentitiesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input IdentitiesOrder {\n column: IdentitiesColumns!\n direction: OrderDirection!\n }\n\n input IdentitiesInput {\n where: [IdentitiesWhere]\n order: [IdentitiesOrder]\n take: Int\n skip: Int\n }\n\n\n enum PresentationsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n audience\n }\n\n input PresentationsWhere {\n column: PresentationsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input PresentationsOrder {\n column: PresentationsColumns!\n direction: OrderDirection!\n }\n\n input PresentationsInput {\n where: [PresentationsWhere]\n order: [PresentationsOrder]\n take: Int\n skip: Int\n }\n\n\n enum CredentialsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n subject\n }\n\n input CredentialsWhere {\n column: CredentialsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input CredentialsOrder {\n column: CredentialsColumns!\n direction: OrderDirection!\n }\n\n input CredentialsInput {\n where: [CredentialsWhere]\n order: [CredentialsOrder]\n take: Int\n skip: Int\n }\n\n\n enum ClaimsColumns {\n issuanceDate\n expirationDate\n context\n credentialType\n type\n value\n issuer\n subject\n }\n\n input ClaimsWhere {\n column: ClaimsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input ClaimsOrder {\n column: ClaimsColumns!\n direction: OrderDirection!\n }\n\n input ClaimsInput {\n where: [ClaimsWhere]\n order: [ClaimsOrder]\n take: Int\n skip: Int\n }\n\n\n\n extend type Query {\n identity(did: String!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n messagesCount(input: MessagesInput): Int\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n presentationsCount(input: PresentationsInput): Int\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n credentialsCount(input: CredentialsInput): Int\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n claimsCount(input: ClaimsInput): Int\n }\n\n input MetaDataInput {\n type: String!\n value: String\n }\n extend type Mutation {\n handleMessage(raw: String!, meta: [MetaDataInput], save: Boolean = true): Message\n }\n\n\n extend type Identity {\n shortDid: String!\n latestClaimValue(type: String): String\n saveDate: Date!\n updateDate: Date!\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n audience: Identity!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n subject: Identity\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity\n credential: Credential!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n credentialType: [String]\n type: String!\n value: String!\n isObj: Boolean\n } \n"; | ||
exports.typeDefs = "\n enum WhereOperation {\n Not\n LessThan\n LessThanOrEqual\n MoreThan\n MoreThanOrEqual\n Equal\n Like\n Between\n In\n Any\n IsNull\n }\n\n enum OrderDirection {\n ASC\n DESC\n }\n\n enum MessagesColumns {\n saveDate\n updateDate\n createdAt\n expiresAt\n threadId\n type\n replyTo\n replyUrl\n from\n to\n }\n\n input MessagesWhere {\n column: MessagesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input MessagesOrder {\n column: MessagesColumns!\n direction: OrderDirection!\n }\n\n input MessagesInput {\n where: [MessagesWhere]\n order: [MessagesOrder]\n take: Int\n skip: Int\n }\n\n\n\n enum IdentitiesColumns {\n saveDate\n updateDate\n did\n provider\n }\n\n input IdentitiesWhere {\n column: IdentitiesColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input IdentitiesOrder {\n column: IdentitiesColumns!\n direction: OrderDirection!\n }\n\n input IdentitiesInput {\n where: [IdentitiesWhere]\n order: [IdentitiesOrder]\n take: Int\n skip: Int\n }\n\n\n enum PresentationsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n audience\n }\n\n input PresentationsWhere {\n column: PresentationsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input PresentationsOrder {\n column: PresentationsColumns!\n direction: OrderDirection!\n }\n\n input PresentationsInput {\n where: [PresentationsWhere]\n order: [PresentationsOrder]\n take: Int\n skip: Int\n }\n\n\n enum CredentialsColumns {\n id\n issuanceDate\n expirationDate\n context\n type\n issuer\n subject\n }\n\n input CredentialsWhere {\n column: CredentialsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input CredentialsOrder {\n column: CredentialsColumns!\n direction: OrderDirection!\n }\n\n input CredentialsInput {\n where: [CredentialsWhere]\n order: [CredentialsOrder]\n take: Int\n skip: Int\n }\n\n\n enum ClaimsColumns {\n issuanceDate\n expirationDate\n context\n credentialType\n type\n value\n issuer\n subject\n }\n\n input ClaimsWhere {\n column: ClaimsColumns!\n value: [String]\n not: Boolean\n op: WhereOperation\n }\n\n input ClaimsOrder {\n column: ClaimsColumns!\n direction: OrderDirection!\n }\n\n input ClaimsInput {\n where: [ClaimsWhere]\n order: [ClaimsOrder]\n take: Int\n skip: Int\n }\n\n\n\n extend type Query {\n identity(did: String!): Identity\n identities(input: IdentitiesInput): [Identity]\n message(id: ID!): Message\n messages(input: MessagesInput): [Message]\n messagesCount(input: MessagesInput): Int\n presentation(hash: ID!): Presentation\n presentations(input: PresentationsInput): [Presentation]\n presentationsCount(input: PresentationsInput): Int\n credential(hash: ID!): Credential\n credentials(input: CredentialsInput): [Credential]\n credentialsCount(input: CredentialsInput): Int\n claim(hash: ID!): Claim\n claims(input: ClaimsInput): [Claim]\n claimsCount(input: ClaimsInput): Int\n }\n\n input MetaDataInput {\n type: String!\n value: String\n }\n extend type Mutation {\n handleMessage(raw: String!, meta: [MetaDataInput], save: Boolean = true): Message\n }\n\n\n extend type Identity {\n shortDid: String!\n latestClaimValue(type: String): String\n saveDate: Date!\n updateDate: Date!\n }\n\n scalar Object\n scalar Date\n \n type Message {\n id: ID!\n saveDate: Date!\n updateDate: Date!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: Identity\n to: Identity\n metaData: [MetaData]\n presentations: [Presentation]\n credentials: [Credential]\n }\n\n type MetaData {\n type: String!\n value: String\n }\n\n type Presentation {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n audience: [Identity]!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentials: [Credential]\n messages: [Message]\n }\n \n type Credential {\n hash: ID!\n id: String\n raw: String!\n issuer: Identity!\n subject: Identity\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n type: [String]\n credentialSubject: Object\n claims: [Claim]\n presentations: [Presentation]\n messages: [Message]\n }\n\n type Claim {\n hash: ID!\n issuer: Identity!\n subject: Identity\n credential: Credential!\n issuanceDate: Date!\n expirationDate: Date\n context: [String]\n credentialType: [String]\n type: String!\n value: String!\n isObj: Boolean\n } \n"; | ||
//# sourceMappingURL=graphql-core.js.map |
@@ -25,4 +25,4 @@ declare const Gql: { | ||
}, ctx: import("./graphql-core").Context) => Promise<import("..").Message>; | ||
messages: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<import("..").Message[]>; | ||
messagesCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<any>; | ||
messages: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<any[]>; | ||
messagesCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<number>; | ||
presentation: (_: any, { hash }: { | ||
@@ -32,3 +32,3 @@ hash: any; | ||
presentations: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<import("..").Presentation[]>; | ||
presentationsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<any>; | ||
presentationsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<number>; | ||
credential: (_: any, { hash }: { | ||
@@ -38,3 +38,3 @@ hash: any; | ||
credentials: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<import("..").Credential[]>; | ||
credentialsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<any>; | ||
credentialsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<number>; | ||
claim: (_: any, { hash }: { | ||
@@ -44,3 +44,3 @@ hash: any; | ||
claims: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<import("..").Claim[]>; | ||
claimsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<any>; | ||
claimsCount: (_: any, args: import("./graphql-core").FindArgs, ctx: import("./graphql-core").Context) => Promise<number>; | ||
}; | ||
@@ -47,0 +47,0 @@ Identity: { |
@@ -6,2 +6,24 @@ # Change Log | ||
# [5.0.0](https://github.com/uport-project/daf/compare/v4.5.0...v5.0.0) (2020-05-05) | ||
### Bug Fixes | ||
* fixes failing audience query tests ([40408dc](https://github.com/uport-project/daf/commit/40408dce03a3c23dff07c89f2455d89c60893ebf)) | ||
* Remove static Credential.credentialStatus ([f9a06af](https://github.com/uport-project/daf/commit/f9a06afcd01fc9e0452535d10d32158414490ea4)) | ||
### Features | ||
* Multiple audience dids ([eaa1a40](https://github.com/uport-project/daf/commit/eaa1a40d9d3728533be63660ad4cdef6bdbdeded)) | ||
### BREAKING CHANGES | ||
* DB Schema change | ||
# [4.5.0](https://github.com/uport-project/daf/compare/v4.4.0...v4.5.0) (2020-05-05) | ||
@@ -8,0 +30,0 @@ |
{ | ||
"name": "daf-core", | ||
"description": "DID Agent Framework Core", | ||
"version": "4.5.0", | ||
"version": "5.0.0", | ||
"main": "build/index.js", | ||
@@ -32,3 +32,3 @@ "types": "build/index.d.ts", | ||
"keywords": [], | ||
"gitHead": "9607061b72e9b234dce0ea421a333f8d7abaf321" | ||
"gitHead": "0598d89ace6a005d1053659a7865b5f5761bb636" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { createConnection, Connection, In } from 'typeorm' | ||
import { createConnection, Connection, In, Raw } from 'typeorm' | ||
import { Identity, Key, Message, Credential, Presentation, Claim } from '../index' | ||
@@ -82,2 +82,5 @@ import { Entities } from '../index' | ||
const id3 = new Identity() | ||
id3.did = 'did:test:333' | ||
const vc = new Credential() | ||
@@ -101,3 +104,3 @@ vc.issuer = id1 | ||
vp.issuer = id1 | ||
vp.audience = id2 | ||
vp.audience = [id2] | ||
vp.issuanceDate = new Date() | ||
@@ -109,2 +112,13 @@ vp.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323'] | ||
const vp2 = new Presentation() | ||
vp2.issuer = id1 | ||
vp2.audience = [id3] | ||
vp2.issuanceDate = new Date() | ||
vp2.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323'] | ||
vp2.type = ['VerifiablePresentation', 'PublicProfile', 'Specific'] | ||
vp2.raw = 'mockJWT' | ||
vp2.credentials = [vc] | ||
await vp2.save() | ||
const m = new Message() | ||
@@ -149,2 +163,9 @@ m.from = id1 | ||
expect(claims[0].value).toEqual('Alice') | ||
const presentations = await Presentation.find({ | ||
relations: ["audience"], | ||
where: Raw((alias) => `audience.did = "did:test:333"`) | ||
}) | ||
expect(presentations.length).toEqual(1) | ||
}) | ||
@@ -151,0 +172,0 @@ |
@@ -25,2 +25,5 @@ import { createConnection, Connection, In } from 'typeorm' | ||
const id4 = new Identity() | ||
id4.did = 'did:test:444' | ||
const vc = new Credential() | ||
@@ -44,3 +47,3 @@ vc.issuer = id1 | ||
vp.issuer = id1 | ||
vp.audience = id2 | ||
vp.audience = [id2] | ||
vp.issuanceDate = new Date() | ||
@@ -52,2 +55,11 @@ vp.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323'] | ||
const vp2 = new Presentation() | ||
vp2.issuer = id1 | ||
vp2.audience = [id2, id4] | ||
vp2.issuanceDate = new Date() | ||
vp2.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323'] | ||
vp2.type = ['VerifiablePresentation', 'PublicProfile'] | ||
vp2.raw = 'mockjwtwithmoreaudience' | ||
vp2.credentials = [vc] | ||
const m = new Message() | ||
@@ -81,2 +93,13 @@ m.from = id1 | ||
await m3.save() | ||
const m4 = new Message() | ||
m4.from = id1 | ||
m4.to = id2 | ||
m4.type = 'mock' | ||
m4.raw = 'mockmoreaudienct' | ||
m4.createdAt = new Date() | ||
m4.credentials = [vc] | ||
m4.presentations = [vp2] | ||
await m4.save() | ||
} | ||
@@ -115,2 +138,32 @@ | ||
test('search presentations by audience', async () => { | ||
const agent = makeAgent() | ||
const query: FindArgs = { | ||
input: { | ||
where: [ | ||
{ | ||
column: 'audience', | ||
value: ['did:test:444'], | ||
op: 'In', | ||
}, | ||
], | ||
}, | ||
} | ||
let presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent }) | ||
expect(presentations.length).toBe(1) | ||
// search when authenticated as the issuer | ||
let authenticatedDid = 'did:test:111' | ||
presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(1) | ||
// search when authenticated as another did | ||
authenticatedDid = 'did:test:333' | ||
presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(0) | ||
}) | ||
test('without auth it fetches all messages that match the query', async () => { | ||
@@ -131,3 +184,3 @@ const agent = makeAgent() | ||
const messages = await Gql.Core.resolvers.Query.messages({}, query, { agent }) | ||
expect(messages.length).toBe(3) | ||
expect(messages.length).toBe(4) | ||
}) | ||
@@ -152,3 +205,3 @@ | ||
const messages = await Gql.Core.resolvers.Query.messages({}, query, { agent, authenticatedDid }) | ||
expect(messages.length).toBe(2) | ||
expect(messages.length).toBe(3) | ||
}) | ||
@@ -171,3 +224,3 @@ | ||
const messagesCount = await Gql.Core.resolvers.Query.messagesCount({}, query, { agent }) | ||
expect(messagesCount).toBe(3) | ||
expect(messagesCount).toBe(4) | ||
const authenticatedDid = 'did:test:111' | ||
@@ -179,3 +232,3 @@ | ||
}) | ||
expect(messagesCount2).toBe(2) | ||
expect(messagesCount2).toBe(3) | ||
}) | ||
@@ -262,2 +315,37 @@ | ||
}) | ||
test('multiple audience members can retrieve a credential', async () => { | ||
const agent = makeAgent() | ||
const query: FindArgs = { | ||
input: { | ||
where: [ | ||
{ | ||
column: 'raw', | ||
value: ['mockjwtwithmoreaudience'], | ||
op: 'Equal', | ||
}, | ||
], | ||
}, | ||
} | ||
let authenticatedDid = 'did:test:111' | ||
let presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(1) | ||
authenticatedDid = 'did:test:222' | ||
presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(1) | ||
authenticatedDid = 'did:test:444' | ||
presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(1) | ||
authenticatedDid = 'did:test:333' | ||
presentations = await Gql.Core.resolvers.Query.presentations({}, query, { agent, authenticatedDid }) | ||
expect(presentations.length).toBe(0) | ||
}) | ||
}) |
@@ -7,2 +7,3 @@ import { | ||
OneToMany, | ||
ManyToMany, | ||
CreateDateColumn, | ||
@@ -59,3 +60,3 @@ UpdateDateColumn, | ||
@OneToMany( | ||
@ManyToMany( | ||
type => Presentation, | ||
@@ -62,0 +63,0 @@ presentation => presentation.audience, |
@@ -43,3 +43,3 @@ import { blake2bHex } from 'blakejs' | ||
@ManyToOne( | ||
@ManyToMany( | ||
type => Identity, | ||
@@ -52,3 +52,4 @@ identity => identity.receivedPresentations, | ||
) | ||
audience: Identity | ||
@JoinTable() | ||
audience: Identity[] | ||
@@ -55,0 +56,0 @@ @Column({ nullable: true }) |
@@ -61,2 +61,37 @@ import { | ||
function opToSQL(item: Where): any[] { | ||
switch (item.op) { | ||
case 'IsNull': | ||
return ['IS NULL', ''] | ||
case 'Like': | ||
if (item.value?.length != 1) throw Error('Operation Equal requires one value') | ||
return ['LIKE :value', item.value[0]] | ||
case 'Equal': | ||
if (item.value?.length != 1) throw Error('Operation Equal requires one value') | ||
return ['= :value', item.value[0]] | ||
case 'Any': | ||
case 'Between': | ||
case 'LessThan': | ||
case 'LessThanOrEqual': | ||
case 'MoreThan': | ||
case 'MoreThanOrEqual': | ||
throw new Error(`${item.op} not compatable with DID argument`) | ||
case 'In': | ||
default: | ||
return ['IN (:...value)', item.value] | ||
} | ||
} | ||
function addAudienceQuery(input: FindInput, qb: SelectQueryBuilder<any>): SelectQueryBuilder<any> { | ||
if (!Array.isArray(input.where)) { | ||
return qb | ||
} | ||
const audienceWhere = input.where.find((item) => item.column === "audience") | ||
if (!audienceWhere) { | ||
return qb | ||
} | ||
const [op, value] = opToSQL(audienceWhere) | ||
return qb.andWhere(`audience.did ${op}`, {value}) | ||
} | ||
function createWhereObject(input: FindInput): any { | ||
@@ -66,2 +101,5 @@ if (input?.where) { | ||
for (const item of input.where) { | ||
if (item.column === "audience") { | ||
continue | ||
} | ||
switch (item.op) { | ||
@@ -109,4 +147,4 @@ case 'Any': | ||
} | ||
return where | ||
} | ||
return where | ||
} | ||
@@ -125,6 +163,3 @@ } | ||
for (const item of input.order) { | ||
qb = qb.orderBy( | ||
`${qb.connection.driver.escape(tablename)}.${qb.connection.driver.escape(item.column)}`, | ||
item.direction, | ||
) | ||
qb = qb.orderBy(qb.connection.driver.escape(`${item.column}`), item.direction) | ||
} | ||
@@ -149,3 +184,3 @@ } | ||
const messages = async (_: any, args: FindArgs, ctx: Context) => { | ||
const messagesQuery = async (_: any, args: FindArgs, ctx: Context): Promise<SelectQueryBuilder<any>> => { | ||
const where = createWhereObject(args.input) | ||
@@ -168,26 +203,14 @@ let qb = (await ctx.agent.dbConnection) | ||
} | ||
return qb.getMany() | ||
return qb | ||
} | ||
const messages = async (_: any, args: FindArgs, ctx: Context) => { | ||
return (await messagesQuery(_, args, ctx)).getMany() | ||
} | ||
const messagesCount = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
let qb = (await ctx.agent.dbConnection) | ||
.getRepository(Message) | ||
.createQueryBuilder('message') | ||
.leftJoinAndSelect('message.from', 'from') | ||
.leftJoinAndSelect('message.to', 'to') | ||
.where(where) | ||
qb = decorateQB(qb, 'message', args.input) | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('message.to = :ident', { ident: ctx.authenticatedDid }).orWhere('message.from = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}) | ||
}), | ||
) | ||
} | ||
return (await qb.select('COUNT(message.id)').getRawOne())['COUNT("message"."id")'] | ||
return (await messagesQuery(_, args, ctx)).getCount() | ||
} | ||
const presentations = async (_: any, args: FindArgs, ctx: Context) => { | ||
const presentationsQuery = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
@@ -201,6 +224,7 @@ let qb = (await ctx.agent.dbConnection) | ||
qb = decorateQB(qb, 'presentation', args.input) | ||
qb = addAudienceQuery(args.input, qb) | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('presentation.audience = :ident', { | ||
qb.where('audience.did = :ident', { | ||
ident: ctx.authenticatedDid, | ||
@@ -211,27 +235,14 @@ }).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }) | ||
} | ||
return qb.getMany() | ||
return qb | ||
} | ||
const presentations = async (_: any, args: FindArgs, ctx: Context) => { | ||
return (await presentationsQuery(_, args, ctx)).getMany() | ||
} | ||
const presentationsCount = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
let qb = (await ctx.agent.dbConnection) | ||
.getRepository(Presentation) | ||
.createQueryBuilder('presentation') | ||
.leftJoinAndSelect('presentation.issuer', 'issuer') | ||
.leftJoinAndSelect('presentation.audience', 'audience') | ||
.where(where) | ||
qb = decorateQB(qb, 'presentation', args.input) | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('presentation.audience = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }) | ||
}), | ||
) | ||
} | ||
return qb.select('COUNT(presentation.hash)').getRawOne() | ||
return (await presentationsQuery(_, args, ctx)).getCount() | ||
} | ||
const credentials = async (_: any, args: FindArgs, ctx: Context) => { | ||
const credentialsQuery = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
@@ -257,30 +268,15 @@ let qb = (await ctx.agent.dbConnection) | ||
} | ||
return qb.getMany() | ||
return qb | ||
} | ||
const credentials = async (_: any, args: FindArgs, ctx: Context) => { | ||
return (await credentialsQuery(_, args, ctx)).getMany() | ||
} | ||
const credentialsCount = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
let qb = (await ctx.agent.dbConnection) | ||
.getRepository(Credential) | ||
.createQueryBuilder('credential') | ||
.leftJoinAndSelect('credential.issuer', 'issuer') | ||
.leftJoinAndSelect('credential.subject', 'subject') | ||
.where(where) | ||
qb = decorateQB(qb, 'credential', args.input) | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere( | ||
'credential.issuer = :ident', | ||
{ | ||
ident: ctx.authenticatedDid, | ||
}, | ||
) | ||
}), | ||
) | ||
} | ||
return qb.select('COUNT(credential.hash)').getRawOne() | ||
return (await credentialsQuery(_, args, ctx)).getCount() | ||
} | ||
const claims = async (_: any, args: FindArgs, ctx: Context) => { | ||
const claimsQuery = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
@@ -304,25 +300,11 @@ let qb = (await ctx.agent.dbConnection) | ||
} | ||
return qb.getMany() | ||
return qb | ||
} | ||
const claims = async (_: any, args: FindArgs, ctx: Context) => { | ||
return (await claimsQuery(_, args, ctx)).getMany() | ||
} | ||
const claimsCount = async (_: any, args: FindArgs, ctx: Context) => { | ||
const where = createWhereObject(args.input) | ||
let qb = (await ctx.agent.dbConnection) | ||
.getRepository(Claim) | ||
.createQueryBuilder('claim') | ||
.leftJoinAndSelect('claim.issuer', 'issuer') | ||
.leftJoinAndSelect('claim.subject', 'subject') | ||
.where(where) | ||
qb = decorateQB(qb, 'claim', args.input) | ||
qb = qb.leftJoinAndSelect('claim.credential', 'credential') | ||
if (ctx.authenticatedDid) { | ||
qb = qb.andWhere( | ||
new Brackets(qb => { | ||
qb.where('claim.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('claim.issuer = :ident', { | ||
ident: ctx.authenticatedDid, | ||
}) | ||
}), | ||
) | ||
} | ||
return qb.select('COUNT(claim.hash)').getRawOne() | ||
return (await claimsQuery(_, args, ctx)).getCount() | ||
} | ||
@@ -384,3 +366,3 @@ | ||
new Brackets(qb => { | ||
qb.where('presentation.audience = :ident', { | ||
qb.where('audience.did = :ident', { | ||
ident: ctx.authenticatedDid, | ||
@@ -744,3 +726,3 @@ }).orWhere('presentation.issuer = :ident', { ident: ctx.authenticatedDid }) | ||
issuer: Identity! | ||
audience: Identity! | ||
audience: [Identity]! | ||
issuanceDate: Date! | ||
@@ -747,0 +729,0 @@ expirationDate: Date |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
345666
5964