@exogee/graphweaver-mikroorm 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@exogee/graphweaver-mikroorm`
2
+
3
+ MikroORM adapter package for Graphweaver
@@ -0,0 +1,7 @@
1
+ import { EntityData } from '@mikro-orm/core';
2
+ interface AssignOptions {
3
+ create?: boolean;
4
+ update?: boolean;
5
+ }
6
+ export declare const assign: <T extends Partial<T>>(entity: T, data: EntityData<T>, options?: AssignOptions | undefined, visited?: Set<Partial<any>>) => Promise<T>;
7
+ export {};
@@ -0,0 +1 @@
1
+ export * from './provider';
@@ -0,0 +1,29 @@
1
+ import { BackendProvider, PaginationOptions } from '@exogee/graphweaver';
2
+ export declare const visitPathForPopulate: (entityName: string, updateArgBranch: any, populateBranch?: string) => Set<string>;
3
+ export declare const gqlToMikro: (filter: any) => any;
4
+ export declare const mapAndAssignKeys: <T>(result: T, entityType: new () => T, inputArgs: Partial<T>) => Promise<T>;
5
+ export declare class MikroBackendProvider<T extends {}> implements BackendProvider<T> {
6
+ readonly backendId = "mikro-orm";
7
+ entityType: new () => T;
8
+ readonly supportsInFilter = true;
9
+ private getRepository;
10
+ constructor(mikroType: new () => T);
11
+ private applyWhereClause;
12
+ find(filter: any, // @todo: Create a type for this
13
+ pagination?: PaginationOptions, additionalOptionsForBackend?: any): Promise<T[]>;
14
+ findOne(id: string): Promise<T | null>;
15
+ findByRelatedId(entity: any, relatedField: string, relatedFieldIds: string[], filter?: any): Promise<T[]>;
16
+ updateOne(id: string, updateArgs: Partial<T & {
17
+ version?: number;
18
+ }>): Promise<T>;
19
+ updateMany(updateItems: (Partial<T> & {
20
+ id: string;
21
+ })[]): Promise<T[]>;
22
+ createOrUpdateMany(items: Partial<T>[]): Promise<T[]>;
23
+ createOne(createArgs: Partial<T>): Promise<T>;
24
+ createMany(createItems: Partial<T>[]): Promise<T[]>;
25
+ deleteOne(id: string): Promise<boolean>;
26
+ deleteMany(ids: string[]): Promise<boolean>;
27
+ getRelatedEntityId(entity: any, relatedIdField: string): any;
28
+ isCollection(entity: any): boolean;
29
+ }
@@ -0,0 +1,17 @@
1
+ import { AccessType } from '@exogee/base-resolver';
2
+ import { AnyEntity } from '@exogee/database-entities';
3
+ import { Reference } from '@exogee/database-entities';
4
+ export declare const requiredPermissionsForAction: (intent: any) => AccessType;
5
+ export declare const assertObjectLevelPermissions: (
6
+ userPermission: ConsolidatedAccessControlEntry<any>,
7
+ requiredPermission: AccessType
8
+ ) => void;
9
+ export declare function checkFilterPermsForReference(
10
+ value: Reference<any>,
11
+ accessType: AccessType
12
+ ): Promise<void>;
13
+ export declare function checkAuthorization(
14
+ entity: AnyEntity<unknown>,
15
+ requestInput: any,
16
+ requiredPermission: AccessType
17
+ ): Promise<void>;
@@ -0,0 +1,8 @@
1
+ declare class RowLevelSecurityContextImplementation {
2
+ private getRolesFunction;
3
+ constructor();
4
+ setContext(getRolesFunction: () => string[]): void;
5
+ getRoles: () => string[];
6
+ }
7
+ export declare const RlsContext: RowLevelSecurityContextImplementation;
8
+ export {};
@@ -0,0 +1,26 @@
1
+ import { GraphQLEntity, PaginationOptions } from '@exogee/base-resolver';
2
+ import { MikroBackendProvider } from '@exogee/database-entities';
3
+ export declare class RLSMikroBackendProvider<
4
+ T,
5
+ G extends GraphQLEntity<T>
6
+ > extends MikroBackendProvider<T> {
7
+ private readonly gqlTypeName;
8
+ constructor(mikroType: new () => T, gqlType: new (dataEntity: T) => G);
9
+ private getAcl;
10
+ find(
11
+ filter: any,
12
+ pagination?: PaginationOptions,
13
+ additionalOptionsForBackend?: any
14
+ ): Promise<T[]>;
15
+ findOne(id: string): Promise<T | null>;
16
+ updateOne(id: string, updateArgs: Partial<T>): Promise<T>;
17
+ updateMany(
18
+ entities: (Partial<T> & {
19
+ id: string;
20
+ })[]
21
+ ): Promise<T[]>;
22
+ createOne(entity: Partial<T>): Promise<T>;
23
+ createMany(entities: Partial<T>[]): Promise<T[]>;
24
+ createOrUpdateMany(entities: Partial<T>[]): Promise<T[]>;
25
+ deleteOne(id: string): Promise<boolean>;
26
+ }
@@ -0,0 +1,2 @@
1
+ export * from './authorization-context';
2
+ export * from './database-provider';
@@ -0,0 +1,5 @@
1
+ export declare const requireEnvironmentVariable: (
2
+ envStr: string,
3
+ warnOnly?: boolean | undefined
4
+ ) => string | undefined;
5
+ export declare const config: {};
@@ -0,0 +1,33 @@
1
+ import 'reflect-metadata';
2
+ import './utils/change-tracker';
3
+ import { Connection, EntityName, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core';
4
+ import { EntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';
5
+ export interface ConnectionOptions {
6
+ overrides?: Options;
7
+ secretArn?: string;
8
+ }
9
+ export declare enum IsolationLevel {
10
+ SERIALIZABLE = "SERIALIZABLE",
11
+ REPEATABLE_READ = "REPEATABLE READ",
12
+ READ_COMMITTED = "READ COMMITTED",
13
+ READ_UNCOMMITTED = "READ UNCOMMITTED"
14
+ }
15
+ declare class DatabaseImplementation {
16
+ private cachedOrm?;
17
+ private transactionalEm?;
18
+ private transactionInProgressIsolationLevel?;
19
+ get orm(): MikroORM<IDatabaseDriver<Connection>>;
20
+ get em(): EntityManager<PostgreSqlDriver>;
21
+ transactional<T>(callback: () => Promise<T>, isolationLevel?: IsolationLevel): Promise<T>;
22
+ isolatedTest(test: () => any): () => Promise<void>;
23
+ get rawConnection(): import("@mikro-orm/postgresql").PostgreSqlConnection;
24
+ private getConnectionInfo;
25
+ getRepository: <T extends Partial<T>>(entityName: EntityName<T>) => import("@mikro-orm/core").GetRepository<T, import("@mikro-orm/postgresql").EntityRepository<T>>;
26
+ connect: (connectionOptions?: ConnectionOptions | undefined) => Promise<MikroORM<IDatabaseDriver<Connection>>>;
27
+ close: () => Promise<void>;
28
+ }
29
+ export declare const Database: DatabaseImplementation;
30
+ export declare const checkDatabase: () => Promise<any>;
31
+ export declare const getDbSchema: () => Promise<string>;
32
+ export declare const clearDatabaseContext: (req?: any, res?: any, next?: any, connectionOptions?: ConnectionOptions | undefined) => Promise<any>;
33
+ export {};
@@ -0,0 +1,13 @@
1
+ import { ChangeSetType, Collection } from '@mikro-orm/core';
2
+ import { AuditRelatedEntityChange } from './audit-related-entity-change';
3
+ import { BaseEntity } from './base-entity';
4
+ export declare class AuditChange extends BaseEntity {
5
+ id: string;
6
+ type: ChangeSetType;
7
+ entityId: string;
8
+ entityType: string;
9
+ createdBy: string;
10
+ createdAt: Date;
11
+ data?: Record<string, unknown>;
12
+ relatedEntityChanges?: Collection<AuditRelatedEntityChange>;
13
+ }
@@ -0,0 +1,9 @@
1
+ import { IdentifiedReference } from '@mikro-orm/core';
2
+ import { AuditChange } from './audit-change';
3
+ import { BaseEntity } from './base-entity';
4
+ export declare class AuditRelatedEntityChange extends BaseEntity {
5
+ id: string;
6
+ change: IdentifiedReference<AuditChange>;
7
+ relatedEntityType: string;
8
+ relatedEntityId: string;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseDataEntity } from '@exogee/graphweaver';
2
+ export declare class BaseEntity implements BaseDataEntity {
3
+ isReference(_: string, dataField: any): boolean;
4
+ isCollection(fieldName: string, dataField: any): boolean;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Reference } from '@mikro-orm/core';
2
+ import { BaseEntity } from './base-entity';
3
+ import { User } from './user';
4
+ export declare class Hobby extends BaseEntity {
5
+ id: string;
6
+ name: string;
7
+ user: Reference<User>;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './audit-change';
2
+ export * from './audit-related-entity-change';
3
+ export * from './base-entity';
@@ -0,0 +1,5 @@
1
+ export declare class Migration {
2
+ id: number;
3
+ lastMigration: number;
4
+ runAt: Date;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { BaseEntity } from './base-entity';
2
+ export declare class Session extends BaseEntity {
3
+ sessionToken: string;
4
+ expiresAt: Date;
5
+ value?: any;
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Collection } from '@mikro-orm/core';
2
+ import { BaseEntity } from './base-entity';
3
+ import { User } from './user';
4
+ export declare class Skill extends BaseEntity {
5
+ id: string;
6
+ name: string;
7
+ users: Collection<User, object>;
8
+ }
@@ -0,0 +1,10 @@
1
+ import { Collection } from '@mikro-orm/core';
2
+ import { BaseEntity } from './base-entity';
3
+ import { Hobby } from './hobby';
4
+ import { Skill } from './skill';
5
+ export declare class User extends BaseEntity {
6
+ id: string;
7
+ name: string;
8
+ hobbies: Collection<Hobby, object>;
9
+ skills: Collection<Skill, object>;
10
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export * from './base-resolver';
3
+ export * from './entities';
4
+ export * from './database';
5
+ export * from './types';
6
+ export * from './utils/authentication-context';
7
+ export type { AnyEntity, ChangeSet, EntityData, EntityName, EventArgs, EventSubscriber, FilterQuery, FlushEventArgs, Loaded, QueryOrderMap, } from '@mikro-orm/core';
8
+ export type { LoadedReference } from '@mikro-orm/core';
9
+ export { ChangeSetType, Collection, DatabaseObjectNotFoundException, EntityManager, EntityRepository, LockMode, PrimaryKeyType, QueryFlag, QueryOrder, Reference, ReferenceType, Subscriber, UniqueConstraintViolationException, Utils, wrap, } from '@mikro-orm/core';
10
+ export { SqlEntityManager, SqlEntityRepository } from '@mikro-orm/postgresql';