@things-factory/resource-base 8.0.5 → 9.0.0-beta.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/resource-base",
3
- "version": "8.0.5",
3
+ "version": "9.0.0-beta.12",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "author": "",
@@ -23,7 +23,7 @@
23
23
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
24
24
  },
25
25
  "dependencies": {
26
- "@things-factory/auth-base": "^8.0.5"
26
+ "@things-factory/auth-base": "^9.0.0-beta.12"
27
27
  },
28
- "gitHead": "9ab6fca18eeb58b9d2f3411661508a39d0ab6aee"
28
+ "gitHead": "5e9ade1c2d4b4c96b89396e36c3afa1caaf18ef0"
29
29
  }
package/server/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './service'
@@ -1,148 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { Entity } from './entity'
5
- import { EntityPatch, NewEntity } from './entity-type'
6
-
7
- @Resolver(Entity)
8
- export class EntityMutation {
9
- @Directive('@transaction')
10
- @Mutation(returns => Entity, { description: 'To create new Entity' })
11
- async createEntity(@Arg('entity') entity: NewEntity, @Ctx() context: ResolverContext): Promise<Entity> {
12
- const { domain, user, tx } = context.state
13
-
14
- const repository = tx.getRepository(Entity)
15
-
16
- if (entity.master) {
17
- entity.master = (await repository.findOne({ where: { id: entity.master } })) as any
18
- }
19
-
20
- return await repository.save({
21
- ...(entity as any),
22
- domain,
23
- creator: user,
24
- updater: user
25
- })
26
- }
27
-
28
- @Directive('@transaction')
29
- @Mutation(returns => Entity, { description: "To modify Entity' information" })
30
- async updateEntity(@Arg('id', type => String) id: string, @Arg('patch', type => EntityPatch) patch: EntityPatch, @Ctx() context: ResolverContext): Promise<Entity> {
31
- const { domain, user, tx } = context.state
32
-
33
- const repository = tx.getRepository(Entity)
34
- const entity = repository.findOne({
35
- where: { domain: { id: domain.id }, id },
36
- relations: ['master', 'children']
37
- })
38
-
39
- if (patch.master) {
40
- patch.master = (await repository.findOne({ where: { domain: { id: domain.id }, id: patch.master } })) as any
41
- }
42
-
43
- if (patch.children && patch.children.length) {
44
- patch.children = (await repository.findBy({ id: In(patch.children) })) as any
45
- }
46
-
47
- return await repository.save({
48
- ...entity,
49
- ...(patch as any),
50
- updater: user
51
- })
52
- }
53
-
54
- @Directive('@transaction')
55
- @Mutation(returns => [Entity], { description: "To modify multiple Entitys' information" })
56
- async updateMultipleEntity(@Arg('patches', type => [EntityPatch]) patches: EntityPatch[], @Ctx() context: ResolverContext): Promise<Entity[]> {
57
- const { domain, user, tx } = context.state
58
-
59
- let results = []
60
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
61
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
62
- const entityRepo = tx.getRepository(Entity)
63
-
64
- if (_createRecords.length > 0) {
65
- for (let i = 0; i < _createRecords.length; i++) {
66
- const newRecord = _createRecords[i]
67
-
68
- if (newRecord.master) {
69
- newRecord.master = (await tx.getRepository(Entity).findOne({ where: { domain: { id: domain.id }, id: newRecord.master } })) as any
70
- }
71
-
72
- if (newRecord.children && newRecord.children.length) {
73
- newRecord.children = (await tx.getRepository(Entity).findBy({ id: In(newRecord.children) })) as any
74
- }
75
-
76
- const result = await entityRepo.save({
77
- ...(newRecord as any),
78
- domain,
79
- creator: user,
80
- updater: user
81
- })
82
-
83
- results.push({ ...result, cuFlag: '+' })
84
- }
85
- }
86
-
87
- if (_updateRecords.length > 0) {
88
- for (let i = 0; i < _updateRecords.length; i++) {
89
- const updateRecord = _updateRecords[i]
90
- const entity = await entityRepo.findOneBy({ id: updateRecord.id })
91
-
92
- if (updateRecord.master) {
93
- updateRecord.master = (await tx.getRepository(Entity).findOne({ where: { domain: { id: domain.id }, id: updateRecord.master } })) as any
94
- }
95
-
96
- if (updateRecord.children && updateRecord.children.length) {
97
- updateRecord.children = (await tx.getRepository(Entity).findBy({ id: In(updateRecord.children) })) as any
98
- }
99
-
100
- const result = await entityRepo.save({
101
- ...entity,
102
- ...(updateRecord as any),
103
- updater: user
104
- })
105
-
106
- results.push({ ...result, cuFlag: 'M' })
107
- }
108
- }
109
-
110
- return results
111
- }
112
-
113
- @Directive('@transaction')
114
- @Mutation(returns => Boolean, { description: 'To delete Entity' })
115
- async deleteEntity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
116
- const { domain, tx } = context.state
117
- const entityRepo = tx.getRepository(Entity)
118
-
119
- const entity: Entity = await entityRepo.findOne({
120
- where: { domain: { id: domain.id }, id },
121
- relations: ['columns']
122
- })
123
-
124
- if (entity.columns.length) throw new Error('cannot delete Entity because columns of entity exists')
125
- else await entityRepo.delete(entity.id)
126
-
127
- return true
128
- }
129
-
130
- @Directive('@transaction')
131
- @Mutation(returns => Boolean, { description: 'To delete multiple Entities' })
132
- async deleteEntities(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
133
- const { domain, tx } = context.state
134
- const entityRepo = tx.getRepository(Entity)
135
-
136
- for (const id of ids) {
137
- const entity: Entity = await entityRepo.findOne({
138
- where: { domain: { id: domain.id }, id },
139
- relations: ['columns']
140
- })
141
-
142
- if (entity.columns.length) throw new Error('cannot delete Entity because columns of entity exists')
143
- else await entityRepo.delete(entity.id)
144
- }
145
-
146
- return true
147
- }
148
- }
@@ -1,77 +0,0 @@
1
- import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
-
3
- import { User } from '@things-factory/auth-base'
4
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
5
-
6
- import { EntityColumn } from '../entity-column/entity-column'
7
- import { Entity } from './entity'
8
- import { EntityList } from './entity-type'
9
-
10
- @Resolver(Entity)
11
- export class EntityQuery {
12
- @Query(returns => Entity, { description: 'To fetch a Entity' })
13
- async entity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Entity> {
14
- const { domain } = context.state
15
-
16
- return await getRepository(Entity).findOne({
17
- where: { domain: { id: domain.id }, id }
18
- })
19
- }
20
-
21
- @Query(returns => EntityList, { description: 'To fetch multiple Entities' })
22
- async entities(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<EntityList> {
23
- const { domain } = context.state
24
-
25
- const queryBuilder = getQueryBuilderFromListParams({
26
- repository: getRepository(Entity),
27
- params,
28
- domain,
29
- searchables: ['name', 'description']
30
- })
31
-
32
- const [items, total] = await queryBuilder.getManyAndCount()
33
-
34
- return { items, total }
35
- }
36
-
37
- @FieldResolver(type => Entity)
38
- async master(@Root() entity: Entity): Promise<Entity> {
39
- return await getRepository(Entity).findOneBy({ id: entity.masterId })
40
- }
41
-
42
- @FieldResolver(type => [Entity])
43
- async children(@Root() entity: Entity): Promise<Entity[]> {
44
- return await getRepository(Entity).find({
45
- where: {
46
- master: { id: entity.id }
47
- }
48
- })
49
- }
50
-
51
- @FieldResolver(type => [EntityColumn])
52
- async columns(@Root() entity: Entity): Promise<EntityColumn[]> {
53
- return await getRepository(EntityColumn).find({
54
- where: {
55
- entity: { id: entity.id }
56
- },
57
- order: {
58
- rank: 'ASC'
59
- }
60
- })
61
- }
62
-
63
- @FieldResolver(type => Domain)
64
- async domain(@Root() entity: Entity): Promise<Domain> {
65
- return await getRepository(Domain).findOneBy({ id: entity.domainId })
66
- }
67
-
68
- @FieldResolver(type => User)
69
- async updater(@Root() entity: Entity): Promise<User> {
70
- return await getRepository(User).findOneBy({ id: entity.updaterId })
71
- }
72
-
73
- @FieldResolver(type => User)
74
- async creator(@Root() entity: Entity): Promise<User> {
75
- return await getRepository(User).findOneBy({ id: entity.creatorId })
76
- }
77
- }
@@ -1,135 +0,0 @@
1
- import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
-
3
- import { Entity } from './entity'
4
-
5
- @InputType()
6
- export class NewEntity {
7
- @Field()
8
- name: string
9
-
10
- @Field({ nullable: true })
11
- description?: string
12
-
13
- @Field()
14
- bundle: string
15
-
16
- @Field()
17
- tableName: string
18
-
19
- @Field({ nullable: true })
20
- searchUrl?: string
21
-
22
- @Field({ nullable: true })
23
- multiSaveUrl?: string
24
-
25
- @Field({ nullable: true })
26
- idType?: string
27
-
28
- @Field({ nullable: true })
29
- idField?: string
30
-
31
- @Field({ nullable: true })
32
- titleField?: string
33
-
34
- @Field({ nullable: true })
35
- master?: string
36
-
37
- @Field({ nullable: true })
38
- association?: string
39
-
40
- @Field({ nullable: true })
41
- dataProp?: string
42
-
43
- @Field({ nullable: true })
44
- refField?: string
45
-
46
- @Field({ nullable: true })
47
- delStrategy?: string
48
-
49
- @Field(type => Int, { nullable: true })
50
- fixedColumns?: number
51
-
52
- @Field({ nullable: true })
53
- active?: boolean
54
-
55
- @Field({ nullable: true })
56
- extEntity?: boolean
57
-
58
- @Field(type => [String], { nullable: true })
59
- columns?: string[]
60
- }
61
-
62
- @InputType()
63
- export class EntityPatch {
64
- @Field(type => ID, { nullable: true })
65
- id?: string
66
-
67
- @Field({ nullable: true })
68
- name?: string
69
-
70
- @Field({ nullable: true })
71
- description?: string
72
-
73
- @Field({ nullable: true })
74
- bundle?: string
75
-
76
- @Field({ nullable: true })
77
- tableName?: string
78
-
79
- @Field({ nullable: true })
80
- searchUrl?: string
81
-
82
- @Field({ nullable: true })
83
- multiSaveUrl?: string
84
-
85
- @Field({ nullable: true })
86
- idType?: string
87
-
88
- @Field({ nullable: true })
89
- idField?: string
90
-
91
- @Field({ nullable: true })
92
- titleField?: string
93
-
94
- @Field({ nullable: true })
95
- master?: string
96
-
97
- @Field({ nullable: true })
98
- association?: string
99
-
100
- @Field({ nullable: true })
101
- dataProp?: string
102
-
103
- @Field({ nullable: true })
104
- refField?: string
105
-
106
- @Field({ nullable: true })
107
- delStrategy?: string
108
-
109
- @Field(type => Int, { nullable: true })
110
- fixedColumns?: number
111
-
112
- @Field({ nullable: true })
113
- active?: boolean
114
-
115
- @Field({ nullable: true })
116
- extEntity?: boolean
117
-
118
- @Field(type => [String], { nullable: true })
119
- columns?: string[]
120
-
121
- @Field(type => [String], { nullable: true })
122
- children: string[]
123
-
124
- @Field({ nullable: true })
125
- cuFlag?: string
126
- }
127
-
128
- @ObjectType()
129
- export class EntityList {
130
- @Field(type => [Entity])
131
- items: Entity[]
132
-
133
- @Field(type => Int)
134
- total: number
135
- }
@@ -1,168 +0,0 @@
1
- import { Field, ID, ObjectType } from 'type-graphql'
2
- import {
3
- Column,
4
- CreateDateColumn,
5
- Entity as ORMEntity,
6
- Index,
7
- ManyToOne,
8
- OneToMany,
9
- PrimaryGeneratedColumn,
10
- RelationId,
11
- UpdateDateColumn
12
- } from 'typeorm'
13
-
14
- import { User } from '@things-factory/auth-base'
15
- import { Domain } from '@things-factory/shell'
16
-
17
- import { EntityColumn } from '../entity-column/entity-column'
18
-
19
- @ORMEntity()
20
- @Index('ix_entity_0', (entity: Entity) => [entity.domain, entity.name], { unique: true })
21
- @Index('ix_entity_1', (entity: Entity) => [entity.domain])
22
- @Index('ix_entity_2', (entity: Entity) => [entity.bundle])
23
- @Index('ix_entity_3', (entity: Entity) => [entity.domain, entity.master])
24
- @ObjectType({ description: 'Entity for Entity' })
25
- export class Entity {
26
- @PrimaryGeneratedColumn('uuid')
27
- @Field(type => ID)
28
- readonly id: string
29
-
30
- @ManyToOne(type => Domain)
31
- @Field(type => Domain)
32
- domain?: Domain
33
-
34
- @RelationId((entity: Entity) => entity.domain)
35
- domainId?: string
36
-
37
- @Column()
38
- @Field()
39
- name: string
40
-
41
- @Column({
42
- nullable: true
43
- })
44
- @Field({ nullable: true })
45
- description?: string
46
-
47
- @Column()
48
- @Field()
49
- bundle: string
50
-
51
- @Column()
52
- @Field()
53
- tableName: string
54
-
55
- @Column({
56
- nullable: true
57
- })
58
- @Field({ nullable: true })
59
- searchUrl?: string
60
-
61
- @Column({
62
- nullable: true
63
- })
64
- @Field({ nullable: true })
65
- multiSaveUrl?: string
66
-
67
- @Column({
68
- nullable: true
69
- })
70
- @Field({ nullable: true })
71
- idType?: string
72
-
73
- @Column({
74
- nullable: true
75
- })
76
- @Field({ nullable: true })
77
- idField?: string
78
-
79
- @Column({
80
- nullable: true
81
- })
82
- @Field({ nullable: true })
83
- titleField?: string
84
-
85
- @ManyToOne(type => Entity, master => master.children)
86
- @Field(type => Entity, { nullable: true })
87
- master?: Entity
88
-
89
- @RelationId((entity: Entity) => entity.master)
90
- masterId?: string
91
-
92
- @OneToMany(type => Entity, child => child.master)
93
- @Field(type => [Entity], { nullable: true })
94
- children?: Entity[]
95
-
96
- @Column({
97
- nullable: true
98
- })
99
- @Field({ nullable: true })
100
- association?: string
101
-
102
- @Column({
103
- nullable: true
104
- })
105
- @Field({ nullable: true })
106
- dataProp?: string
107
-
108
- @Column({
109
- nullable: true
110
- })
111
- @Field({ nullable: true })
112
- refField?: string
113
-
114
- @Column({
115
- nullable: true
116
- })
117
- @Field({ nullable: true })
118
- delStrategy?: string
119
-
120
- @Column('int', {
121
- nullable: true
122
- })
123
- @Field({ nullable: true })
124
- fixedColumns?: number
125
-
126
- @Column({
127
- nullable: true,
128
- default: true
129
- })
130
- @Field({ nullable: true })
131
- active?: boolean
132
-
133
- @Column({
134
- nullable: true
135
- })
136
- @Field({ nullable: true })
137
- extEntity?: boolean
138
-
139
- @OneToMany(type => EntityColumn, entityColumn => entityColumn.entity)
140
- @Field(type => [EntityColumn], { nullable: true })
141
- columns?: EntityColumn[]
142
-
143
- @CreateDateColumn()
144
- @Field({ nullable: true })
145
- createdAt?: Date
146
-
147
- @UpdateDateColumn()
148
- @Field({ nullable: true })
149
- updatedAt?: Date
150
-
151
- @ManyToOne(type => User, {
152
- nullable: true
153
- })
154
- @Field(type => User, { nullable: true })
155
- creator?: User
156
-
157
- @RelationId((entity: Entity) => entity.creator)
158
- creatorId?: string
159
-
160
- @ManyToOne(type => User, {
161
- nullable: true
162
- })
163
- @Field(type => User, { nullable: true })
164
- updater?: User
165
-
166
- @RelationId((entity: Entity) => entity.updater)
167
- updaterId?: string
168
- }
@@ -1,6 +0,0 @@
1
- import { Entity } from './entity'
2
- import { EntityQuery } from './entity-query'
3
- import { EntityMutation } from './entity-mutation'
4
-
5
- export const entities = [Entity]
6
- export const resolvers = [EntityQuery, EntityMutation]
@@ -1,130 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { Entity } from '../entity/entity'
5
- import { EntityColumn } from './entity-column'
6
- import { EntityColumnPatch, NewEntityColumn } from './entity-column-type'
7
-
8
- @Resolver(EntityColumn)
9
- export class EntityColumnMutation {
10
- @Directive('@transaction')
11
- @Mutation(returns => EntityColumn, { description: 'To create new EntityColumn' })
12
- async createEntityColumn(
13
- @Arg('entityColumn') entityColumn: NewEntityColumn,
14
- @Ctx() context: ResolverContext
15
- ): Promise<EntityColumn> {
16
- const { domain, user, tx } = context.state
17
-
18
- if (entityColumn.entity) {
19
- entityColumn.entity = (await tx.getRepository(Entity).findOne({ where: { id: entityColumn.entity.id } })) as any
20
- }
21
-
22
- return await tx.getRepository(EntityColumn).save({
23
- ...(entityColumn as any),
24
- domain,
25
- creator: user,
26
- updater: user
27
- })
28
- }
29
-
30
- @Directive('@transaction')
31
- @Mutation(returns => EntityColumn, { description: 'To modify EntityColumn information' })
32
- async updateEntityColumn(
33
- @Arg('id') id: string,
34
- @Arg('patch') patch: EntityColumnPatch,
35
- @Ctx() context: ResolverContext
36
- ): Promise<EntityColumn> {
37
- const { domain, user, tx } = context.state
38
-
39
- const repository = tx.getRepository(EntityColumn)
40
- const entityColumn = await repository.findOne({
41
- where: { domain: { id: domain.id }, id }
42
- })
43
-
44
- if (patch.entity) {
45
- patch.entity = (await tx.getRepository(Entity).findOneBy({ id: patch.entity.id })) as any
46
- }
47
-
48
- return await repository.save({
49
- ...entityColumn,
50
- ...(patch as any),
51
- updater: user
52
- })
53
- }
54
-
55
- @Directive('@transaction')
56
- @Mutation(returns => [EntityColumn], { description: "To modify multiple Entitys' information" })
57
- async updateMultipleEntityColumn(
58
- @Arg('patches', type => [EntityColumnPatch]) patches: EntityColumnPatch[],
59
- @Ctx() context: ResolverContext
60
- ): Promise<EntityColumn[]> {
61
- const { domain, user, tx } = context.state
62
-
63
- let results = []
64
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
65
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
66
- const entityColumnRepo = tx.getRepository(EntityColumn)
67
-
68
- if (_createRecords.length > 0) {
69
- for (let i = 0; i < _createRecords.length; i++) {
70
- const newRecord = _createRecords[i]
71
-
72
- if (newRecord.entity) {
73
- newRecord.entity = (await tx.getRepository(Entity).findOneBy({ id: newRecord.entity.id })) as any
74
- }
75
-
76
- const result = await entityColumnRepo.save({
77
- ...(newRecord as any),
78
- domain,
79
- creator: user,
80
- updater: user
81
- })
82
-
83
- results.push({ ...result, cuFlag: '+' })
84
- }
85
- }
86
-
87
- if (_updateRecords.length > 0) {
88
- for (let i = 0; i < _updateRecords.length; i++) {
89
- const updateRecord = _updateRecords[i]
90
- const entity = await entityColumnRepo.findOneBy({ id: updateRecord.id })
91
-
92
- if (updateRecord.entity) {
93
- updateRecord.entity = (await tx.getRepository(Entity).findOneBy({ id: updateRecord.entity.id })) as any
94
- }
95
-
96
- const result = await entityColumnRepo.save({
97
- ...entity,
98
- ...(updateRecord as any),
99
- updater: user
100
- })
101
-
102
- results.push({ ...result, cuFlag: 'M' })
103
- }
104
- }
105
-
106
- return results
107
- }
108
-
109
- @Directive('@transaction')
110
- @Mutation(returns => Boolean, { description: 'To delete EntityColumn' })
111
- async deleteEntityColumn(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
112
- const { domain, tx } = context.state
113
-
114
- await tx.getRepository(EntityColumn).delete({ domain: { id: domain.id }, id })
115
- return true
116
- }
117
-
118
- @Directive('@transaction')
119
- @Mutation(returns => Boolean, { description: 'To delete multiple EntityColumns' })
120
- async deleteEntityColumns(
121
- @Arg('ids', type => [String]) ids: string[],
122
- @Ctx() context: ResolverContext
123
- ): Promise<boolean> {
124
- const { domain, tx } = context.state
125
-
126
- await tx.getRepository(EntityColumn).delete({ domain: { id: domain.id }, id: In(ids) })
127
-
128
- return true
129
- }
130
- }