@exogee/graphweaver-mikroorm 0.1.1 → 0.1.2
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/lib/base-resolver/assign.d.ts +1 -1
- package/lib/base-resolver/assign.js +13 -12
- package/lib/base-resolver/assign.js.map +7 -0
- package/lib/base-resolver/index.js +1 -0
- package/lib/base-resolver/index.js.map +7 -0
- package/lib/base-resolver/provider.d.ts +10 -4
- package/lib/base-resolver/provider.js +121 -66
- package/lib/base-resolver/provider.js.map +7 -0
- package/lib/config.js +1 -0
- package/lib/config.js.map +7 -0
- package/lib/database.d.ts +9 -4
- package/lib/database.js +33 -27
- package/lib/database.js.map +7 -0
- package/lib/decorators/external-id-field.d.ts +8 -0
- package/lib/decorators/external-id-field.js +36 -0
- package/lib/decorators/external-id-field.js.map +7 -0
- package/lib/decorators/index.d.ts +1 -0
- package/lib/decorators/index.js +19 -0
- package/lib/decorators/index.js.map +7 -0
- package/lib/entities/audit-change.js +1 -0
- package/lib/entities/audit-change.js.map +7 -0
- package/lib/entities/audit-related-entity-change.js +1 -0
- package/lib/entities/audit-related-entity-change.js.map +7 -0
- package/lib/entities/base-entity.js +1 -0
- package/lib/entities/base-entity.js.map +7 -0
- package/lib/entities/index.js +1 -0
- package/lib/entities/index.js.map +7 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +7 -0
- package/lib/types/date-type.js +1 -0
- package/lib/types/date-type.js.map +7 -0
- package/lib/types/decimal-type.js +1 -0
- package/lib/types/decimal-type.js.map +7 -0
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +7 -0
- package/lib/types/time-type.js +1 -0
- package/lib/types/time-type.js.map +7 -0
- package/lib/utils/authentication-context.js +1 -0
- package/lib/utils/authentication-context.js.map +7 -0
- package/lib/utils/change-tracker.js +1 -0
- package/lib/utils/change-tracker.js.map +7 -0
- package/lib/utils/errors.js +1 -0
- package/lib/utils/errors.js.map +7 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +7 -0
- package/lib/utils/tracked-entity.js +1 -0
- package/lib/utils/tracked-entity.js.map +7 -0
- package/lib/utils/untracked-property.js +1 -0
- package/lib/utils/untracked-property.js.map +7 -0
- package/package.json +8 -7
|
@@ -3,5 +3,5 @@ interface AssignOptions {
|
|
|
3
3
|
create?: boolean;
|
|
4
4
|
update?: boolean;
|
|
5
5
|
}
|
|
6
|
-
export declare const assign: <T extends Partial<T>>(entity: T, data: EntityData<T>, options?: AssignOptions, visited?: Set<Partial<any
|
|
6
|
+
export declare const assign: <T extends Partial<T>>(entity: T, data: EntityData<T>, options?: AssignOptions, visited?: Set<Partial<any>>, em?: import("@mikro-orm/postgresql").EntityManager<import("@mikro-orm/postgresql").PostgreSqlDriver>) => Promise<T>;
|
|
7
7
|
export {};
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(assign_exports);
|
|
|
24
24
|
var import_core = require("@mikro-orm/core");
|
|
25
25
|
var import_logger = require("@exogee/logger");
|
|
26
26
|
var import_database = require("../database");
|
|
27
|
-
const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()) => {
|
|
27
|
+
const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set(), em = import_database.ConnectionManager.default.em) => {
|
|
28
28
|
var _a;
|
|
29
29
|
if (visited.has(entity))
|
|
30
30
|
return entity;
|
|
@@ -47,15 +47,15 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
|
|
|
47
47
|
for (const subvalue of value) {
|
|
48
48
|
let entity2;
|
|
49
49
|
if (subvalue.id) {
|
|
50
|
-
entity2 =
|
|
50
|
+
entity2 = em.getUnitOfWork().getById(propertyMetadata.type, subvalue.id);
|
|
51
51
|
if (!entity2) {
|
|
52
52
|
if (Object.keys(subvalue).length === 1) {
|
|
53
|
-
entity2 =
|
|
53
|
+
entity2 = em.getReference(propertyMetadata.type, subvalue.id);
|
|
54
54
|
} else {
|
|
55
55
|
import_logger.logger.warn(
|
|
56
56
|
`Doing a full database fetch for ${propertyMetadata.type} with id ${subvalue.id}, this should ideally be prefetched into the Unit of Work before calling assign() for performance`
|
|
57
57
|
);
|
|
58
|
-
entity2 = (_a = await
|
|
58
|
+
entity2 = (_a = await em.findOne(propertyMetadata.type, {
|
|
59
59
|
id: subvalue.id
|
|
60
60
|
})) != null ? _a : void 0;
|
|
61
61
|
}
|
|
@@ -71,7 +71,8 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
|
|
|
71
71
|
entityType: propertyMetadata.type,
|
|
72
72
|
data: subvalue,
|
|
73
73
|
options,
|
|
74
|
-
visited
|
|
74
|
+
visited,
|
|
75
|
+
em
|
|
75
76
|
});
|
|
76
77
|
entityPropertyValue.add(newEntity);
|
|
77
78
|
visitedEntities.add(newEntity);
|
|
@@ -85,10 +86,7 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
|
|
|
85
86
|
} else {
|
|
86
87
|
const valueKeys = Object.keys(value);
|
|
87
88
|
if (valueKeys.length === 1 && valueKeys[0] === "id") {
|
|
88
|
-
entity[property] =
|
|
89
|
-
propertyMetadata.type,
|
|
90
|
-
value.id
|
|
91
|
-
);
|
|
89
|
+
entity[property] = em.getReference(propertyMetadata.type, value.id);
|
|
92
90
|
} else {
|
|
93
91
|
if (entityPropertyValue && !import_core.Reference.isReference(entityPropertyValue)) {
|
|
94
92
|
throw new Error(
|
|
@@ -105,7 +103,8 @@ const assign = async (entity, data, options, visited = /* @__PURE__ */ new Set()
|
|
|
105
103
|
entityType: propertyMetadata.type,
|
|
106
104
|
data: value,
|
|
107
105
|
options,
|
|
108
|
-
visited
|
|
106
|
+
visited,
|
|
107
|
+
em
|
|
109
108
|
});
|
|
110
109
|
entity[property] = import_core.Reference.create(newEntity);
|
|
111
110
|
}
|
|
@@ -121,7 +120,8 @@ const createOrAssignEntity = ({
|
|
|
121
120
|
entityType,
|
|
122
121
|
data,
|
|
123
122
|
options,
|
|
124
|
-
visited
|
|
123
|
+
visited,
|
|
124
|
+
em
|
|
125
125
|
}) => {
|
|
126
126
|
var _a, _b;
|
|
127
127
|
const create = (_a = options == null ? void 0 : options.create) != null ? _a : true;
|
|
@@ -150,7 +150,7 @@ const createOrAssignEntity = ({
|
|
|
150
150
|
)} was passed which does not have an ID property.`
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
|
-
const entity2 =
|
|
153
|
+
const entity2 = em.create(entityType, {});
|
|
154
154
|
return assign(entity2, data, options, visited);
|
|
155
155
|
}
|
|
156
156
|
};
|
|
@@ -158,3 +158,4 @@ const createOrAssignEntity = ({
|
|
|
158
158
|
0 && (module.exports = {
|
|
159
159
|
assign
|
|
160
160
|
});
|
|
161
|
+
//# sourceMappingURL=assign.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/base-resolver/assign.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tAnyEntity,\n\tCollection,\n\tEntityData,\n\tEntityManager,\n\tEntityProperty,\n\tReference,\n\tReferenceType,\n\twrap,\n} from '@mikro-orm/core';\nimport { logger } from '@exogee/logger';\n\nimport { ConnectionManager } from '../database';\n\n// This is how Mikro ORM does it within their own code, so in this file we're ok with non-null assertions.\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\ninterface AssignOptions {\n\t// Whether this assign should be allowed to create new entities.\n\t// If false and a create is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tcreate?: boolean;\n\n\t// Whether this assign should be allowed update existing entities.\n\t// If false and an update is attempted, assign will throw.\n\t// Defaults to true if not specified.\n\tupdate?: boolean;\n}\n\nexport const assign = async <T extends AnyEntity<T>>(\n\tentity: T,\n\tdata: EntityData<T>,\n\toptions?: AssignOptions,\n\tvisited = new Set<AnyEntity<any>>(),\n\tem = ConnectionManager.default.em\n) => {\n\tif (visited.has(entity)) return entity;\n\tvisited.add(entity);\n\n\t// We'll need the metadata for this entity to be able to traverse the properties later.\n\tconst metadata = wrap(entity, true).__meta!;\n\n\tfor (const [property, value] of Object.entries(data)) {\n\t\tconst entityPropertyValue = (entity as any)[property];\n\n\t\t// We're going to need the metadata for this property so we can ensure it exists and so that we can\n\t\t// navigate to related entities.\n\t\tconst propertyMetadata = (metadata.properties as any)[property] as\n\t\t\t| EntityProperty<T>\n\t\t\t| undefined;\n\n\t\tif (\n\t\t\tpropertyMetadata?.reference === ReferenceType.MANY_TO_MANY ||\n\t\t\tpropertyMetadata?.reference === ReferenceType.ONE_TO_MANY\n\t\t) {\n\t\t\tif (!Array.isArray(value))\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Value is not an array while trying to assign to collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\n\t\t\t// Ensure the entity has a loaded collection at the same place.\n\t\t\tif (!(entityPropertyValue instanceof Collection)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Tried to merge array into non-collection property ${property} on entity ${metadata.name}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst visitedEntities = new Set<T>();\n\n\t\t\tfor (const subvalue of value) {\n\t\t\t\tlet entity: T | undefined;\n\n\t\t\t\tif (subvalue.id) {\n\t\t\t\t\t// Get the current entity from the ORM if there's an ID.\n\t\t\t\t\tentity = em.getUnitOfWork().getById(propertyMetadata.type, subvalue.id);\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\t// There are two cases here: either the user is trying to assign properties to the entity as well as changing members of a collection,\n\t\t\t\t\t\t// or they're just changing members of a collection.\n\t\t\t\t\t\t// For the former we actually need the entity from the DB, while for the latter we can let it slide and just pass an ID entity on down.\n\t\t\t\t\t\tif (Object.keys(subvalue).length === 1) {\n\t\t\t\t\t\t\t// It's just the ID.\n\t\t\t\t\t\t\tentity = em.getReference(propertyMetadata.type, subvalue.id) as T;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t\t`Doing a full database fetch for ${propertyMetadata.type} with id ${subvalue.id}, this should ideally be prefetched into the Unit of Work before calling assign() for performance`\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// We should be prefetching for performance in most cases here but if we don't have it we can load it now.\n\t\t\t\t\t\t\t// From base resolver a reason this would be needed is when you're switching collection values from one entity to another, e.g.\n\t\t\t\t\t\t\t// Business unit 1 -> Business unit 2. In this scenario we prefetch the one that's currently on the entity, but the one we're changing\n\t\t\t\t\t\t\t// to is not in the unit of work.\n\t\t\t\t\t\t\tentity =\n\t\t\t\t\t\t\t\t((await em.findOne(propertyMetadata.type, {\n\t\t\t\t\t\t\t\t\tid: subvalue.id,\n\t\t\t\t\t\t\t\t})) as T | null) ?? undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!entity) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Attempted to assign as an update to '${propertyMetadata.name}' property of ${metadata.name} Entity, but even after a full fetch to the database ${propertyMetadata.type} with ID of ${subvalue.id} could not be found.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\tentity,\n\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\tdata: subvalue,\n\t\t\t\t\toptions,\n\t\t\t\t\tvisited,\n\t\t\t\t\tem,\n\t\t\t\t});\n\n\t\t\t\t// Ok, now we've got the created or updated entity, ensure it's in the collection\n\t\t\t\t// so its foreign keys are set correctly. If it's already in the collection this is a noop.\n\t\t\t\tentityPropertyValue.add(newEntity);\n\n\t\t\t\t// We need to keep track of the fact that this entity belongs here so it doesn't get removed in the cleanup step down below.\n\t\t\t\tvisitedEntities.add(newEntity);\n\t\t\t}\n\n\t\t\t// Ok, at this point we know what IDs we visited. If anything is left in the collection that has an ID and has not been visited\n\t\t\t// it needs to be removed from the collection, because this is the canonical list of everything that's in the collection now.\n\t\t\t// ------------\n\t\t\t// \u2757\uD83D\uDC3B WARNING BEAR TRAP \uD83D\uDC3B\u2757: If you're looking at this going, \"But I just want to pass in the items I want to update and for it not to\n\t\t\t// mess with the rest of the collection\", this is here because without this behaviour, there's no way to remove items from\n\t\t\t// Many to many properties. Consider the case of tags on an entity, when we pass ['a', 'b', 'c'] as the list of tags, that\n\t\t\t// means we need to remove anything that isn't 'a', 'b', or 'c' because it's not in the array.\n\t\t\tentityPropertyValue.remove(\n\t\t\t\t...entityPropertyValue.getItems().filter((entity) => !visitedEntities.has(entity))\n\t\t\t);\n\t\t} else if (\n\t\t\tpropertyMetadata?.reference == ReferenceType.MANY_TO_ONE ||\n\t\t\tpropertyMetadata?.reference === ReferenceType.ONE_TO_ONE\n\t\t) {\n\t\t\tif (value === null) {\n\t\t\t\t// If the value is null, unset the reference\n\t\t\t\t(entity as any)[property] = null;\n\t\t\t} else {\n\t\t\t\tconst valueKeys = Object.keys(value as any);\n\t\t\t\tif (valueKeys.length === 1 && valueKeys[0] === 'id') {\n\t\t\t\t\t// Ok, this is just the ID, set the reference and move on.\n\t\t\t\t\t(entity as any)[property] = em.getReference(propertyMetadata.type, (value as any).id);\n\t\t\t\t} else {\n\t\t\t\t\tif (entityPropertyValue && !Reference.isReference(entityPropertyValue)) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not a reference.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (entityPropertyValue && !entityPropertyValue.isInitialized()) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Trying to merge to related property ${property} on entity ${metadata.name} which is not initialised.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = await createOrAssignEntity<T>({\n\t\t\t\t\t\tentity: entityPropertyValue?.unwrap() as T,\n\t\t\t\t\t\tentityType: propertyMetadata.type,\n\t\t\t\t\t\tdata: value as EntityData<T>,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\tvisited,\n\t\t\t\t\t\tem,\n\t\t\t\t\t});\n\n\t\t\t\t\t(entity as any)[property] = Reference.create(newEntity);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Ok, we're a simple scalar.\n\t\t\t(entity as any)[property] = value;\n\t\t}\n\t}\n\n\treturn entity;\n};\n\nconst createOrAssignEntity = <T extends AnyEntity<T>>({\n\tentity,\n\tentityType,\n\tdata,\n\toptions,\n\tvisited,\n\tem,\n}: {\n\tentity?: T;\n\tentityType: string;\n\tdata: EntityData<T>;\n\toptions?: AssignOptions;\n\tvisited: Set<AnyEntity<any>>;\n\tem: EntityManager;\n}) => {\n\tconst create = options?.create ?? true;\n\tconst update = options?.update ?? true;\n\n\tif ((data as any).id) {\n\t\tif (!update) {\n\t\t\tthrow new Error(\n\t\t\t\t`Updates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which has an ID property.`\n\t\t\t);\n\t\t}\n\n\t\tif (!entity) {\n\t\t\tthrow new Error(\n\t\t\t\t`Tried to update with data ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} but entity could not be located to update.`\n\t\t\t);\n\t\t}\n\n\t\t// Ok, we need to recurse here.\n\t\treturn assign(entity, data, options, visited);\n\t} else {\n\t\tif (!create) {\n\t\t\tthrow new Error(\n\t\t\t\t`Creates are disabled, but update value ${JSON.stringify(\n\t\t\t\t\tdata\n\t\t\t\t)} was passed which does not have an ID property.`\n\t\t\t);\n\t\t}\n\n\t\t// We don't want Mikro to manage the data merging here, we'll do it in the next line.\n\t\tconst entity = em.create<T>(entityType, {} as any);\n\t\treturn assign(entity, data, options, visited);\n\t}\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBASO;AACP,oBAAuB;AAEvB,sBAAkC;AAiB3B,MAAM,SAAS,OACrB,QACA,MACA,SACA,UAAU,oBAAI,IAAoB,GAClC,KAAK,kCAAkB,QAA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EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,MAOM;AAjMN;AAkMC,QAAM,UAAS,wCAAS,WAAT,YAAmB;AAClC,QAAM,UAAS,wCAAS,WAAT,YAAmB;AAElC,MAAK,KAAa,IAAI;AACrB,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,0CAA0C,KAAK;AAAA,UAC9C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,6BAA6B,KAAK;AAAA,UACjC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGA,WAAO,OAAO,QAAQ,MAAM,SAAS,OAAO;AAAA,EAC7C,OAAO;AACN,QAAI,CAAC,QAAQ;AACZ,YAAM,IAAI;AAAA,QACT,0CAA0C,KAAK;AAAA,UAC9C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGA,UAAMA,UAAS,GAAG,OAAU,YAAY,CAAC,CAAQ;AACjD,WAAO,OAAOA,SAAQ,MAAM,SAAS,OAAO;AAAA,EAC7C;AACD;",
|
|
6
|
+
"names": ["entity"]
|
|
7
|
+
}
|
|
@@ -16,3 +16,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var base_resolver_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(base_resolver_exports);
|
|
18
18
|
__reExport(base_resolver_exports, require("./provider"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { BackendProvider, PaginationOptions } from '@exogee/graphweaver';
|
|
2
|
-
export declare const visitPathForPopulate: (entityName: string, updateArgBranch: any, populateBranch?: string) => Set<string>;
|
|
3
2
|
export declare const gqlToMikro: (filter: any) => any;
|
|
4
|
-
export declare const mapAndAssignKeys: <T>(result: T, entityType: new () => T, inputArgs: Partial<T>) => Promise<T>;
|
|
5
3
|
export declare class MikroBackendProvider<T extends {}> implements BackendProvider<T> {
|
|
6
|
-
|
|
4
|
+
private _backendId;
|
|
7
5
|
entityType: new () => T;
|
|
6
|
+
connectionManagerId?: string;
|
|
8
7
|
readonly supportsInFilter = true;
|
|
8
|
+
get backendId(): string;
|
|
9
|
+
private get database();
|
|
10
|
+
get transactional(): <T_1>(callback: () => Promise<T_1>, isolationLevel?: import("..").IsolationLevel) => Promise<T_1>;
|
|
11
|
+
get em(): import("@mikro-orm/postgresql").EntityManager<import("@mikro-orm/postgresql").PostgreSqlDriver>;
|
|
9
12
|
private getRepository;
|
|
10
|
-
constructor(mikroType: new () => T);
|
|
13
|
+
constructor(mikroType: new () => T, connectionManagerId?: string);
|
|
14
|
+
private mapAndAssignKeys;
|
|
15
|
+
private applyExternalIdFields;
|
|
16
|
+
visitPathForPopulate: (entityName: string, updateArgBranch: any, populateBranch?: string) => Set<string>;
|
|
11
17
|
private applyWhereClause;
|
|
12
18
|
find(filter: any, // @todo: Create a type for this
|
|
13
19
|
pagination?: PaginationOptions, additionalOptionsForBackend?: any): Promise<T[]>;
|
|
@@ -19,9 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var provider_exports = {};
|
|
20
20
|
__export(provider_exports, {
|
|
21
21
|
MikroBackendProvider: () => MikroBackendProvider,
|
|
22
|
-
gqlToMikro: () => gqlToMikro
|
|
23
|
-
mapAndAssignKeys: () => mapAndAssignKeys,
|
|
24
|
-
visitPathForPopulate: () => visitPathForPopulate
|
|
22
|
+
gqlToMikro: () => gqlToMikro
|
|
25
23
|
});
|
|
26
24
|
module.exports = __toCommonJS(provider_exports);
|
|
27
25
|
var import_logger = require("@exogee/logger");
|
|
@@ -48,34 +46,6 @@ const nonJoinKeys = /* @__PURE__ */ new Set([
|
|
|
48
46
|
"id"
|
|
49
47
|
]);
|
|
50
48
|
const appendPath = (path, newPath) => path.length ? `${path}.${newPath}` : newPath;
|
|
51
|
-
const visitPathForPopulate = (entityName, updateArgBranch, populateBranch = "") => {
|
|
52
|
-
var _a, _b, _c, _d;
|
|
53
|
-
const { properties } = import__.Database.em.getMetadata().get(entityName);
|
|
54
|
-
const collectedPaths = populateBranch ? /* @__PURE__ */ new Set([populateBranch]) : /* @__PURE__ */ new Set([]);
|
|
55
|
-
for (const [key, value] of Object.entries(updateArgBranch != null ? updateArgBranch : {})) {
|
|
56
|
-
if (((_a = properties[key]) == null ? void 0 : _a.reference) === import__.ReferenceType.ONE_TO_ONE || ((_b = properties[key]) == null ? void 0 : _b.reference) === import__.ReferenceType.ONE_TO_MANY || ((_c = properties[key]) == null ? void 0 : _c.reference) === import__.ReferenceType.MANY_TO_ONE || ((_d = properties[key]) == null ? void 0 : _d.reference) === import__.ReferenceType.MANY_TO_MANY) {
|
|
57
|
-
if (Array.isArray(value)) {
|
|
58
|
-
collectedPaths.add(appendPath(populateBranch, key));
|
|
59
|
-
for (const entry of value) {
|
|
60
|
-
const newPaths = visitPathForPopulate(
|
|
61
|
-
properties[key].type,
|
|
62
|
-
entry,
|
|
63
|
-
appendPath(populateBranch, key)
|
|
64
|
-
);
|
|
65
|
-
newPaths.forEach((path) => collectedPaths.add(path));
|
|
66
|
-
}
|
|
67
|
-
} else if (typeof value === "object") {
|
|
68
|
-
const newPaths = visitPathForPopulate(
|
|
69
|
-
properties[key].type,
|
|
70
|
-
value,
|
|
71
|
-
appendPath(populateBranch, key)
|
|
72
|
-
);
|
|
73
|
-
newPaths.forEach((path) => collectedPaths.add(path));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return collectedPaths;
|
|
78
|
-
};
|
|
79
49
|
const gqlToMikro = (filter) => {
|
|
80
50
|
if (Array.isArray(filter)) {
|
|
81
51
|
return filter.map((element) => gqlToMikro(element));
|
|
@@ -102,21 +72,104 @@ const gqlToMikro = (filter) => {
|
|
|
102
72
|
}
|
|
103
73
|
return filter;
|
|
104
74
|
};
|
|
105
|
-
const mapAndAssignKeys = (result, entityType, inputArgs) => {
|
|
106
|
-
const cleanInput = JSON.parse(JSON.stringify(inputArgs));
|
|
107
|
-
return (0, import_assign.assign)(result, cleanInput);
|
|
108
|
-
};
|
|
109
75
|
class MikroBackendProvider {
|
|
110
|
-
constructor(mikroType) {
|
|
111
|
-
this.backendId = "mikro-orm";
|
|
76
|
+
constructor(mikroType, connectionManagerId) {
|
|
112
77
|
this.supportsInFilter = true;
|
|
113
78
|
this.getRepository = () => {
|
|
114
|
-
const repository =
|
|
79
|
+
const repository = this.database.em.getRepository(this.entityType);
|
|
115
80
|
if (!repository)
|
|
116
81
|
throw new Error("Could not find repository for " + this.entityType.name);
|
|
117
82
|
return repository;
|
|
118
83
|
};
|
|
84
|
+
this.mapAndAssignKeys = (result, entityType, inputArgs) => {
|
|
85
|
+
const assignmentObj = this.applyExternalIdFields(entityType, inputArgs);
|
|
86
|
+
return (0, import_assign.assign)(result, assignmentObj, void 0, void 0, this.database.em);
|
|
87
|
+
};
|
|
88
|
+
this.applyExternalIdFields = (target, values) => {
|
|
89
|
+
const targetName = typeof target === "string" ? target : target.name;
|
|
90
|
+
const map = import__.externalIdFieldMap.get(targetName);
|
|
91
|
+
const mapFieldNames = (partialFilterObj) => {
|
|
92
|
+
for (const [from, to] of Object.entries(map || {})) {
|
|
93
|
+
if (partialFilterObj[from] && typeof partialFilterObj[from].id !== "undefined") {
|
|
94
|
+
if (Object.keys(partialFilterObj[from]).length > 1) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Expected precisely 1 key called 'id' in queryObj.${from} on ${target}, got ${JSON.stringify(
|
|
97
|
+
partialFilterObj[from],
|
|
98
|
+
null,
|
|
99
|
+
4
|
|
100
|
+
)}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
partialFilterObj[to] = partialFilterObj[from].id;
|
|
104
|
+
delete partialFilterObj[from];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
for (const rootLevelKey of Object.keys(values)) {
|
|
109
|
+
if (mikroObjectOperations.has(rootLevelKey)) {
|
|
110
|
+
for (const field of values[rootLevelKey]) {
|
|
111
|
+
mapFieldNames(field);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
mapFieldNames(values);
|
|
116
|
+
const { properties } = this.database.em.getMetadata().get(targetName);
|
|
117
|
+
Object.values(properties).filter((property) => typeof property.entity !== "undefined" && values[property.name]).forEach((property) => {
|
|
118
|
+
if (Array.isArray(values[property.name])) {
|
|
119
|
+
values[property.name].forEach(
|
|
120
|
+
(value) => this.applyExternalIdFields(property.type, value)
|
|
121
|
+
);
|
|
122
|
+
} else {
|
|
123
|
+
values[property.name] = this.applyExternalIdFields(property.type, values[property.name]);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return values;
|
|
127
|
+
};
|
|
128
|
+
this.visitPathForPopulate = (entityName, updateArgBranch, populateBranch = "") => {
|
|
129
|
+
var _a, _b, _c, _d;
|
|
130
|
+
const { properties } = this.database.em.getMetadata().get(entityName);
|
|
131
|
+
const collectedPaths = populateBranch ? /* @__PURE__ */ new Set([populateBranch]) : /* @__PURE__ */ new Set([]);
|
|
132
|
+
for (const [key, value] of Object.entries(updateArgBranch != null ? updateArgBranch : {})) {
|
|
133
|
+
if (((_a = properties[key]) == null ? void 0 : _a.reference) === import__.ReferenceType.ONE_TO_ONE || ((_b = properties[key]) == null ? void 0 : _b.reference) === import__.ReferenceType.ONE_TO_MANY || ((_c = properties[key]) == null ? void 0 : _c.reference) === import__.ReferenceType.MANY_TO_ONE || ((_d = properties[key]) == null ? void 0 : _d.reference) === import__.ReferenceType.MANY_TO_MANY) {
|
|
134
|
+
if (Array.isArray(value)) {
|
|
135
|
+
collectedPaths.add(appendPath(populateBranch, key));
|
|
136
|
+
for (const entry of value) {
|
|
137
|
+
const newPaths = this.visitPathForPopulate(
|
|
138
|
+
properties[key].type,
|
|
139
|
+
entry,
|
|
140
|
+
appendPath(populateBranch, key)
|
|
141
|
+
);
|
|
142
|
+
newPaths.forEach((path) => collectedPaths.add(path));
|
|
143
|
+
}
|
|
144
|
+
} else if (typeof value === "object") {
|
|
145
|
+
const newPaths = this.visitPathForPopulate(
|
|
146
|
+
properties[key].type,
|
|
147
|
+
value,
|
|
148
|
+
appendPath(populateBranch, key)
|
|
149
|
+
);
|
|
150
|
+
newPaths.forEach((path) => collectedPaths.add(path));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return collectedPaths;
|
|
155
|
+
};
|
|
119
156
|
this.entityType = mikroType;
|
|
157
|
+
this.connectionManagerId = connectionManagerId;
|
|
158
|
+
this._backendId = `mikro-orm-${connectionManagerId || ""}`;
|
|
159
|
+
}
|
|
160
|
+
get backendId() {
|
|
161
|
+
return this._backendId;
|
|
162
|
+
}
|
|
163
|
+
get database() {
|
|
164
|
+
if (!this.connectionManagerId)
|
|
165
|
+
return import__.ConnectionManager.default;
|
|
166
|
+
return import__.ConnectionManager.database(this.connectionManagerId) || import__.ConnectionManager.default;
|
|
167
|
+
}
|
|
168
|
+
get transactional() {
|
|
169
|
+
return this.database.transactional;
|
|
170
|
+
}
|
|
171
|
+
get em() {
|
|
172
|
+
return this.database.em;
|
|
120
173
|
}
|
|
121
174
|
applyWhereClause(where) {
|
|
122
175
|
const query = this.getRepository().createQueryBuilder();
|
|
@@ -158,13 +211,14 @@ class MikroBackendProvider {
|
|
|
158
211
|
filter: JSON.stringify(filter)
|
|
159
212
|
});
|
|
160
213
|
const where = filter ? gqlToMikro(JSON.parse(JSON.stringify(filter))) : void 0;
|
|
161
|
-
const
|
|
214
|
+
const whereWithAppliedExternalIdFields = where && this.applyExternalIdFields(this.entityType, where);
|
|
215
|
+
const query = this.applyWhereClause(whereWithAppliedExternalIdFields);
|
|
162
216
|
(pagination == null ? void 0 : pagination.limit) && query.limit(pagination.limit);
|
|
163
217
|
(pagination == null ? void 0 : pagination.offset) && query.offset(pagination.offset);
|
|
164
218
|
(pagination == null ? void 0 : pagination.orderBy) && query.orderBy({ ...pagination.orderBy });
|
|
165
219
|
query.setFlag(import__.QueryFlag.DISTINCT);
|
|
166
|
-
const driver =
|
|
167
|
-
const meta =
|
|
220
|
+
const driver = this.database.em.getDriver();
|
|
221
|
+
const meta = this.database.em.getMetadata().get(this.entityType.name);
|
|
168
222
|
query.populate(driver.autoJoinOneToOneOwner(meta, []));
|
|
169
223
|
if (additionalOptionsForBackend == null ? void 0 : additionalOptionsForBackend.populate) {
|
|
170
224
|
query.populate(additionalOptionsForBackend.populate);
|
|
@@ -175,7 +229,7 @@ class MikroBackendProvider {
|
|
|
175
229
|
}
|
|
176
230
|
async findOne(id) {
|
|
177
231
|
import_logger.logger.trace(`Running findOne ${this.entityType.name} with ID ${id}`);
|
|
178
|
-
const result = await
|
|
232
|
+
const result = await this.database.em.findOne(this.entityType, id);
|
|
179
233
|
import_logger.logger.trace(`findOne ${this.entityType.name} result`, { result });
|
|
180
234
|
return result;
|
|
181
235
|
}
|
|
@@ -184,7 +238,7 @@ class MikroBackendProvider {
|
|
|
184
238
|
$and: [{ [relatedField]: { $in: relatedFieldIds } }, ...[filter != null ? filter : []]]
|
|
185
239
|
};
|
|
186
240
|
const populate = [relatedField];
|
|
187
|
-
const result = await
|
|
241
|
+
const result = await this.database.em.find(entity, queryFilter, { populate });
|
|
188
242
|
return result;
|
|
189
243
|
}
|
|
190
244
|
async updateOne(id, updateArgs) {
|
|
@@ -192,21 +246,21 @@ class MikroBackendProvider {
|
|
|
192
246
|
id,
|
|
193
247
|
updateArgs: JSON.stringify(updateArgs)
|
|
194
248
|
});
|
|
195
|
-
const entity = await
|
|
196
|
-
populate: [...visitPathForPopulate(this.entityType.name, updateArgs)]
|
|
249
|
+
const entity = await this.database.em.findOne(this.entityType, id, {
|
|
250
|
+
populate: [...this.visitPathForPopulate(this.entityType.name, updateArgs)]
|
|
197
251
|
});
|
|
198
252
|
if (entity === null) {
|
|
199
253
|
throw new Error(`Unable to locate ${this.entityType.name} with ID: '${id}' for updating.`);
|
|
200
254
|
}
|
|
201
255
|
if (updateArgs == null ? void 0 : updateArgs.version) {
|
|
202
256
|
try {
|
|
203
|
-
await
|
|
257
|
+
await this.database.em.lock(entity, import__.LockMode.OPTIMISTIC, updateArgs.version);
|
|
204
258
|
delete updateArgs.version;
|
|
205
259
|
} catch (err) {
|
|
206
260
|
throw new import_errors.OptimisticLockError(err == null ? void 0 : err.message, { entity });
|
|
207
261
|
}
|
|
208
262
|
}
|
|
209
|
-
await mapAndAssignKeys(entity, this.entityType, updateArgs);
|
|
263
|
+
await this.mapAndAssignKeys(entity, this.entityType, updateArgs);
|
|
210
264
|
await this.getRepository().persistAndFlush(entity);
|
|
211
265
|
import_logger.logger.trace(`update ${this.entityType.name} entity`, entity);
|
|
212
266
|
return entity;
|
|
@@ -215,16 +269,16 @@ class MikroBackendProvider {
|
|
|
215
269
|
import_logger.logger.trace(`Running update many ${this.entityType.name} with args`, {
|
|
216
270
|
updateItems: JSON.stringify(updateItems)
|
|
217
271
|
});
|
|
218
|
-
const entities = await
|
|
272
|
+
const entities = await this.database.transactional(async () => {
|
|
219
273
|
return Promise.all(
|
|
220
274
|
updateItems.map(async (item) => {
|
|
221
275
|
if (!(item == null ? void 0 : item.id))
|
|
222
276
|
throw new Error("You must pass an ID for this entity to update it.");
|
|
223
|
-
const entity = await
|
|
224
|
-
populate: [...visitPathForPopulate(this.entityType.name, item)]
|
|
277
|
+
const entity = await this.database.em.findOneOrFail(this.entityType, item.id, {
|
|
278
|
+
populate: [...this.visitPathForPopulate(this.entityType.name, item)]
|
|
225
279
|
});
|
|
226
|
-
await mapAndAssignKeys(entity, this.entityType, item);
|
|
227
|
-
|
|
280
|
+
await this.mapAndAssignKeys(entity, this.entityType, item);
|
|
281
|
+
this.database.em.persist(entity);
|
|
228
282
|
return entity;
|
|
229
283
|
})
|
|
230
284
|
);
|
|
@@ -236,27 +290,29 @@ class MikroBackendProvider {
|
|
|
236
290
|
import_logger.logger.trace(`Running create or update many for ${this.entityType.name} with args`, {
|
|
237
291
|
items: JSON.stringify(items)
|
|
238
292
|
});
|
|
239
|
-
const entities = await
|
|
293
|
+
const entities = await this.database.transactional(async () => {
|
|
240
294
|
return Promise.all(
|
|
241
295
|
items.map(async (item) => {
|
|
242
296
|
let entity;
|
|
243
297
|
const { id } = item;
|
|
244
298
|
if (id) {
|
|
245
|
-
entity = await
|
|
246
|
-
populate: [
|
|
299
|
+
entity = await this.database.em.findOneOrFail(this.entityType, id, {
|
|
300
|
+
populate: [
|
|
301
|
+
...this.visitPathForPopulate(this.entityType.name, item)
|
|
302
|
+
]
|
|
247
303
|
});
|
|
248
304
|
import_logger.logger.trace(`Running update on ${this.entityType.name} with item`, {
|
|
249
305
|
item: JSON.stringify(item)
|
|
250
306
|
});
|
|
251
|
-
await mapAndAssignKeys(entity, this.entityType, item);
|
|
307
|
+
await this.mapAndAssignKeys(entity, this.entityType, item);
|
|
252
308
|
} else {
|
|
253
309
|
entity = new this.entityType();
|
|
254
|
-
await mapAndAssignKeys(entity, this.entityType, item);
|
|
310
|
+
await this.mapAndAssignKeys(entity, this.entityType, item);
|
|
255
311
|
import_logger.logger.trace(`Running create on ${this.entityType.name} with item`, {
|
|
256
312
|
item: JSON.stringify(item)
|
|
257
313
|
});
|
|
258
314
|
}
|
|
259
|
-
|
|
315
|
+
this.database.em.persist(entity);
|
|
260
316
|
return entity;
|
|
261
317
|
})
|
|
262
318
|
);
|
|
@@ -269,7 +325,7 @@ class MikroBackendProvider {
|
|
|
269
325
|
createArgs: JSON.stringify(createArgs)
|
|
270
326
|
});
|
|
271
327
|
const entity = new this.entityType();
|
|
272
|
-
await mapAndAssignKeys(entity, this.entityType, createArgs);
|
|
328
|
+
await this.mapAndAssignKeys(entity, this.entityType, createArgs);
|
|
273
329
|
await this.getRepository().persistAndFlush(entity);
|
|
274
330
|
import_logger.logger.trace(`create ${this.entityType.name} result`, entity);
|
|
275
331
|
return entity;
|
|
@@ -278,12 +334,12 @@ class MikroBackendProvider {
|
|
|
278
334
|
import_logger.logger.trace(`Running create ${this.entityType.name} with args`, {
|
|
279
335
|
createArgs: JSON.stringify(createItems)
|
|
280
336
|
});
|
|
281
|
-
const entities = await
|
|
337
|
+
const entities = await this.database.transactional(async () => {
|
|
282
338
|
return Promise.all(
|
|
283
339
|
createItems.map(async (item) => {
|
|
284
340
|
const entity = new this.entityType();
|
|
285
|
-
await mapAndAssignKeys(entity, this.entityType, item);
|
|
286
|
-
|
|
341
|
+
await this.mapAndAssignKeys(entity, this.entityType, item);
|
|
342
|
+
this.database.em.persist(entity);
|
|
287
343
|
return entity;
|
|
288
344
|
})
|
|
289
345
|
);
|
|
@@ -304,7 +360,7 @@ class MikroBackendProvider {
|
|
|
304
360
|
}
|
|
305
361
|
async deleteMany(ids) {
|
|
306
362
|
import_logger.logger.trace(`Running delete ${this.entityType.name} with ids ${ids}`);
|
|
307
|
-
const deletedRows = await
|
|
363
|
+
const deletedRows = await this.database.transactional(async () => {
|
|
308
364
|
const deletedCount = await this.getRepository().nativeDelete({
|
|
309
365
|
id: { $in: ids }
|
|
310
366
|
});
|
|
@@ -332,7 +388,6 @@ class MikroBackendProvider {
|
|
|
332
388
|
// Annotate the CommonJS export names for ESM import in node:
|
|
333
389
|
0 && (module.exports = {
|
|
334
390
|
MikroBackendProvider,
|
|
335
|
-
gqlToMikro
|
|
336
|
-
mapAndAssignKeys,
|
|
337
|
-
visitPathForPopulate
|
|
391
|
+
gqlToMikro
|
|
338
392
|
});
|
|
393
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/base-resolver/provider.ts"],
|
|
4
|
+
"sourcesContent": ["import { BackendProvider, PaginationOptions } from '@exogee/graphweaver';\nimport { logger } from '@exogee/logger';\n\nimport {\n\tFilterQuery,\n\tLockMode,\n\tQueryFlag,\n\tReferenceType,\n\tSqlEntityRepository,\n\tUtils,\n\tConnectionManager,\n\texternalIdFieldMap,\n\tAnyEntity,\n} from '..';\nimport { OptimisticLockError } from '../utils/errors';\nimport { assign } from './assign';\n\nconst objectOperations = new Set(['_and', '_or', '_not']);\nconst mikroObjectOperations = new Set(['$and', '$or', '$not']);\nconst nonJoinKeys = new Set([\n\t'$and',\n\t'$gt',\n\t'$gte',\n\t'$in',\n\t'$lt',\n\t'$lte',\n\t'$ne',\n\t'$nin',\n\t'$not',\n\t'$or',\n\t'$like',\n\t'$ilike',\n\t'$null',\n\t'$notnull',\n\t'id', // @todo: remove this? Why is it here?\n]);\n\nconst appendPath = (path: string, newPath: string) =>\n\tpath.length ? `${path}.${newPath}` : newPath;\n\nexport const gqlToMikro: (filter: any) => any = (filter: any) => {\n\tif (Array.isArray(filter)) {\n\t\treturn filter.map((element) => gqlToMikro(element));\n\t} else if (typeof filter === 'object') {\n\t\tfor (const key of Object.keys(filter)) {\n\t\t\t// A null here is a user-specified value and is valid to filter on\n\t\t\tif (filter[key] === null) continue;\n\n\t\t\tif (objectOperations.has(key)) {\n\t\t\t\t// { _not: '1' } => { $not: '1' }\n\t\t\t\tfilter[key.replace('_', '$')] = gqlToMikro(filter[key]);\n\t\t\t\tdelete filter[key];\n\t\t\t} else if (typeof filter[key] === 'object' && !Array.isArray(filter[key])) {\n\t\t\t\t// Recurse over nested filters only (arrays are an argument to a filter, not a nested filter)\n\t\t\t\tfilter[key] = gqlToMikro(filter[key]);\n\t\t\t} else if (key.indexOf('_') >= 0) {\n\t\t\t\t// { firstName_in: ['k', 'b'] } => { firstName: { $in: ['k', 'b'] } }\n\t\t\t\tconst [newKey, operator] = key.split('_');\n\t\t\t\tconst newValue = { [`$${operator}`]: gqlToMikro(filter[key]) };\n\n\t\t\t\t// They can construct multiple filters for the same key. In that case we need\n\t\t\t\t// to append them all into an object.\n\t\t\t\tif (typeof filter[newKey] !== 'undefined') {\n\t\t\t\t\tfilter[newKey] = { ...filter[newKey], ...newValue };\n\t\t\t\t} else {\n\t\t\t\t\tfilter[newKey] = newValue;\n\t\t\t\t}\n\n\t\t\t\tdelete filter[key];\n\t\t\t}\n\t\t}\n\t}\n\treturn filter;\n};\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport class MikroBackendProvider<T extends {}> implements BackendProvider<T> {\n\tprivate _backendId: string;\n\n\tpublic entityType: new () => T;\n\tpublic connectionManagerId?: string;\n\n\tpublic readonly supportsInFilter = true;\n\n\tget backendId() {\n\t\treturn this._backendId;\n\t}\n\n\tprivate get database() {\n\t\t// If we have a connection manager ID then use that else fallback to the Database\n\t\tif (!this.connectionManagerId) return ConnectionManager.default;\n\t\treturn ConnectionManager.database(this.connectionManagerId) || ConnectionManager.default;\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get transactional() {\n\t\treturn this.database.transactional;\n\t}\n\n\t// This is exposed for use in the RLS package\n\tpublic get em() {\n\t\treturn this.database.em;\n\t}\n\n\tprivate getRepository: () => SqlEntityRepository<T> = () => {\n\t\tconst repository = this.database.em.getRepository<T>(this.entityType);\n\t\tif (!repository) throw new Error('Could not find repository for ' + this.entityType.name);\n\n\t\treturn repository as SqlEntityRepository<T>;\n\t};\n\n\tpublic constructor(mikroType: new () => T, connectionManagerId?: string) {\n\t\tthis.entityType = mikroType;\n\t\tthis.connectionManagerId = connectionManagerId;\n\t\tthis._backendId = `mikro-orm-${connectionManagerId || ''}`;\n\t}\n\n\tprivate mapAndAssignKeys = <T>(result: T, entityType: new () => T, inputArgs: Partial<T>) => {\n\t\t// Clean the input and remove any GraphQL classes from the object\n\t\t// const cleanInput = JSON.parse(JSON.stringify(inputArgs));\n\t\tconst assignmentObj = this.applyExternalIdFields(entityType, inputArgs);\n\t\treturn assign(result, assignmentObj, undefined, undefined, this.database.em);\n\t};\n\n\tprivate applyExternalIdFields = (target: AnyEntity | string, values: any) => {\n\t\tconst targetName = typeof target === 'string' ? target : target.name;\n\t\tconst map = externalIdFieldMap.get(targetName);\n\n\t\tconst mapFieldNames = (partialFilterObj: any) => {\n\t\t\tfor (const [from, to] of Object.entries(map || {})) {\n\t\t\t\tif (partialFilterObj[from] && typeof partialFilterObj[from].id !== 'undefined') {\n\t\t\t\t\tif (Object.keys(partialFilterObj[from]).length > 1) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected precisely 1 key called 'id' in queryObj.${from} on ${target}, got ${JSON.stringify(\n\t\t\t\t\t\t\t\tpartialFilterObj[from],\n\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t4\n\t\t\t\t\t\t\t)}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tpartialFilterObj[to] = partialFilterObj[from].id;\n\t\t\t\t\tdelete partialFilterObj[from];\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Check for and/or/etc at the root level and handle correctly\n\t\tfor (const rootLevelKey of Object.keys(values)) {\n\t\t\tif (mikroObjectOperations.has(rootLevelKey)) {\n\t\t\t\tfor (const field of values[rootLevelKey]) {\n\t\t\t\t\tmapFieldNames(field);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Map the rest of the field names as well\n\t\tmapFieldNames(values);\n\n\t\t// Traverse the nested entities\n\t\tconst { properties } = this.database.em.getMetadata().get(targetName);\n\t\tObject.values(properties)\n\t\t\t.filter((property) => typeof property.entity !== 'undefined' && values[property.name])\n\t\t\t.forEach((property) => {\n\t\t\t\tif (Array.isArray(values[property.name])) {\n\t\t\t\t\tvalues[property.name].forEach((value: any) =>\n\t\t\t\t\t\tthis.applyExternalIdFields(property.type, value)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvalues[property.name] = this.applyExternalIdFields(property.type, values[property.name]);\n\t\t\t\t}\n\t\t\t});\n\n\t\treturn values;\n\t};\n\n\t// Check if we have any keys that are a collection of entities\n\tpublic visitPathForPopulate = (entityName: string, updateArgBranch: any, populateBranch = '') => {\n\t\tconst { properties } = this.database.em.getMetadata().get(entityName);\n\t\tconst collectedPaths = populateBranch ? new Set<string>([populateBranch]) : new Set<string>([]);\n\n\t\tfor (const [key, value] of Object.entries(updateArgBranch ?? {})) {\n\t\t\tif (\n\t\t\t\t// If it's a relationship, go ahead and and '.' it in, recurse.\n\t\t\t\tproperties[key]?.reference === ReferenceType.ONE_TO_ONE ||\n\t\t\t\tproperties[key]?.reference === ReferenceType.ONE_TO_MANY ||\n\t\t\t\tproperties[key]?.reference === ReferenceType.MANY_TO_ONE ||\n\t\t\t\tproperties[key]?.reference === ReferenceType.MANY_TO_MANY\n\t\t\t) {\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t// In the case where the array is empty we also need to make sure we load the collection.\n\t\t\t\t\tcollectedPaths.add(appendPath(populateBranch, key));\n\n\t\t\t\t\tfor (const entry of value) {\n\t\t\t\t\t\t// Recurse\n\t\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof value === 'object') {\n\t\t\t\t\t// Recurse\n\t\t\t\t\tconst newPaths = this.visitPathForPopulate(\n\t\t\t\t\t\tproperties[key].type,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tappendPath(populateBranch, key)\n\t\t\t\t\t);\n\t\t\t\t\tnewPaths.forEach((path) => collectedPaths.add(path));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn collectedPaths;\n\t};\n\n\tprivate applyWhereClause(where: any) {\n\t\tconst query = this.getRepository().createQueryBuilder();\n\t\tconst joinKeysUsed = new Map<string, number>();\n\n\t\tif (where) {\n\t\t\tconst visit = (current: any, table = 'e0') => {\n\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\tfor (const element of current) {\n\t\t\t\t\t\tvisit(element, table);\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof current === 'object') {\n\t\t\t\t\tfor (const key of Object.keys(current)) {\n\t\t\t\t\t\tconst shouldJoin =\n\t\t\t\t\t\t\tcurrent[key] !== null &&\n\t\t\t\t\t\t\ttypeof current[key] === 'object' &&\n\t\t\t\t\t\t\tObject.keys(current[key]).filter((key) => !nonJoinKeys.has(key)).length > 0;\n\n\t\t\t\t\t\t// Only join if it's not $and, $or, $not, and if it's one of those object operations\n\t\t\t\t\t\t// pass the parent and current table on down without any change.\n\t\t\t\t\t\tif (mikroObjectOperations.has(key)) {\n\t\t\t\t\t\t\tvisit(current[key], table);\n\t\t\t\t\t\t} else if (shouldJoin) {\n\t\t\t\t\t\t\t// Otherwise ensure we've actually got a full on nested object,\n\t\t\t\t\t\t\t// not just a filter property.\n\t\t\t\t\t\t\tconst keyUseCount = joinKeysUsed.has(key) ? (joinKeysUsed.get(key) ?? 0) + 1 : 1;\n\t\t\t\t\t\t\tconst joinKey = joinKeysUsed.has(key) ? `${key}${keyUseCount}` : key;\n\t\t\t\t\t\t\tquery.leftJoin(`${table}.${key}`, joinKey);\n\t\t\t\t\t\t\t// Certain filters can result in the same table being joined\n\t\t\t\t\t\t\t// on different criteria - keep track and avoid using the same alias\n\t\t\t\t\t\t\tjoinKeysUsed.set(joinKey, keyUseCount);\n\t\t\t\t\t\t\tvisit(current[key], key);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Filter out empty objects\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tcurrent[key] !== null &&\n\t\t\t\t\t\t\ttypeof current[key] === 'object' &&\n\t\t\t\t\t\t\tObject.keys(current[key]).length === 0\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tdelete current[key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tvisit(where);\n\n\t\t\tif (Object.keys(where).length > 0) {\n\t\t\t\tquery.andWhere(where);\n\t\t\t}\n\t\t}\n\n\t\treturn query;\n\t}\n\n\tpublic async find(\n\t\tfilter: any, // @todo: Create a type for this\n\t\tpagination?: PaginationOptions,\n\t\tadditionalOptionsForBackend?: any // @todo: Create a type for this\n\t): Promise<T[]> {\n\t\tlogger.trace(`Running find ${this.entityType.name} with filter`, {\n\t\t\tfilter: JSON.stringify(filter),\n\t\t});\n\n\t\t// Strip custom types out of the equation.\n\t\t// This query only works if we JSON.parse(JSON.stringify(filter)):\n\t\t//\n\t\t// query {\n\t\t// drivers (filter: { region: { name: \"North Shore\" }}) {\n\t\t// id\n\t\t// }\n\t\t// }\n\t\tconst where = filter ? gqlToMikro(JSON.parse(JSON.stringify(filter))) : undefined;\n\n\t\t// Convert from: { account: {id: '6' }}\n\t\t// to { accountId: '6' }\n\t\t// This conversion only works on root level objects\n\t\tconst whereWithAppliedExternalIdFields =\n\t\t\twhere && this.applyExternalIdFields(this.entityType, where);\n\n\t\t// Regions need some fancy handling with Query Builder. Process the where further\n\t\t// and return a Query Builder instance.\n\t\tconst query = this.applyWhereClause(whereWithAppliedExternalIdFields);\n\n\t\t// If we have specified a limit, offset or order then update the query\n\t\tpagination?.limit && query.limit(pagination.limit);\n\t\tpagination?.offset && query.offset(pagination.offset);\n\t\tpagination?.orderBy && query.orderBy({ ...pagination.orderBy });\n\n\t\t// Certain query filters can result in duplicate records once all joins are resolved\n\t\t// These duplicates can be discarded as related entities are returned to the\n\t\t// API consumer via field resolvers\n\t\tquery.setFlag(QueryFlag.DISTINCT);\n\n\t\t// 1:1 relations that aren't on the owning side need to get populated so the references get set.\n\t\t// This method is protected, but we need to use it from here, hence the `as any`.\n\t\tconst driver = this.database.em.getDriver();\n\t\tconst meta = this.database.em.getMetadata().get(this.entityType.name);\n\t\tquery.populate((driver as any).autoJoinOneToOneOwner(meta, []));\n\n\t\tif (additionalOptionsForBackend?.populate) {\n\t\t\tquery.populate(additionalOptionsForBackend.populate);\n\t\t}\n\n\t\tconst result = await query.getResult();\n\t\tlogger.trace(`find ${this.entityType.name} result: ${result.length} rows`);\n\n\t\treturn result;\n\t}\n\n\tpublic async findOne(id: string): Promise<T | null> {\n\t\tlogger.trace(`Running findOne ${this.entityType.name} with ID ${id}`);\n\n\t\tconst result = await this.database.em.findOne(this.entityType, id);\n\n\t\tlogger.trace(`findOne ${this.entityType.name} result`, { result });\n\n\t\treturn result;\n\t}\n\n\tpublic async findByRelatedId(\n\t\tentity: any,\n\t\trelatedField: string,\n\t\trelatedFieldIds: string[],\n\t\tfilter?: any\n\t): Promise<T[]> {\n\t\tconst queryFilter = {\n\t\t\t$and: [{ [relatedField]: { $in: relatedFieldIds } }, ...[filter ?? []]],\n\t\t};\n\n\t\tconst populate = [relatedField as `${string}.`];\n\t\tconst result = (await this.database.em.find(entity, queryFilter, { populate })) as unknown[];\n\n\t\treturn result as T[];\n\t}\n\n\tpublic async updateOne(id: string, updateArgs: Partial<T & { version?: number }>): Promise<T> {\n\t\tlogger.trace(`Running update ${this.entityType.name} with args`, {\n\t\t\tid,\n\t\t\tupdateArgs: JSON.stringify(updateArgs),\n\t\t});\n\n\t\tconst entity = await this.database.em.findOne(this.entityType, id, {\n\t\t\t// This is an optimisation so that assign() doesn't have to go fetch everything one at a time.\n\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, updateArgs)] as `${string}.`[],\n\t\t});\n\n\t\tif (entity === null) {\n\t\t\tthrow new Error(`Unable to locate ${this.entityType.name} with ID: '${id}' for updating.`);\n\t\t}\n\n\t\t// If a version has been sent, let's check it\n\t\tif (updateArgs?.version) {\n\t\t\ttry {\n\t\t\t\tawait this.database.em.lock(entity, LockMode.OPTIMISTIC, updateArgs.version);\n\t\t\t\tdelete updateArgs.version;\n\t\t\t} catch (err) {\n\t\t\t\tthrow new OptimisticLockError((err as Error)?.message, { entity });\n\t\t\t}\n\t\t}\n\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, updateArgs);\n\t\tawait this.getRepository().persistAndFlush(entity);\n\n\t\tlogger.trace(`update ${this.entityType.name} entity`, entity);\n\n\t\treturn entity;\n\t}\n\n\tpublic async updateMany(updateItems: (Partial<T> & { id: string })[]): Promise<T[]> {\n\t\tlogger.trace(`Running update many ${this.entityType.name} with args`, {\n\t\t\tupdateItems: JSON.stringify(updateItems),\n\t\t});\n\n\t\tconst entities = await this.database.transactional<T[]>(async () => {\n\t\t\treturn Promise.all<T>(\n\t\t\t\tupdateItems.map(async (item) => {\n\t\t\t\t\tif (!item?.id) throw new Error('You must pass an ID for this entity to update it.');\n\n\t\t\t\t\t// Find the entity in the database\n\t\t\t\t\tconst entity = await this.database.em.findOneOrFail(this.entityType, item.id, {\n\t\t\t\t\t\tpopulate: [...this.visitPathForPopulate(this.entityType.name, item)] as `${string}.`[],\n\t\t\t\t\t});\n\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace(`updated ${this.entityType.name} items `, entities);\n\n\t\treturn entities;\n\t}\n\n\tpublic async createOrUpdateMany(items: Partial<T>[]): Promise<T[]> {\n\t\tlogger.trace(`Running create or update many for ${this.entityType.name} with args`, {\n\t\t\titems: JSON.stringify(items),\n\t\t});\n\n\t\tconst entities = await this.database.transactional<T[]>(async () => {\n\t\t\treturn Promise.all<T>(\n\t\t\t\titems.map(async (item) => {\n\t\t\t\t\tlet entity;\n\t\t\t\t\tconst { id } = item as any;\n\t\t\t\t\tif (id) {\n\t\t\t\t\t\tentity = await this.database.em.findOneOrFail(this.entityType, id, {\n\t\t\t\t\t\t\tpopulate: [\n\t\t\t\t\t\t\t\t...this.visitPathForPopulate(this.entityType.name, item),\n\t\t\t\t\t\t\t] as `${string}.`[],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlogger.trace(`Running update on ${this.entityType.name} with item`, {\n\t\t\t\t\t\t\titem: JSON.stringify(item),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tentity = new this.entityType();\n\t\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\t\tlogger.trace(`Running create on ${this.entityType.name} with item`, {\n\t\t\t\t\t\t\titem: JSON.stringify(item),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace(`created or updated ${this.entityType.name} items `, entities);\n\n\t\treturn entities;\n\t}\n\n\tpublic async createOne(createArgs: Partial<T>): Promise<T> {\n\t\tlogger.trace(`Running create ${this.entityType.name} with args`, {\n\t\t\tcreateArgs: JSON.stringify(createArgs),\n\t\t});\n\n\t\tconst entity = new this.entityType();\n\t\tawait this.mapAndAssignKeys(entity, this.entityType, createArgs);\n\t\tawait this.getRepository().persistAndFlush(entity);\n\n\t\tlogger.trace(`create ${this.entityType.name} result`, entity);\n\n\t\treturn entity;\n\t}\n\n\tpublic async createMany(createItems: Partial<T>[]): Promise<T[]> {\n\t\tlogger.trace(`Running create ${this.entityType.name} with args`, {\n\t\t\tcreateArgs: JSON.stringify(createItems),\n\t\t});\n\n\t\tconst entities = await this.database.transactional<T[]>(async () => {\n\t\t\treturn Promise.all<T>(\n\t\t\t\tcreateItems.map(async (item) => {\n\t\t\t\t\tconst entity = new this.entityType();\n\t\t\t\t\tawait this.mapAndAssignKeys(entity, this.entityType, item);\n\t\t\t\t\tthis.database.em.persist(entity);\n\t\t\t\t\treturn entity;\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\n\t\tlogger.trace(`created ${this.entityType.name} items `, entities);\n\n\t\treturn entities;\n\t}\n\n\tpublic async deleteOne(id: string): Promise<boolean> {\n\t\tlogger.trace(`Running delete ${this.entityType.name} with id ${id}`);\n\t\tconst deletedRows = await this.getRepository().nativeDelete({\n\t\t\tid,\n\t\t} as unknown as FilterQuery<T>);\n\n\t\tif (deletedRows > 1) {\n\t\t\tthrow new Error('Multiple deleted rows');\n\t\t}\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn deletedRows === 1;\n\t}\n\n\tpublic async deleteMany(ids: string[]): Promise<boolean> {\n\t\tlogger.trace(`Running delete ${this.entityType.name} with ids ${ids}`);\n\n\t\tconst deletedRows = await this.database.transactional<number>(async () => {\n\t\t\tconst deletedCount = await this.getRepository().nativeDelete({\n\t\t\t\tid: { $in: ids },\n\t\t\t} as FilterQuery<any>); // We can remove this cast when Typescript knows that T has an `id` property.\n\n\t\t\tif (deletedCount !== ids.length) {\n\t\t\t\tthrow new Error('We did not delete all the rows, rolling back');\n\t\t\t}\n\n\t\t\treturn deletedCount;\n\t\t});\n\n\t\tlogger.trace(`delete ${this.entityType.name} result: deleted ${deletedRows} row(s)`);\n\n\t\treturn deletedRows === ids.length;\n\t}\n\n\tpublic getRelatedEntityId(entity: any, relatedIdField: string) {\n\t\tif (typeof entity === 'string') {\n\t\t\treturn entity;\n\t\t}\n\t\tif (entity.id) {\n\t\t\treturn entity.id;\n\t\t}\n\t\t// No need to unwrap in Mikroorm version 5\n\t\tthrow new Error(`Unknown entity without an id: ${JSON.stringify(entity)}`);\n\t}\n\n\tpublic isCollection(entity: any) {\n\t\treturn Utils.isCollection(entity);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAEvB,eAUO;AACP,oBAAoC;AACpC,oBAAuB;AAEvB,MAAM,mBAAmB,oBAAI,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;AACxD,MAAM,wBAAwB,oBAAI,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;AAC7D,MAAM,cAAc,oBAAI,IAAI;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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A,EACjC;AACD;",
|
|
6
|
+
"names": ["key"]
|
|
7
|
+
}
|
package/lib/config.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/config.ts"],
|
|
4
|
+
"sourcesContent": ["import { logger } from '@exogee/logger';\n\nexport const requireEnvironmentVariable = (\n\tenvStr: string,\n\twarnOnly?: boolean\n): string | undefined => {\n\tconst envVar = process.env[envStr];\n\tif (!envVar) {\n\t\tif (warnOnly) {\n\t\t\tlogger.warn(`${envStr} is required in environment.`);\n\t\t\treturn;\n\t\t}\n\t\tthrow new Error(`${envStr} required but not found.`);\n\t}\n\treturn envVar;\n};\n\nexport const config = {};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAEhB,MAAM,6BAA6B,CACzC,QACA,aACwB;AACxB,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,CAAC,QAAQ;AACZ,QAAI,UAAU;AACb,2BAAO,KAAK,GAAG,oCAAoC;AACnD;AAAA,IACD;AACA,UAAM,IAAI,MAAM,GAAG,gCAAgC;AAAA,EACpD;AACA,SAAO;AACR;AAEO,MAAM,SAAS,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/database.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { EntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
|
|
5
5
|
export interface ConnectionOptions {
|
|
6
6
|
mikroOrmConfig?: Options;
|
|
7
7
|
secretArn?: string;
|
|
8
|
+
connectionManagerId?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare enum IsolationLevel {
|
|
10
11
|
SERIALIZABLE = "SERIALIZABLE",
|
|
@@ -26,8 +27,12 @@ declare class DatabaseImplementation {
|
|
|
26
27
|
connect: (connectionOptions?: ConnectionOptions) => Promise<MikroORM<IDatabaseDriver<Connection>>>;
|
|
27
28
|
close: () => Promise<void>;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
declare class ConnectionsManager {
|
|
31
|
+
private connections;
|
|
32
|
+
constructor();
|
|
33
|
+
get default(): DatabaseImplementation;
|
|
34
|
+
connect: (id: string, connectionOptions?: ConnectionOptions) => Promise<DatabaseImplementation | undefined>;
|
|
35
|
+
database(id: string): DatabaseImplementation | undefined;
|
|
36
|
+
}
|
|
37
|
+
export declare const ConnectionManager: ConnectionsManager;
|
|
33
38
|
export {};
|
package/lib/database.js
CHANGED
|
@@ -18,11 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var database_exports = {};
|
|
20
20
|
__export(database_exports, {
|
|
21
|
-
|
|
22
|
-
IsolationLevel: () => IsolationLevel
|
|
23
|
-
checkDatabase: () => checkDatabase,
|
|
24
|
-
clearDatabaseContext: () => clearDatabaseContext,
|
|
25
|
-
getDbSchema: () => getDbSchema
|
|
21
|
+
ConnectionManager: () => ConnectionManager,
|
|
22
|
+
IsolationLevel: () => IsolationLevel
|
|
26
23
|
});
|
|
27
24
|
module.exports = __toCommonJS(database_exports);
|
|
28
25
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -176,28 +173,37 @@ class DatabaseImplementation {
|
|
|
176
173
|
return this.em.getDriver().getConnection();
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
176
|
+
class ConnectionsManager {
|
|
177
|
+
constructor() {
|
|
178
|
+
this.connect = async (id, connectionOptions) => {
|
|
179
|
+
if (this.connections.has(id))
|
|
180
|
+
return this.connections.get(id);
|
|
181
|
+
const database = new DatabaseImplementation();
|
|
182
|
+
if (connectionOptions)
|
|
183
|
+
await database.connect(connectionOptions);
|
|
184
|
+
import_logger.logger.trace(`Saving database connection with id "${id}".`);
|
|
185
|
+
this.connections.set(id, database);
|
|
186
|
+
};
|
|
187
|
+
this.connections = /* @__PURE__ */ new Map();
|
|
188
|
+
}
|
|
189
|
+
get default() {
|
|
190
|
+
const [defaultConnection] = [...this.connections];
|
|
191
|
+
if (!defaultConnection)
|
|
192
|
+
throw new Error(
|
|
193
|
+
"Error: No database connections. There should be at least one database connection."
|
|
194
|
+
);
|
|
195
|
+
const [_, databaseConnection] = defaultConnection;
|
|
196
|
+
return databaseConnection;
|
|
197
|
+
}
|
|
198
|
+
database(id) {
|
|
199
|
+
import_logger.logger.trace(`Finding database connection for id "${id}"`);
|
|
200
|
+
return this.connections.get(id);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const ConnectionManager = new ConnectionsManager();
|
|
196
204
|
// Annotate the CommonJS export names for ESM import in node:
|
|
197
205
|
0 && (module.exports = {
|
|
198
|
-
|
|
199
|
-
IsolationLevel
|
|
200
|
-
checkDatabase,
|
|
201
|
-
clearDatabaseContext,
|
|
202
|
-
getDbSchema
|
|
206
|
+
ConnectionManager,
|
|
207
|
+
IsolationLevel
|
|
203
208
|
});
|
|
209
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/database.ts"],
|
|
4
|
+
"sourcesContent": ["import 'reflect-metadata';\nimport './utils/change-tracker';\n\nimport {\n\tAnyEntity,\n\tConnection,\n\tEntityName,\n\tIDatabaseDriver,\n\tMikroORM,\n\tOptions,\n\tReflectMetadataProvider,\n} from '@mikro-orm/core';\nimport { EntityManager, PostgreSqlDriver } from '@mikro-orm/postgresql';\nimport { logger } from '@exogee/logger';\n//import AWS from 'aws-sdk';\n\nexport interface ConnectionOptions {\n\tmikroOrmConfig?: Options;\n\tsecretArn?: string;\n\tconnectionManagerId?: string;\n}\n\nexport enum IsolationLevel {\n\tSERIALIZABLE = 'SERIALIZABLE',\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\tREAD_COMMITTED = 'READ COMMITTED',\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n}\n\nconst NumericIsolationLevels = {\n\t[IsolationLevel.SERIALIZABLE]: 4,\n\t[IsolationLevel.REPEATABLE_READ]: 3,\n\t[IsolationLevel.READ_COMMITTED]: 2,\n\t[IsolationLevel.READ_UNCOMMITTED]: 1,\n};\n\nclass DatabaseImplementation {\n\tprivate cachedOrm?: MikroORM<IDatabaseDriver<Connection>>;\n\tprivate transactionalEm?: EntityManager;\n\tprivate transactionInProgressIsolationLevel?: IsolationLevel;\n\n\tpublic get orm() {\n\t\tif (!this.cachedOrm) {\n\t\t\tconst error = new Error('Tried to get the ORM before it was connected.');\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn this.cachedOrm;\n\t}\n\n\tpublic get em() {\n\t\treturn (this.transactionalEm || this.orm.em) as EntityManager<PostgreSqlDriver>;\n\t}\n\n\tpublic async transactional<T>(\n\t\tcallback: () => Promise<T>,\n\t\tisolationLevel: IsolationLevel = IsolationLevel.READ_COMMITTED\n\t) {\n\t\tlogger.trace('Database::transactional() enter');\n\n\t\tif (\n\t\t\tthis.transactionInProgressIsolationLevel &&\n\t\t\tNumericIsolationLevels[this.transactionInProgressIsolationLevel] <\n\t\t\t\tNumericIsolationLevels[isolationLevel]\n\t\t) {\n\t\t\tconst error = new Error(\n\t\t\t\t`Transaction in progress is ${this.transactionInProgressIsolationLevel} isolation level, but ${isolationLevel} was requested, which is more restrictive. Since we can't upgrade, this is an error.`\n\t\t\t);\n\t\t\tlogger.error(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (this.transactionalEm) {\n\t\t\t// Transaction is already in progress that is isolated enough. Run the callback without starting a new one.\n\t\t\tlogger.trace(\n\t\t\t\t'Transaction already in progress with sufficient isolation, proceeding without new transaction.'\n\t\t\t);\n\n\t\t\treturn callback();\n\t\t} else {\n\t\t\t// Ok, start a new one.\n\t\t\tlogger.trace('Starting transaction');\n\n\t\t\treturn this.em.transactional(async (em) => {\n\t\t\t\tthis.transactionalEm = em;\n\t\t\t\tthis.transactionInProgressIsolationLevel = isolationLevel;\n\t\t\t\tawait em.execute(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`);\n\t\t\t\tlet result: T;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await callback();\n\t\t\t\t} finally {\n\t\t\t\t\tdelete this.transactionalEm;\n\t\t\t\t\tdelete this.transactionInProgressIsolationLevel;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic isolatedTest(test: () => any) {\n\t\treturn async () => {\n\t\t\ttry {\n\t\t\t\tawait this.transactional(async () => {\n\t\t\t\t\tawait test();\n\t\t\t\t\tthrow new Error('Rollback transaction for test');\n\t\t\t\t}, IsolationLevel.SERIALIZABLE);\n\t\t\t} catch (error) {\n\t\t\t\t// Only need to care if this isn't our rollback from above.\n\t\t\t\t// Otherwise just gobble it.\n\t\t\t\tif ((error as Error).message !== 'Rollback transaction for test') {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic get rawConnection() {\n\t\treturn this.em.getDriver().getConnection();\n\t}\n\n\tprivate getConnectionInfo = async (connectionOptions?: ConnectionOptions): Promise<Options> => {\n\t\tlogger.trace('Database::getConnectionInfo() - Enter');\n\n\t\t// We have some defaults\n\t\tconst defaults: Options = {\n\t\t\thost: 'localhost',\n\t\t\tport: 5432,\n\t\t\tdbName: 'graphweaver',\n\t\t};\n\n\t\t// If we've been passed a secret then we need to get all this\n\t\t// info from Secrets Manager.\n\t\t/* let secret = {};\n\t\tconst secretArn = connectionOptions?.secretArn || process.env.DATABASE_SECRET_ARN;\n\n\t\tif (secretArn) {\n\t\t\tconst SecretsManager = new AWS.SecretsManager();\n\t\t\tlogger.trace('Fetching database connection info from Secrets Manager');\n\n\t\t\tconst result = await SecretsManager.getSecretValue({\n\t\t\t\tSecretId: secretArn,\n\t\t\t}).promise();\n\n\t\t\tlogger.trace('Got result from Secrets Manager');\n\n\t\t\tif (result.SecretString) {\n\t\t\t\tlogger.trace('Parsing result');\n\n\t\t\t\t// We only want certain properties from this secret.\n\t\t\t\tconst { host, port, username: user, password, dbname: dbName } = JSON.parse(\n\t\t\t\t\tresult.SecretString\n\t\t\t\t) as {\n\t\t\t\t\thost: string;\n\t\t\t\t\tport: number;\n\t\t\t\t\tusername: string;\n\t\t\t\t\tpassword: string;\n\t\t\t\t\tdbname: string;\n\t\t\t\t};\n\n\t\t\t\tsecret = { host, port, user, password, dbName };\n\t\t\t}\n\t\t} */\n\n\t\t// And finally we can override all of this with environment variables if needed.\n\t\tconst environmentOverrides: Options = {\n\t\t\thost: process.env.DATABASE_HOST,\n\t\t\tport: process.env.DATABASE_PORT ? parseInt(process.env.DATABASE_PORT) : undefined,\n\t\t\tuser: process.env.DATABASE_USERNAME,\n\t\t\tpassword: process.env.DATABASE_PASSWORD,\n\t\t\tdbName: process.env.DATABASE_NAME,\n\t\t};\n\n\t\t// Create a function we can use to filter out undefined values in the object.\n\t\tconst filterUndefined = (obj?: Options) => {\n\t\t\tif (!obj) return {};\n\n\t\t\tfor (const key of Object.keys(obj) as Array<keyof Options>) {\n\t\t\t\tif (obj[key] === undefined) delete obj[key];\n\t\t\t}\n\n\t\t\treturn obj;\n\t\t};\n\n\t\t// Apply each in order so the correct value wins.\n\t\treturn {\n\t\t\t...defaults,\n\t\t\t//...filterUndefined(secret),\n\t\t\t...filterUndefined(environmentOverrides),\n\t\t\t...filterUndefined(connectionOptions?.mikroOrmConfig),\n\t\t};\n\t};\n\n\tpublic getRepository = <T extends AnyEntity<T>>(entityName: EntityName<T>) =>\n\t\tthis.em.getRepository(entityName);\n\n\tpublic connect = async (connectionOptions?: ConnectionOptions) => {\n\t\tlogger.trace('Database::connect() - Enter');\n\n\t\tif (this.cachedOrm) {\n\t\t\tlogger.trace('Returning cached ORM');\n\t\t\treturn this.cachedOrm;\n\t\t}\n\n\t\tlogger.trace('Creating new ORM');\n\t\tlogger.trace('Getting connection info');\n\t\tconst params = await this.getConnectionInfo(connectionOptions);\n\n\t\tlogger.trace('Initialising ORM');\n\n\t\tlogger.trace(`${params.entities?.length}x entities`);\n\n\t\tconst orm = await MikroORM.init({\n\t\t\tdriver: PostgreSqlDriver,\n\t\t\tvalidateRequired: false, // Since v5, new entities are validated on runtime (just before executing insert queries), based on the entity metadata\n\n\t\t\timplicitTransactions: false,\n\t\t\tmetadataProvider: ReflectMetadataProvider,\n\t\t\tdiscovery: {\n\t\t\t\tdisableDynamicFileAccess: true,\n\t\t\t\trequireEntitiesArray: false,\n\t\t\t\twarnWhenNoEntities: false,\n\t\t\t},\n\t\t\tallowGlobalContext: true,\n\n\t\t\t// Ensure we only ever create one connection to the database.\n\t\t\tpool: {\n\t\t\t\tmin: 1,\n\t\t\t\tmax: 1,\n\t\t\t},\n\t\t\t...params,\n\t\t});\n\n\t\tlogger.trace('Creating connection to %s on %s', params.dbName, params.host);\n\t\tawait orm.connect();\n\n\t\tlogger.trace('Caching connection');\n\t\tthis.cachedOrm = orm;\n\t\treturn orm;\n\t};\n\n\tpublic close = async () => {\n\t\tlogger.trace('Closing database connection');\n\n\t\tawait this.orm.close();\n\t\tdelete this.cachedOrm;\n\t};\n}\n\nclass ConnectionsManager {\n\tprivate connections: Map<string, DatabaseImplementation>;\n\n\tconstructor() {\n\t\tthis.connections = new Map<string, DatabaseImplementation>();\n\t}\n\n\tget default(): DatabaseImplementation {\n\t\tconst [defaultConnection] = [...this.connections];\n\t\tif (!defaultConnection)\n\t\t\tthrow new Error(\n\t\t\t\t'Error: No database connections. There should be at least one database connection.'\n\t\t\t);\n\t\tconst [_, databaseConnection] = defaultConnection;\n\t\treturn databaseConnection;\n\t}\n\n\tpublic connect = async (id: string, connectionOptions?: ConnectionOptions) => {\n\t\tif (this.connections.has(id)) return this.connections.get(id);\n\t\tconst database = new DatabaseImplementation();\n\t\tif (connectionOptions) await database.connect(connectionOptions);\n\t\tlogger.trace(`Saving database connection with id \"${id}\".`);\n\t\tthis.connections.set(id, database);\n\t};\n\n\tpublic database(id: string) {\n\t\tlogger.trace(`Finding database connection for id \"${id}\"`);\n\t\treturn this.connections.get(id);\n\t}\n}\nexport const ConnectionManager = new ConnectionsManager();\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AACP,4BAAO;AAEP,kBAQO;AACP,wBAAgD;AAChD,oBAAuB;AAShB,IAAK,iBAAL,kBAAKA,oBAAL;AACN,EAAAA,gBAAA,kBAAe;AACf,EAAAA,gBAAA,qBAAkB;AAClB,EAAAA,gBAAA,oBAAiB;AACjB,EAAAA,gBAAA,sBAAmB;AAJR,SAAAA;AAAA,GAAA;AAOZ,MAAM,yBAAyB;AAAA,EAC9B,CAAC,oCAA8B;AAAA,EAC/B,CAAC,0CAAiC;AAAA,EAClC,CAAC,wCAAgC;AAAA,EACjC,CAAC,4CAAkC;AACpC;AAEA,MAAM,uBAAuB;AAAA,EAA7B;AAqFC,SAAQ,oBAAoB,OAAO,sBAA4D;AAC9F,2BAAO,MAAM,uCAAuC;AAGpD,YAAM,WAAoB;AAAA,QACzB,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA,MACT;AAoCA,YAAM,uBAAgC;AAAA,QACrC,MAAM,QAAQ,IAAI;AAAA,QAClB,MAAM,QAAQ,IAAI,gBAAgB,SAAS,QAAQ,IAAI,aAAa,IAAI;AAAA,QACxE,MAAM,QAAQ,IAAI;AAAA,QAClB,UAAU,QAAQ,IAAI;AAAA,QACtB,QAAQ,QAAQ,IAAI;AAAA,MACr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gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,IAAW,gBAAgB;AAC1B,WAAO,KAAK,GAAG,UAAU,EAAE,cAAc;AAAA,EAC1C;AAgID;AAEA,MAAM,mBAAmB;AAAA,EAGxB,cAAc;AAcd,SAAO,UAAU,OAAO,IAAY,sBAA0C;AAC7E,UAAI,KAAK,YAAY,IAAI,EAAE;AAAG,eAAO,KAAK,YAAY,IAAI,EAAE;AAC5D,YAAM,WAAW,IAAI,uBAAuB;AAC5C,UAAI;AAAmB,cAAM,SAAS,QAAQ,iBAAiB;AAC/D,2BAAO,MAAM,uCAAuC,MAAM;AAC1D,WAAK,YAAY,IAAI,IAAI,QAAQ;AAAA,IAClC;AAnBC,SAAK,cAAc,oBAAI,IAAoC;AAAA,EAC5D;AAAA,EAEA,IAAI,UAAkC;AACrC,UAAM,CAAC,iBAAiB,IAAI,CAAC,GAAG,KAAK,WAAW;AAChD,QAAI,CAAC;AACJ,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AACD,UAAM,CAAC,GAAG,kBAAkB,IAAI;AAChC,WAAO;AAAA,EACR;AAAA,EAUO,SAAS,IAAY;AAC3B,yBAAO,MAAM,uCAAuC,KAAK;AACzD,WAAO,KAAK,YAAY,IAAI,EAAE;AAAA,EAC/B;AACD;AACO,MAAM,oBAAoB,IAAI,mBAAmB;",
|
|
6
|
+
"names": ["IsolationLevel"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyEntity } from '@mikro-orm/core';
|
|
2
|
+
export type StringDictionary = {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const externalIdFieldMap: Map<string, StringDictionary>;
|
|
6
|
+
export declare const ExternalIdField: ({ from }: {
|
|
7
|
+
from: string;
|
|
8
|
+
}) => (target: AnyEntity, field: string) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var external_id_field_exports = {};
|
|
20
|
+
__export(external_id_field_exports, {
|
|
21
|
+
ExternalIdField: () => ExternalIdField,
|
|
22
|
+
externalIdFieldMap: () => externalIdFieldMap
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(external_id_field_exports);
|
|
25
|
+
const externalIdFieldMap = /* @__PURE__ */ new Map();
|
|
26
|
+
const ExternalIdField = ({ from }) => (target, field) => {
|
|
27
|
+
const existing = externalIdFieldMap.get(target.constructor.name) || {};
|
|
28
|
+
existing[from] = field;
|
|
29
|
+
externalIdFieldMap.set(target.constructor.name, existing);
|
|
30
|
+
};
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
ExternalIdField,
|
|
34
|
+
externalIdFieldMap
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=external-id-field.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/decorators/external-id-field.ts"],
|
|
4
|
+
"sourcesContent": ["// In some cases when linking across from CRM to GoCollect (or the other way around), it's very handy\n// to flatten entities from:\n//\n// job.account = { id : 'whatever' }\n//\n// to\n//\n// job.crmAccountId = 'whatever'\n//\n// This allows us to treat them consistently from an API standpoint\n// but actually store the values where they need to go.\n\nimport { AnyEntity } from '@mikro-orm/core';\n\nexport type StringDictionary = { [key: string]: string };\n\n// A map of classes to dictionary.\nexport const externalIdFieldMap = new Map<string, StringDictionary>();\n\nexport const ExternalIdField =\n\t({ from }: { from: string }) =>\n\t(target: AnyEntity, field: string) => {\n\t\tconst existing = externalIdFieldMap.get(target.constructor.name) || {};\n\t\texisting[from] = field;\n\t\texternalIdFieldMap.set(target.constructor.name, existing);\n\t};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,MAAM,qBAAqB,oBAAI,IAA8B;AAE7D,MAAM,kBACZ,CAAC,EAAE,KAAK,MACR,CAAC,QAAmB,UAAkB;AACrC,QAAM,WAAW,mBAAmB,IAAI,OAAO,YAAY,IAAI,KAAK,CAAC;AACrE,WAAS,QAAQ;AACjB,qBAAmB,IAAI,OAAO,YAAY,MAAM,QAAQ;AACzD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './external-id-field';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var decorators_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(decorators_exports);
|
|
18
|
+
__reExport(decorators_exports, require("./external-id-field"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/entities/audit-change.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tBigIntType,\n\tChangeSetType,\n\tCollection,\n\tEntity,\n\tEnum,\n\tIndex,\n\tOneToMany,\n\tPrimaryKey,\n\tProperty,\n} from '@mikro-orm/core';\n\nimport { AuditRelatedEntityChange } from './audit-related-entity-change';\nimport { BaseEntity } from './base-entity';\n\n@Entity()\n@Index({ properties: ['entityType', 'entityId'] })\nexport class AuditChange extends BaseEntity {\n\t@PrimaryKey({ type: BigIntType })\n\tid!: string;\n\n\t@Enum({ items: () => ChangeSetType, type: 'string' })\n\ttype!: ChangeSetType;\n\n\t@Property({ type: 'string' })\n\tentityId!: string;\n\n\t@Property({ type: 'string' })\n\tentityType!: string;\n\n\t@Property({ type: 'string' })\n\tcreatedBy!: string;\n\n\t@Property({ type: 'date' })\n\tcreatedAt: Date = new Date();\n\n\t@Property({ type: 'json', nullable: true })\n\tdata?: Record<string, unknown>;\n\n\t@OneToMany(() => AuditRelatedEntityChange, 'change')\n\trelatedEntityChanges?: Collection<AuditRelatedEntityChange>;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAUO;AAEP,yCAAyC;AACzC,yBAA2B;AAIpB,IAAM,cAAN,cAA0B,8BAAW;AAAA,EAArC;AAAA;AAiBN,qBAAkB,IAAI,KAAK;AAAA;AAO5B;AAtBC;AAAA,MADC,wBAAW,EAAE,MAAM,uBAAW,CAAC;AAAA,GADpB,YAEZ;AAGA;AAAA,MADC,kBAAK,EAAE,OAAO,MAAM,2BAAe,MAAM,SAAS,CAAC;AAAA,GAJxC,YAKZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAPhB,YAQZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAVhB,YAWZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAbhB,YAcZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAhBd,YAiBZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAnB9B,YAoBZ;AAGA;AAAA,MADC,uBAAU,MAAM,6DAA0B,QAAQ;AAAA,GAtBvC,YAuBZ;AAvBY,cAAN;AAAA,MAFN,oBAAO;AAAA,MACP,mBAAM,EAAE,YAAY,CAAC,cAAc,UAAU,EAAE,CAAC;AAAA,GACpC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/entities/audit-related-entity-change.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tBigIntType,\n\tEntity,\n\tIdentifiedReference,\n\tIndex,\n\tManyToOne,\n\tPrimaryKey,\n\tProperty,\n} from '@mikro-orm/core';\n\nimport { AuditChange } from './audit-change';\nimport { BaseEntity } from './base-entity';\n@Entity()\n@Index({ properties: ['relatedEntityType', 'relatedEntityId'] })\nexport class AuditRelatedEntityChange extends BaseEntity {\n\t@PrimaryKey({ type: BigIntType })\n\tid!: string;\n\n\t@ManyToOne(() => AuditChange, { onDelete: 'cascade', wrappedReference: true })\n\tchange!: IdentifiedReference<AuditChange>;\n\n\t@Property({ type: 'string' })\n\trelatedEntityType!: string;\n\n\t@Property({ type: 'string' })\n\trelatedEntityId!: string;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQO;AAEP,0BAA4B;AAC5B,yBAA2B;AAGpB,IAAM,2BAAN,cAAuC,8BAAW;AAYzD;AAVC;AAAA,MADC,wBAAW,EAAE,MAAM,uBAAW,CAAC;AAAA,GADpB,yBAEZ;AAGA;AAAA,MADC,uBAAU,MAAM,iCAAa,EAAE,UAAU,WAAW,kBAAkB,KAAK,CAAC;AAAA,GAJjE,yBAKZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAPhB,yBAQZ;AAGA;AAAA,MADC,sBAAS,EAAE,MAAM,SAAS,CAAC;AAAA,GAVhB,yBAWZ;AAXY,2BAAN;AAAA,MAFN,oBAAO;AAAA,MACP,mBAAM,EAAE,YAAY,CAAC,qBAAqB,iBAAiB,EAAE,CAAC;AAAA,GAClD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/entities/base-entity.ts"],
|
|
4
|
+
"sourcesContent": ["import { BaseDataEntity } from '@exogee/graphweaver';\nimport { Reference, Utils } from '@mikro-orm/core';\n\nexport class BaseEntity implements BaseDataEntity {\n\tpublic isReference(_: string, dataField: any) {\n\t\treturn Reference.isReference<any>(dataField);\n\t}\n\n\tpublic isCollection(fieldName: string, dataField: any) {\n\t\treturn Utils.isCollection<any>(dataField);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAiC;AAE1B,MAAM,WAAqC;AAAA,EAC1C,YAAY,GAAW,WAAgB;AAC7C,WAAO,sBAAU,YAAiB,SAAS;AAAA,EAC5C;AAAA,EAEO,aAAa,WAAmB,WAAgB;AACtD,WAAO,kBAAM,aAAkB,SAAS;AAAA,EACzC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/entities/index.js
CHANGED
|
@@ -18,3 +18,4 @@ module.exports = __toCommonJS(entities_exports);
|
|
|
18
18
|
__reExport(entities_exports, require("./audit-change"), module.exports);
|
|
19
19
|
__reExport(entities_exports, require("./audit-related-entity-change"), module.exports);
|
|
20
20
|
__reExport(entities_exports, require("./base-entity"), module.exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/entities/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './audit-change';\nexport * from './audit-related-entity-change';\nexport * from './base-entity';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,2BAAd;AACA,6BAAc,0CADd;AAEA,6BAAc,0BAFd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
export * from './base-resolver';
|
|
3
3
|
export * from './entities';
|
|
4
|
+
export * from './decorators';
|
|
4
5
|
export * from './database';
|
|
5
6
|
export * from './types';
|
|
6
7
|
export * from './utils/authentication-context';
|
|
7
8
|
export type { AnyEntity, ChangeSet, EntityData, EntityName, EventArgs, EventSubscriber, FilterQuery, FlushEventArgs, Loaded, QueryOrderMap, } from '@mikro-orm/core';
|
|
8
9
|
export type { LoadedReference } from '@mikro-orm/core';
|
|
9
10
|
export { ChangeSetType, Collection, DatabaseObjectNotFoundException, EntityManager, EntityRepository, LockMode, PrimaryKeyType, QueryFlag, QueryOrder, Reference, ReferenceType, Subscriber, UniqueConstraintViolationException, Utils, wrap, } from '@mikro-orm/core';
|
|
10
|
-
export {
|
|
11
|
+
export { SqlEntityRepository } from '@mikro-orm/postgresql';
|
package/lib/index.js
CHANGED
|
@@ -36,7 +36,6 @@ __export(src_exports, {
|
|
|
36
36
|
QueryOrder: () => import_core.QueryOrder,
|
|
37
37
|
Reference: () => import_core.Reference,
|
|
38
38
|
ReferenceType: () => import_core.ReferenceType,
|
|
39
|
-
SqlEntityManager: () => import_postgresql.SqlEntityManager,
|
|
40
39
|
SqlEntityRepository: () => import_postgresql.SqlEntityRepository,
|
|
41
40
|
Subscriber: () => import_core.Subscriber,
|
|
42
41
|
UniqueConstraintViolationException: () => import_core.UniqueConstraintViolationException,
|
|
@@ -48,6 +47,7 @@ var import_reflect_metadata = require("reflect-metadata");
|
|
|
48
47
|
var dotenv = __toESM(require("dotenv"));
|
|
49
48
|
__reExport(src_exports, require("./base-resolver"), module.exports);
|
|
50
49
|
__reExport(src_exports, require("./entities"), module.exports);
|
|
50
|
+
__reExport(src_exports, require("./decorators"), module.exports);
|
|
51
51
|
__reExport(src_exports, require("./database"), module.exports);
|
|
52
52
|
__reExport(src_exports, require("./types"), module.exports);
|
|
53
53
|
__reExport(src_exports, require("./utils/authentication-context"), module.exports);
|
|
@@ -69,10 +69,10 @@ dotenv.config({
|
|
|
69
69
|
QueryOrder,
|
|
70
70
|
Reference,
|
|
71
71
|
ReferenceType,
|
|
72
|
-
SqlEntityManager,
|
|
73
72
|
SqlEntityRepository,
|
|
74
73
|
Subscriber,
|
|
75
74
|
UniqueConstraintViolationException,
|
|
76
75
|
Utils,
|
|
77
76
|
wrap
|
|
78
77
|
});
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import 'reflect-metadata';\n\nimport * as dotenv from 'dotenv';\ndotenv.config({\n\tpath: `.env.${(process.env.NODE_ENV || 'development').toLowerCase()}`,\n}); // TODO: The path to .env file in pnpm workspaces seems to use the workspace package.json path. Need to ensure it uses the local version (if required)\n\nexport * from './base-resolver';\nexport * from './entities';\nexport * from './decorators';\nexport * from './database';\nexport * from './types';\nexport * from './utils/authentication-context';\n\n// Re-export from Mikro so things that depend on database entities can access helpers such as\n// Reference.isReference().\nexport type {\n\tAnyEntity,\n\tChangeSet,\n\tEntityData,\n\tEntityName,\n\tEventArgs,\n\tEventSubscriber,\n\tFilterQuery,\n\tFlushEventArgs,\n\tLoaded,\n\tQueryOrderMap,\n} from '@mikro-orm/core';\nexport type { LoadedReference } from '@mikro-orm/core';\nexport {\n\tChangeSetType,\n\tCollection,\n\tDatabaseObjectNotFoundException,\n\tEntityManager,\n\tEntityRepository,\n\tLockMode,\n\tPrimaryKeyType,\n\tQueryFlag,\n\tQueryOrder,\n\tReference,\n\tReferenceType,\n\tSubscriber,\n\tUniqueConstraintViolationException,\n\tUtils,\n\twrap,\n} from '@mikro-orm/core';\nexport { SqlEntityRepository } from '@mikro-orm/postgresql';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAEP,aAAwB;AAKxB,wBAAc,4BAPd;AAQA,wBAAc,uBARd;AASA,wBAAc,yBATd;AAUA,wBAAc,uBAVd;AAWA,wBAAc,oBAXd;AAYA,wBAAc,2CAZd;AA6BA,kBAgBO;AACP,wBAAoC;AA3CpC,OAAO,OAAO;AAAA,EACb,MAAM,SAAS,QAAQ,IAAI,YAAY,eAAe,YAAY;AACnE,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/types/date-type.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types/date-type.ts"],
|
|
4
|
+
"sourcesContent": ["import { EntityProperty, Platform, Type, ValidationError } from '@mikro-orm/core';\n\nconst DatePattern = /^\\d{4}-\\d{1,2}-\\d{1,2}$/;\n\nexport class DateType extends Type {\n\tconvertToDatabaseValue(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\n\t\tif (typeof value === 'string') {\n\t\t\tconst [date] = value.split('T');\n\t\t\tconst [year, month, day] = date.split('-');\n\t\t\treturn new Date(`${year}-${month}-${day}T00:00:00Z`);\n\t\t}\n\n\t\tthrow ValidationError.invalidType(DateType, value, 'JS');\n\t}\n\n\tconvertToJSValue(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\n\t\tif (typeof value === 'string' && DatePattern.test(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\tthrow ValidationError.invalidType(DateType, value, 'database');\n\t}\n\n\tgetColumnType(prop: EntityProperty, platform: Platform) {\n\t\treturn 'date';\n\t}\n\n\ttoJSON(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\t\tif (value instanceof Date) {\n\t\t\treturn `${value.getFullYear()}-${value.getMonth() + 1}-${value.getDate()}`;\n\t\t} else if (typeof value === 'string') {\n\t\t\treturn value;\n\t\t}\n\t\tthrow ValidationError.invalidType(DateType, value, 'JS');\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgE;AAEhE,MAAM,cAAc;AAEb,MAAM,iBAAiB,iBAAK;AAAA,EAClC,uBAAuB,OAAY,UAAoB;AACtD,QAAI,CAAC;AAAO,aAAO;AAEnB,QAAI,OAAO,UAAU,UAAU;AAC9B,YAAM,CAAC,IAAI,IAAI,MAAM,MAAM,GAAG;AAC9B,YAAM,CAAC,MAAM,OAAO,GAAG,IAAI,KAAK,MAAM,GAAG;AACzC,aAAO,IAAI,KAAK,GAAG,QAAQ,SAAS,eAAe;AAAA,IACpD;AAEA,UAAM,4BAAgB,YAAY,UAAU,OAAO,IAAI;AAAA,EACxD;AAAA,EAEA,iBAAiB,OAAY,UAAoB;AAChD,QAAI,CAAC;AAAO,aAAO;AAEnB,QAAI,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK,GAAG;AACzD,aAAO;AAAA,IACR;AAEA,UAAM,4BAAgB,YAAY,UAAU,OAAO,UAAU;AAAA,EAC9D;AAAA,EAEA,cAAc,MAAsB,UAAoB;AACvD,WAAO;AAAA,EACR;AAAA,EAEA,OAAO,OAAY,UAAoB;AACtC,QAAI,CAAC;AAAO,aAAO;AACnB,QAAI,iBAAiB,MAAM;AAC1B,aAAO,GAAG,MAAM,YAAY,KAAK,MAAM,SAAS,IAAI,KAAK,MAAM,QAAQ;AAAA,IACxE,WAAW,OAAO,UAAU,UAAU;AACrC,aAAO;AAAA,IACR;AACA,UAAM,4BAAgB,YAAY,UAAU,OAAO,IAAI;AAAA,EACxD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types/decimal-type.ts"],
|
|
4
|
+
"sourcesContent": ["import { EntityProperty, Platform, Type, ValidationError } from '@mikro-orm/core';\nimport { Decimal } from 'decimal.js';\n\nexport class DecimalType extends Type {\n\tconstructor(private readonly precision = 12, private readonly scale = 4) {\n\t\tsuper();\n\t}\n\n\tconvertToDatabaseValue(value: any, platform: Platform) {\n\t\tif (value == null) return value;\n\t\tif (value instanceof Decimal) {\n\t\t\tif (value.isNaN()) throw new Error('Decimal should not be NaN');\n\t\t\tif (!value.isFinite()) throw new Error('Decimal should be finite');\n\t\t\treturn value.toFixed(this.scale);\n\t\t}\n\t\tthrow ValidationError.invalidType(DecimalType, value, 'JS');\n\t}\n\n\tconvertToJSValue(value: any, platform: Platform) {\n\t\tif (value == null) return value;\n\t\tconst decimal = new Decimal(value);\n\n\t\tif (!decimal.isFinite()) throw new Error('Decimal should be finite');\n\n\t\treturn decimal;\n\t}\n\n\tgetColumnType(prop: EntityProperty, platform: Platform) {\n\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t}\n\n\ttoJSON(value: any, platform: Platform) {\n\t\tif (value === null || typeof value === 'undefined') return value;\n\t\tif (value instanceof Decimal) {\n\t\t\tif (value.isNaN()) throw new Error('Decimal should not be NaN');\n\t\t\tif (!value.isFinite()) throw new Error('Decimal should be finite');\n\t\t\treturn value.toNumber();\n\t\t}\n\t\tthrow ValidationError.invalidType(DecimalType, value, 'JS');\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgE;AAChE,qBAAwB;AAEjB,MAAM,oBAAoB,iBAAK;AAAA,EACrC,YAA6B,YAAY,IAAqB,QAAQ,GAAG;AACxE,UAAM;AADsB;AAAiC;AAAA,EAE9D;AAAA,EAEA,uBAAuB,OAAY,UAAoB;AACtD,QAAI,SAAS;AAAM,aAAO;AAC1B,QAAI,iBAAiB,wBAAS;AAC7B,UAAI,MAAM,MAAM;AAAG,cAAM,IAAI,MAAM,2BAA2B;AAC9D,UAAI,CAAC,MAAM,SAAS;AAAG,cAAM,IAAI,MAAM,0BAA0B;AACjE,aAAO,MAAM,QAAQ,KAAK,KAAK;AAAA,IAChC;AACA,UAAM,4BAAgB,YAAY,aAAa,OAAO,IAAI;AAAA,EAC3D;AAAA,EAEA,iBAAiB,OAAY,UAAoB;AAChD,QAAI,SAAS;AAAM,aAAO;AAC1B,UAAM,UAAU,IAAI,uBAAQ,KAAK;AAEjC,QAAI,CAAC,QAAQ,SAAS;AAAG,YAAM,IAAI,MAAM,0BAA0B;AAEnE,WAAO;AAAA,EACR;AAAA,EAEA,cAAc,MAAsB,UAAoB;AACvD,WAAO,WAAW,KAAK,cAAc,KAAK;AAAA,EAC3C;AAAA,EAEA,OAAO,OAAY,UAAoB;AACtC,QAAI,UAAU,QAAQ,OAAO,UAAU;AAAa,aAAO;AAC3D,QAAI,iBAAiB,wBAAS;AAC7B,UAAI,MAAM,MAAM;AAAG,cAAM,IAAI,MAAM,2BAA2B;AAC9D,UAAI,CAAC,MAAM,SAAS;AAAG,cAAM,IAAI,MAAM,0BAA0B;AACjE,aAAO,MAAM,SAAS;AAAA,IACvB;AACA,UAAM,4BAAgB,YAAY,aAAa,OAAO,IAAI;AAAA,EAC3D;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/types/index.js
CHANGED
package/lib/types/time-type.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types/time-type.ts"],
|
|
4
|
+
"sourcesContent": ["import { EntityProperty, Platform, Type, ValidationError } from '@mikro-orm/core';\n\nconst TimePattern = /^\\d{2}:\\d{2}:\\d{2}$/;\n\nexport class Time {\n\tconstructor(public readonly hour = 0, public readonly minute = 0, public readonly second = 0) {\n\t\tif (hour > 23 || hour < 0) throw new Error(`Invalid time '${hour}:${minute}:${second}`);\n\t\tif (minute > 59 || minute < 0) throw new Error(`Invalid time '${hour}:${minute}:${second}`);\n\t\tif (second > 59 || second < 0) throw new Error(`Invalid time '${hour}:${minute}:${second}`);\n\t}\n\n\tpublic toString() {\n\t\treturn `${this.hour.toString().padStart(2, '0')}:${this.minute\n\t\t\t.toString()\n\t\t\t.padStart(2, '0')}:${this.second.toString().padStart(2, '0')}`;\n\t}\n}\n\nexport class TimeType extends Type {\n\tconvertToDatabaseValue(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\t\tif (value instanceof Time) return value;\n\n\t\tthrow ValidationError.invalidType(TimeType, value, 'JS');\n\t}\n\n\tconvertToJSValue(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\n\t\tif (typeof value === 'string' && TimePattern.test(value)) {\n\t\t\tconst [hour, minute, second] = value.split(':');\n\t\t\treturn new Time(+hour, +minute, +second);\n\t\t}\n\n\t\tthrow ValidationError.invalidType(TimeType, value, 'database');\n\t}\n\n\tgetColumnType(prop: EntityProperty, platform: Platform) {\n\t\treturn 'time';\n\t}\n\n\ttoJSON(value: any, platform: Platform) {\n\t\tif (!value) return value;\n\t\tif (value instanceof Time) return Time.toString();\n\t\tthrow ValidationError.invalidType(TimeType, value, 'JS');\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgE;AAEhE,MAAM,cAAc;AAEb,MAAM,KAAK;AAAA,EACjB,YAA4B,OAAO,GAAmB,SAAS,GAAmB,SAAS,GAAG;AAAlE;AAA0B;AAA4B;AACjF,QAAI,OAAO,MAAM,OAAO;AAAG,YAAM,IAAI,MAAM,iBAAiB,QAAQ,UAAU,QAAQ;AACtF,QAAI,SAAS,MAAM,SAAS;AAAG,YAAM,IAAI,MAAM,iBAAiB,QAAQ,UAAU,QAAQ;AAC1F,QAAI,SAAS,MAAM,SAAS;AAAG,YAAM,IAAI,MAAM,iBAAiB,QAAQ,UAAU,QAAQ;AAAA,EAC3F;AAAA,EAEO,WAAW;AACjB,WAAO,GAAG,KAAK,KAAK,SAAS,EAAE,SAAS,GAAG,GAAG,KAAK,KAAK,OACtD,SAAS,EACT,SAAS,GAAG,GAAG,KAAK,KAAK,OAAO,SAAS,EAAE,SAAS,GAAG,GAAG;AAAA,EAC7D;AACD;AAEO,MAAM,iBAAiB,iBAAK;AAAA,EAClC,uBAAuB,OAAY,UAAoB;AACtD,QAAI,CAAC;AAAO,aAAO;AACnB,QAAI,iBAAiB;AAAM,aAAO;AAElC,UAAM,4BAAgB,YAAY,UAAU,OAAO,IAAI;AAAA,EACxD;AAAA,EAEA,iBAAiB,OAAY,UAAoB;AAChD,QAAI,CAAC;AAAO,aAAO;AAEnB,QAAI,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK,GAAG;AACzD,YAAM,CAAC,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,GAAG;AAC9C,aAAO,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM;AAAA,IACxC;AAEA,UAAM,4BAAgB,YAAY,UAAU,OAAO,UAAU;AAAA,EAC9D;AAAA,EAEA,cAAc,MAAsB,UAAoB;AACvD,WAAO;AAAA,EACR;AAAA,EAEA,OAAO,OAAY,UAAoB;AACtC,QAAI,CAAC;AAAO,aAAO;AACnB,QAAI,iBAAiB;AAAM,aAAO,KAAK,SAAS;AAChD,UAAM,4BAAgB,YAAY,UAAU,OAAO,IAAI;AAAA,EACxD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/authentication-context.ts"],
|
|
4
|
+
"sourcesContent": ["import { logger } from '@exogee/logger';\n\nclass AuthenticationContextImplementation {\n\tprivate currentUserLogin?: string;\n\n\tpublic clear() {\n\t\tthis.currentUserLogin = undefined;\n\t}\n\n\tpublic set(user: string) {\n\t\tlogger.trace(`Setting AuthenticationContext.currentUser to ${user}`);\n\t\tthis.currentUserLogin = user;\n\t}\n\n\tpublic get currentUser() {\n\t\tif (!this.currentUserLogin)\n\t\t\tthrow new Error('Attempted to access AuthenticationContext before it has been set');\n\t\treturn this.currentUserLogin;\n\t}\n}\nexport const AuthenticationContext = new AuthenticationContextImplementation();\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAEvB,MAAM,oCAAoC;AAAA,EAGlC,QAAQ;AACd,SAAK,mBAAmB;AAAA,EACzB;AAAA,EAEO,IAAI,MAAc;AACxB,yBAAO,MAAM,gDAAgD,MAAM;AACnE,SAAK,mBAAmB;AAAA,EACzB;AAAA,EAEA,IAAW,cAAc;AACxB,QAAI,CAAC,KAAK;AACT,YAAM,IAAI,MAAM,kEAAkE;AACnF,WAAO,KAAK;AAAA,EACb;AACD;AACO,MAAM,wBAAwB,IAAI,oCAAoC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/change-tracker.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tAnyEntity,\n\tChangeSet,\n\tChangeSetType,\n\tEventSubscriber,\n\tFlushEventArgs,\n\tReference,\n\tSubscriber,\n} from '@mikro-orm/core';\n\nimport { AuditChange, AuditRelatedEntityChange } from '../entities';\nimport { AuthenticationContext } from './authentication-context';\nimport { TrackedEntity } from './tracked-entity';\nimport { isUntrackedProperty } from './untracked-property';\n\n@Subscriber()\nexport class ChangeTracker implements EventSubscriber {\n\tasync afterFlush({ uow, em }: FlushEventArgs): Promise<void> {\n\t\tconst changesets = uow\n\t\t\t.getChangeSets()\n\t\t\t.filter((cs) => cs.entity instanceof TrackedEntity) as unknown as ChangeSet<\n\t\t\tTrackedEntity<any>\n\t\t>[];\n\t\tconst trx = em.getTransactionContext();\n\n\t\tfor (const cs of changesets) {\n\t\t\tlet change;\n\n\t\t\tconst data = dataForChangeSet(cs);\n\t\t\tif (data || cs.type === ChangeSetType.DELETE) {\n\t\t\t\tconst changeData = {\n\t\t\t\t\ttype: cs.type,\n\t\t\t\t\tentityId: cs.entity.id,\n\t\t\t\t\tentityType: cs.name,\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tcreatedBy: AuthenticationContext.currentUser,\n\t\t\t\t\tdata,\n\t\t\t\t};\n\t\t\t\tchange = await em.getDriver().nativeInsert(AuditChange.name, changeData, trx);\n\t\t\t}\n\n\t\t\tconst entity = cs.entity;\n\t\t\tconst relatedEntities = entity.relatedTrackedEntities;\n\t\t\tif (relatedEntities) {\n\t\t\t\tfor (const re of relatedEntities) {\n\t\t\t\t\tconst relatedEntityData = {\n\t\t\t\t\t\tchange: change?.insertId,\n\t\t\t\t\t\trelatedEntityId: re.id,\n\t\t\t\t\t\trelatedEntityType: re.entityType,\n\t\t\t\t\t};\n\t\t\t\t\tawait em.getDriver().nativeInsert(AuditRelatedEntityChange.name, relatedEntityData, trx);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst dataForChangeSet = <T extends TrackedEntity<T>>(cs: ChangeSet<TrackedEntity<T>>) => {\n\tif (cs.payload && cs.type !== ChangeSetType.DELETE) {\n\t\tconst entries = Object.entries(cs.payload)\n\t\t\t.filter(([k]) => !isUntrackedProperty(cs.entity, k))\n\t\t\t.map(([k]) => processPayloadEntry(k, cs.type, cs.entity, cs.originalEntity));\n\t\tconst id = cs.type === ChangeSetType.CREATE ? { to: cs.entity.id } : undefined;\n\t\tif (entries.length || id) return { ...Object.fromEntries(entries), id };\n\t}\n\n\treturn undefined;\n};\n\nconst processPayloadEntry = (\n\tkey: string,\n\tchangeSetType: ChangeSetType,\n\tupdatedEntity: AnyEntity,\n\toriginalEntity?: AnyEntity\n) => {\n\tlet from = originalEntity ? originalEntity[key] : null;\n\tif (!from && changeSetType === ChangeSetType.CREATE) from = undefined;\n\tlet to = updatedEntity[key] ?? null;\n\n\tif (Reference.isReference(to)) {\n\t\tconst relatedToEntity = to as Reference<AnyEntity>;\n\t\tif (from) {\n\t\t\tconst id = Reference.isReference(from)\n\t\t\t\t? (from as Reference<AnyEntity>).getProperty('id')\n\t\t\t\t: from;\n\t\t\tfrom = {\n\t\t\t\treference: {\n\t\t\t\t\ttype: relatedToEntity.constructor.name,\n\t\t\t\t\tid,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tto = {\n\t\t\treference: {\n\t\t\t\ttype: relatedToEntity.constructor.name,\n\t\t\t\tid: relatedToEntity.unwrap().id,\n\t\t\t},\n\t\t};\n\t}\n\treturn [key, { from, to }];\n};\n"],
|
|
5
|
+
"mappings": ";;;;;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CAAoB,GAAG,QAAQ,CAAC,CAAC,EAClD,IAAI,CAAC,CAAC,CAAC,MAAM,oBAAoB,GAAG,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;AAC5E,UAAM,KAAK,GAAG,SAAS,0BAAc,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,IAAI;AACrE,QAAI,QAAQ,UAAU;AAAI,aAAO,EAAE,GAAG,OAAO,YAAY,OAAO,GAAG,GAAG;AAAA,EACvE;AAEA,SAAO;AACR;AAEA,MAAM,sBAAsB,CAC3B,KACA,eACA,eACA,mBACI;AA1EL;AA2EC,MAAI,OAAO,iBAAiB,eAAe,OAAO;AAClD,MAAI,CAAC,QAAQ,kBAAkB,0BAAc;AAAQ,WAAO;AAC5D,MAAI,MAAK,mBAAc,SAAd,YAAsB;AAE/B,MAAI,sBAAU,YAAY,EAAE,GAAG;AAC9B,UAAM,kBAAkB;AACxB,QAAI,MAAM;AACT,YAAM,KAAK,sBAAU,YAAY,IAAI,IACjC,KAA8B,YAAY,IAAI,IAC/C;AACH,aAAO;AAAA,QACN,WAAW;AAAA,UACV,MAAM,gBAAgB,YAAY;AAAA,UAClC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACA,SAAK;AAAA,MACJ,WAAW;AAAA,QACV,MAAM,gBAAgB,YAAY;AAAA,QAClC,IAAI,gBAAgB,OAAO,EAAE;AAAA,MAC9B;AAAA,IACD;AAAA,EACD;AACA,SAAO,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;AAC1B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/utils/errors.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/errors.ts"],
|
|
4
|
+
"sourcesContent": ["import { GraphQLError } from 'graphql';\n\nexport class OptimisticLockError<T> extends GraphQLError {\n\tconstructor(message: string, extensions: { entity: T }) {\n\t\tsuper(message, { extensions: { code: 'OPTIMISTIC_LOCK_ERROR', extensions } });\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAEtB,MAAM,4BAA+B,4BAAa;AAAA,EACxD,YAAY,SAAiB,YAA2B;AACvD,UAAM,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,WAAW,EAAE,CAAC;AAAA,EAC7E;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/utils/index.js
CHANGED
|
@@ -19,3 +19,4 @@ __reExport(utils_exports, require("./authentication-context"), module.exports);
|
|
|
19
19
|
__reExport(utils_exports, require("./errors"), module.exports);
|
|
20
20
|
__reExport(utils_exports, require("./tracked-entity"), module.exports);
|
|
21
21
|
__reExport(utils_exports, require("./untracked-property"), module.exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './authentication-context';\nexport * from './errors';\nexport * from './tracked-entity';\nexport * from './untracked-property';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,qCAAd;AACA,0BAAc,qBADd;AAEA,0BAAc,6BAFd;AAGA,0BAAc,iCAHd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/tracked-entity.ts"],
|
|
4
|
+
"sourcesContent": ["import { BigIntType, PrimaryKey } from '@mikro-orm/core';\n\nimport { BaseEntity } from '../entities';\n\nexport abstract class TrackedEntity<T extends TrackedEntity<T>> extends BaseEntity {\n\t@PrimaryKey({ type: BigIntType })\n\tid!: string;\n\n\tget relatedTrackedEntities():\n\t\t| {\n\t\t\t\tid: string;\n\t\t\t\tentityType: string;\n\t\t }[]\n\t\t| undefined {\n\t\treturn undefined;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuC;AAEvC,sBAA2B;AAEpB,MAAe,sBAAkD,2BAAW;AAAA,EAIlF,IAAI,yBAKS;AACZ,WAAO;AAAA,EACR;AACD;AAVC;AAAA,MADC,wBAAW,EAAE,MAAM,uBAAW,CAAC;AAAA,GADX,cAErB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/untracked-property.ts"],
|
|
4
|
+
"sourcesContent": ["import 'reflect-metadata';\n\nconst untrackedPropertyMetadataKey = Symbol('UntrackedProperty');\n\nexport function UntrackedProperty() {\n\treturn Reflect.metadata(untrackedPropertyMetadataKey, true);\n}\n\nexport function isUntrackedProperty(target: any, propertyKey: string) {\n\treturn Reflect.getMetadata(untrackedPropertyMetadataKey, target, propertyKey);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAEP,MAAM,+BAA+B,OAAO,mBAAmB;AAExD,SAAS,oBAAoB;AACnC,SAAO,QAAQ,SAAS,8BAA8B,IAAI;AAC3D;AAEO,SAAS,oBAAoB,QAAa,aAAqB;AACrE,SAAO,QAAQ,YAAY,8BAA8B,QAAQ,WAAW;AAC7E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exogee/graphweaver-mikroorm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "MikroORM backend for @exogee/graphweaver",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"lib"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@exogee/graphweaver": "0.1.
|
|
16
|
-
"@exogee/logger": "0.1.
|
|
15
|
+
"@exogee/graphweaver": "0.1.2",
|
|
16
|
+
"@exogee/logger": "0.1.2",
|
|
17
17
|
"apollo-server-core": "3.10.3",
|
|
18
18
|
"dataloader": "2.2.2",
|
|
19
19
|
"decimal.js": "10.3.1",
|
|
@@ -23,23 +23,24 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@mikro-orm/core": "5.4.2",
|
|
26
|
+
"@mikro-orm/mysql": "5.4.2",
|
|
26
27
|
"@mikro-orm/postgresql": "5.4.2",
|
|
27
28
|
"@types/node": "18.11.11",
|
|
28
29
|
"esbuild": "0.15.5",
|
|
29
30
|
"ts-node": "10.4.0",
|
|
30
|
-
"typescript": "
|
|
31
|
+
"typescript": "5.0.2"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"@mikro-orm/core": "5.4.2",
|
|
34
|
-
"@mikro-orm/postgresql": "5.4.2"
|
|
35
|
+
"@mikro-orm/postgresql": "5.4.2",
|
|
36
|
+
"@mikro-orm/mysql": "5.4.2"
|
|
35
37
|
},
|
|
36
38
|
"scripts": {
|
|
37
39
|
"build": "npm run build:js && npm run build:types",
|
|
38
|
-
"build:js": "esbuild --outdir=lib --platform=node --format=cjs `find src \\( -name '*.ts' \\)`",
|
|
40
|
+
"build:js": "esbuild --outdir=lib --platform=node --format=cjs --sourcemap=linked `find src \\( -name '*.ts' \\)`",
|
|
39
41
|
"build:types": "tsc --emitDeclarationOnly",
|
|
40
42
|
"prettier": "prettier --write src/**/*.ts",
|
|
41
43
|
"generate:schema": "ts-node ./src/utils/generate-db-schema.ts",
|
|
42
|
-
"test": "jest --forceExit",
|
|
43
44
|
"version": "npm version --no-git-tag-version"
|
|
44
45
|
}
|
|
45
46
|
}
|