typeorm-hasura 0.0.22 → 0.0.23
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/package.json +3 -3
- package/src/builders/Metadata.ts +2 -2
- package/src/mappers/graphql.ts +1 -1
- package/src/mappers/operators.ts +1 -1
- package/src/mappers/permissions.ts +2 -2
- package/src/mappers/relationships.ts +3 -3
- package/src/mappers/table.ts +2 -2
- package/src/mappers/tableConfiguration.ts +3 -3
- package/src/mappers/whereClause.ts +8 -7
- package/src/types/Action.ts +1 -1
- package/src/types/DataSourceOptions.ts +2 -2
- package/src/types/whereClause.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeorm-hasura",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hasura",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
47
47
|
"graphql-tag": "^2.0.0",
|
|
48
48
|
"hasura-metadata-types": "^2.22.1",
|
|
49
|
-
"lodash
|
|
49
|
+
"lodash-es": "^4.18.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/jest": "^29.5.0",
|
|
59
|
-
"@types/lodash
|
|
59
|
+
"@types/lodash-es": "^4.17.12",
|
|
60
60
|
"@types/node": "^18.14.0",
|
|
61
61
|
"env-cmd": "^10.1.0",
|
|
62
62
|
"jest": "^29.5.0",
|
package/src/builders/Metadata.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DocumentNode } from "graphql";
|
|
1
|
+
import type { DocumentNode } from "graphql";
|
|
3
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
4
3
|
import { ActionBuildResult, DataSourceOptions, InheritedRoles } from "../types";
|
|
5
4
|
import { generateSource } from "../mappers";
|
|
@@ -143,6 +142,7 @@ export class MetadataBuilder {
|
|
|
143
142
|
*/
|
|
144
143
|
async applyMetadata({ hasuraUrl, adminSecret }: { hasuraUrl: string, adminSecret: string }) {
|
|
145
144
|
const { metadata } = await this.getMetadata();
|
|
145
|
+
const { default: axios, AxiosError } = await import("axios");
|
|
146
146
|
try {
|
|
147
147
|
const { data } = await axios.post(`${hasuraUrl}/v1/metadata`, {
|
|
148
148
|
type: "replace_metadata",
|
package/src/mappers/graphql.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode } from "graphql";
|
|
1
|
+
import type { DocumentNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode } from "graphql";
|
|
2
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
3
3
|
import { GraphQlMetadataForAction } from "../types";
|
|
4
4
|
|
package/src/mappers/operators.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { EntityMetadata } from "typeorm";
|
|
2
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
3
3
|
import { ColumnMetadata, DataSourceOptions, EntityInternalStorageWorkspace, UserActionType } from "../types";
|
|
4
4
|
import { convertWhereClause } from "./whereClause"
|
|
@@ -9,7 +9,7 @@ export type PermissionResult = Required<Pick<
|
|
|
9
9
|
|
|
10
10
|
export function generatePermissions<Entity extends Object = Object>(
|
|
11
11
|
dataSourceOptions: DataSourceOptions,
|
|
12
|
-
table:
|
|
12
|
+
table: EntityMetadata,
|
|
13
13
|
{ entityOptions, columnMetadata }: EntityInternalStorageWorkspace<Entity>,
|
|
14
14
|
): PermissionResult {
|
|
15
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { EntityMetadata } from "typeorm";
|
|
2
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
3
3
|
|
|
4
4
|
type RelationshipKind = 'object_relationships' | 'array_relationships'
|
|
@@ -7,7 +7,7 @@ type Relationship =
|
|
|
7
7
|
| Hasura.SameTableObjectRelationship
|
|
8
8
|
| Hasura.ManualObjectRelationship
|
|
9
9
|
|
|
10
|
-
export function generateRelationship(relation:
|
|
10
|
+
export function generateRelationship(relation: EntityMetadata['relations'][number]): Relationship {
|
|
11
11
|
const owningRelation = relation.isOwning ?
|
|
12
12
|
relation : relation.inverseRelation;
|
|
13
13
|
|
|
@@ -62,7 +62,7 @@ export function generateRelationship(relation: TypeORM.EntityMetadata['relations
|
|
|
62
62
|
throw new Error("Relation tableType is not available")
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export function generateRelationships(relations:
|
|
65
|
+
export function generateRelationships(relations: EntityMetadata['relations']):
|
|
66
66
|
Pick<Hasura.MetadataTable, RelationshipKind> {
|
|
67
67
|
const result: Required<Pick<Hasura.MetadataTable, RelationshipKind>> = {
|
|
68
68
|
object_relationships: [],
|
package/src/mappers/table.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as Hasura from "hasura-metadata-types";
|
|
2
|
-
import
|
|
2
|
+
import type { EntityMetadata } from "typeorm";
|
|
3
3
|
import { generateRelationships } from "./relationships";
|
|
4
4
|
import { generateTableConfiguration } from "./tableConfiguration";
|
|
5
5
|
import { DataSourceOptions } from "../types";
|
|
@@ -8,7 +8,7 @@ import { internalStorage } from "../internalStorage";
|
|
|
8
8
|
|
|
9
9
|
export function generateTable<Entity extends Object>(
|
|
10
10
|
dataSourceOptions: DataSourceOptions,
|
|
11
|
-
table:
|
|
11
|
+
table: EntityMetadata
|
|
12
12
|
): Hasura.MetadataTable {
|
|
13
13
|
const entityWorkspace = internalStorage.getEntityWorkspace<Entity>(table.target);
|
|
14
14
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EntityMetadata } from "typeorm";
|
|
2
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
3
3
|
import { EntityInternalStorageWorkspace, EntityRootField } from "../types";
|
|
4
|
-
import snakeCase from 'lodash
|
|
4
|
+
import snakeCase from 'lodash-es/snakeCase'
|
|
5
5
|
|
|
6
6
|
export function generateTableConfiguration<Entity extends Object>(
|
|
7
|
-
table:
|
|
7
|
+
table: EntityMetadata,
|
|
8
8
|
{ entityOptions, columnMetadata }: EntityInternalStorageWorkspace<Entity>,
|
|
9
9
|
): Hasura.MetadataTableConfig {
|
|
10
10
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { InstanceChecker } from "typeorm";
|
|
2
|
+
import type { EntityMetadata, FindOptionsWhere } from "typeorm";
|
|
2
3
|
import { Where, Filter, FilterAlt, ExclusiveParameters } from "../types";
|
|
3
4
|
import { operatorMappers } from "./operators";
|
|
4
5
|
|
|
5
6
|
export function convertWhereClause<Entity extends Object>(
|
|
6
|
-
table:
|
|
7
|
+
table: EntityMetadata,
|
|
7
8
|
...wheres: (Where<Entity> | undefined)[]
|
|
8
9
|
): Filter<Entity> {
|
|
9
10
|
wheres = wheres.filter(Boolean)
|
|
@@ -20,8 +21,8 @@ export function convertWhereClause<Entity extends Object>(
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function parseParameters<Entity extends Object>(
|
|
23
|
-
table:
|
|
24
|
-
where:
|
|
24
|
+
table: EntityMetadata,
|
|
25
|
+
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]
|
|
25
26
|
): Filter<Entity> {
|
|
26
27
|
if (Array.isArray(where)) {
|
|
27
28
|
return { _or: where.map(i => parseParameters(table, i)) }
|
|
@@ -35,7 +36,7 @@ function parseParameters<Entity extends Object>(
|
|
|
35
36
|
|
|
36
37
|
const isJsonb = column?.type === "jsonb" && typeof parameterValue == "object"
|
|
37
38
|
|
|
38
|
-
if (
|
|
39
|
+
if (InstanceChecker.isFindOperator(parameterValue) && !isJsonb) {
|
|
39
40
|
conditions.push({ [key]: operatorMappers(parameterValue) })
|
|
40
41
|
} else if (
|
|
41
42
|
typeof parameterValue === "string" ||
|
|
@@ -45,8 +46,8 @@ function parseParameters<Entity extends Object>(
|
|
|
45
46
|
conditions.push({ [key]: { "_eq": parameterValue } })
|
|
46
47
|
} else if (relation && parameterValue) {
|
|
47
48
|
// this is a relation so we can parse it recursively
|
|
48
|
-
conditions.push({ [key]: parseParameters(relation.inverseEntityMetadata, parameterValue as
|
|
49
|
-
} else if (
|
|
49
|
+
conditions.push({ [key]: parseParameters(relation.inverseEntityMetadata, parameterValue as FindOptionsWhere<Entity>) })
|
|
50
|
+
} else if (InstanceChecker.isFindOperator(parameterValue) && parameterValue.type == "not" && isJsonb) {
|
|
50
51
|
conditions.push({ _not: { [key]: { "_contains": parameterValue.value } } })
|
|
51
52
|
} else if (isJsonb) {
|
|
52
53
|
conditions.push({ [key]: { "_contains": parameterValue } })
|
package/src/types/Action.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { DataSource } from "typeorm";
|
|
2
2
|
import type * as Hasura from "hasura-metadata-types";
|
|
3
3
|
|
|
4
4
|
export interface DataSourceOptions {
|
|
5
5
|
name: string;
|
|
6
|
-
dataSource:
|
|
6
|
+
dataSource: DataSource;
|
|
7
7
|
customizationNative?: Hasura.SourceCustomization;
|
|
8
8
|
|
|
9
9
|
/**
|
package/src/types/whereClause.ts
CHANGED