@things-factory/process 8.0.0-beta.9 → 8.0.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.
Files changed (62) hide show
  1. package/client/actions/main.ts +1 -0
  2. package/client/bootstrap.ts +8 -0
  3. package/client/index.ts +1 -0
  4. package/client/pages/event/event-importer.ts +86 -0
  5. package/client/pages/event/event-list-page.ts +324 -0
  6. package/client/pages/gateway/gateway-importer.ts +87 -0
  7. package/client/pages/gateway/gateway-list-page.ts +323 -0
  8. package/client/pages/main.ts +25 -0
  9. package/client/pages/process/process-importer.ts +87 -0
  10. package/client/pages/process/process-list-page.ts +324 -0
  11. package/client/pages/process-instance/process-instance-importer.ts +87 -0
  12. package/client/pages/process-instance/process-instance-list-page.ts +323 -0
  13. package/client/pages/process-thread/process-thread-importer.ts +87 -0
  14. package/client/pages/process-thread/process-thread-list-page.ts +323 -0
  15. package/client/reducers/main.ts +17 -0
  16. package/client/route.ts +27 -0
  17. package/client/tsconfig.json +13 -0
  18. package/dist-client/tsconfig.tsbuildinfo +1 -1
  19. package/dist-server/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +14 -14
  21. package/server/controllers/common.ts +90 -0
  22. package/server/controllers/index.ts +0 -0
  23. package/server/controllers/process-instance/abort.ts +75 -0
  24. package/server/controllers/process-instance/end.ts +74 -0
  25. package/server/controllers/process-instance/index.ts +2 -0
  26. package/server/controllers/process-thread/_abort.ts +20 -0
  27. package/server/controllers/process-thread/abort.ts +48 -0
  28. package/server/controllers/process-thread/end.ts +54 -0
  29. package/server/controllers/process-thread/index.ts +3 -0
  30. package/server/controllers/process-thread/start.ts +49 -0
  31. package/server/index.ts +4 -0
  32. package/server/middlewares/index.ts +3 -0
  33. package/server/migrations/index.ts +9 -0
  34. package/server/routes.ts +80 -0
  35. package/server/service/index.ts +44 -0
  36. package/server/service/process/event-subscriber.ts +17 -0
  37. package/server/service/process/index.ts +9 -0
  38. package/server/service/process/process-history.ts +108 -0
  39. package/server/service/process/process-mutation.ts +210 -0
  40. package/server/service/process/process-query.ts +120 -0
  41. package/server/service/process/process-search-key-item-type.ts +16 -0
  42. package/server/service/process/process-type.ts +65 -0
  43. package/server/service/process/process.ts +97 -0
  44. package/server/service/process-instance/event-subscriber.ts +44 -0
  45. package/server/service/process-instance/index.ts +10 -0
  46. package/server/service/process-instance/process-instance-history.ts +154 -0
  47. package/server/service/process-instance/process-instance-mutation.ts +33 -0
  48. package/server/service/process-instance/process-instance-query.ts +141 -0
  49. package/server/service/process-instance/process-instance-subscription.ts +46 -0
  50. package/server/service/process-instance/process-instance-type.ts +71 -0
  51. package/server/service/process-instance/process-instance.ts +147 -0
  52. package/server/service/process-stats/index.ts +3 -0
  53. package/server/service/process-stats/process-stats-query.ts +57 -0
  54. package/server/service/process-stats/process-stats-type.ts +31 -0
  55. package/server/service/process-thread/event-subscriber.ts +31 -0
  56. package/server/service/process-thread/index.ts +9 -0
  57. package/server/service/process-thread/process-thread-mutation.ts +34 -0
  58. package/server/service/process-thread/process-thread-query.ts +61 -0
  59. package/server/service/process-thread/process-thread-subscription.ts +42 -0
  60. package/server/service/process-thread/process-thread-type.ts +15 -0
  61. package/server/service/process-thread/process-thread.ts +90 -0
  62. package/server/tsconfig.json +10 -0
@@ -0,0 +1,31 @@
1
+ import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm'
2
+
3
+ import { pubsub } from '@things-factory/shell'
4
+
5
+ import { ProcessThread } from './process-thread'
6
+
7
+ @EventSubscriber()
8
+ export class ProcessThreadSubscriber implements EntitySubscriberInterface<ProcessThread> {
9
+ listenTo() {
10
+ return ProcessThread
11
+ }
12
+
13
+ async afterInsert(event: InsertEvent<ProcessThread>): Promise<any> {
14
+ const processThread = event.entity
15
+
16
+ pubsub.publish('process-thread', {
17
+ processThread
18
+ })
19
+
20
+ console.log('process-thread created', processThread.id)
21
+ }
22
+
23
+ async afterUpdate(event: UpdateEvent<ProcessThread>): Promise<any> {
24
+ const processThread = event.entity
25
+
26
+ pubsub.publish('process-thread', {
27
+ processThread
28
+ })
29
+ console.log('process-thread updated', processThread.id)
30
+ }
31
+ }
@@ -0,0 +1,9 @@
1
+ import { ProcessThread } from './process-thread'
2
+ import { ProcessThreadMutation } from './process-thread-mutation'
3
+ import { ProcessThreadQuery } from './process-thread-query'
4
+ import { ProcessThreadSubscription } from './process-thread-subscription'
5
+ import { ProcessThreadSubscriber } from './event-subscriber'
6
+
7
+ export const entities = [ProcessThread]
8
+ export const resolvers = [ProcessThreadQuery, ProcessThreadMutation, ProcessThreadSubscription]
9
+ export const subscribers = [ProcessThreadSubscriber]
@@ -0,0 +1,34 @@
1
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
+
3
+ import { ObjectRef, ScalarObject } from '@things-factory/shell'
4
+
5
+ import { abort, start } from '../../controllers/process-thread'
6
+ import { ProcessThread } from './process-thread'
7
+
8
+ @Resolver(ProcessThread)
9
+ export class ProcessThreadMutation {
10
+ /* transactions ... */
11
+
12
+ @Directive('@transaction')
13
+ @Directive('@privilege(category: "process", privilege: "mutation", domainOwnerGranted: true)')
14
+ @Mutation(returns => ProcessThread!, { nullable: true, description: 'To start ProcessThread' })
15
+ async startProcessThread(
16
+ @Arg('id') id: string,
17
+ @Arg('output', type => ScalarObject, { nullable: true }) output: { [key: string]: any },
18
+ @Arg('reason', { nullable: true }) reason: string,
19
+ @Ctx() context: ResolverContext
20
+ ): Promise<ProcessThread> {
21
+ return await start(id, output, reason, context)
22
+ }
23
+
24
+ @Directive('@transaction')
25
+ @Directive('@privilege(category: "process", privilege: "mutation", domainOwnerGranted: true)')
26
+ @Mutation(returns => ProcessThread, { description: 'To abort a ProcessThread' })
27
+ async abortProcessThread(
28
+ @Arg('id') id: string,
29
+ @Arg('reason', { nullable: true }) reason: string,
30
+ @Ctx() context: ResolverContext
31
+ ): Promise<ProcessThread> {
32
+ return await abort({ id, reason }, context)
33
+ }
34
+ }
@@ -0,0 +1,61 @@
1
+ import { Arg, Args, Ctx, Directive, 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 { ProcessInstance } from '../process-instance/process-instance'
7
+ import { ProcessThread, ProcessThreadStatus } from './process-thread'
8
+ import { ProcessThreadList } from './process-thread-type'
9
+
10
+ @Resolver(ProcessThread)
11
+ export class ProcessThreadQuery {
12
+ @Directive('@privilege(category: "process", privilege: "query", domainOwnerGranted: true)')
13
+ @Query(returns => ProcessThread!, { nullable: true, description: 'To fetch a ProcessThread' })
14
+ async processThread(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<ProcessThread> {
15
+ const { domain } = context.state
16
+
17
+ return await getRepository(ProcessThread).findOne({
18
+ where: { domain: { id: domain.id }, id }
19
+ })
20
+ }
21
+
22
+ @Directive('@privilege(category: "process", privilege: "query", domainOwnerGranted: true)')
23
+ @Query(returns => ProcessThreadList, { description: 'To fetch multiple ProcessThreads' })
24
+ async processThreads(
25
+ @Args(type => ListParam) params: ListParam,
26
+ @Ctx() context: ResolverContext
27
+ ): Promise<ProcessThreadList> {
28
+ const { domain } = context.state
29
+
30
+ const queryBuilder = getQueryBuilderFromListParams({
31
+ domain,
32
+ params,
33
+ repository: getRepository(ProcessThread),
34
+ searchables: ['name', 'description']
35
+ })
36
+
37
+ const [items, total] = await queryBuilder.getManyAndCount()
38
+
39
+ return { items, total }
40
+ }
41
+
42
+ @FieldResolver(type => ProcessInstance)
43
+ async processInstance(@Root() processThread: ProcessThread): Promise<ProcessInstance> {
44
+ return await getRepository(ProcessInstance).findOneBy({ id: processThread.processInstanceId })
45
+ }
46
+
47
+ @FieldResolver(type => Domain)
48
+ async domain(@Root() processThread: ProcessThread): Promise<Domain> {
49
+ return await getRepository(Domain).findOneBy({ id: processThread.domainId })
50
+ }
51
+
52
+ @FieldResolver(type => User)
53
+ async updater(@Root() processThread: ProcessThread): Promise<User> {
54
+ return processThread.updaterId && (await getRepository(User).findOneBy({ id: processThread.updaterId }))
55
+ }
56
+
57
+ @FieldResolver(type => User)
58
+ async creator(@Root() processThread: ProcessThread): Promise<User> {
59
+ return processThread.creatorId && (await getRepository(User).findOneBy({ id: processThread.creatorId }))
60
+ }
61
+ }
@@ -0,0 +1,42 @@
1
+ import { filter, pipe } from 'graphql-yoga'
2
+ import { Resolver, Root, Subscription } from 'type-graphql'
3
+
4
+ import { pubsub } from '@things-factory/shell'
5
+ import { User } from '@things-factory/auth-base'
6
+
7
+ import { ProcessThread } from './process-thread'
8
+
9
+ @Resolver(ProcessThread)
10
+ export class ProcessThreadSubscription {
11
+ @Subscription({
12
+ subscribe: ({ args, context, info }) => {
13
+ const { domain, user } = context.state
14
+ const subdomain = domain?.subdomain
15
+
16
+ if (!domain) {
17
+ throw new Error('domain required')
18
+ }
19
+
20
+ if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
21
+ throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
22
+ }
23
+
24
+ return pipe(
25
+ pubsub.subscribe('process-thread'),
26
+ filter(async (payload: { processThread: ProcessThread }) => {
27
+ const { processThread } = payload
28
+ const { domainId } = processThread
29
+
30
+ if (domainId !== domain?.id) {
31
+ return false
32
+ }
33
+
34
+ return await User.hasPrivilege('query', 'process-thread', domain, user)
35
+ })
36
+ )
37
+ }
38
+ })
39
+ processThread(@Root() payload: { processThread: ProcessThread }): ProcessThread {
40
+ return payload.processThread
41
+ }
42
+ }
@@ -0,0 +1,15 @@
1
+ import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { ScalarObject } from '@things-factory/shell'
4
+
5
+ import { ProcessThread, ProcessThreadStatus } from './process-thread'
6
+ import { User } from '@things-factory/auth-base'
7
+
8
+ @ObjectType()
9
+ export class ProcessThreadList {
10
+ @Field(type => [ProcessThread])
11
+ items: ProcessThread[]
12
+
13
+ @Field(type => Int)
14
+ total: number
15
+ }
@@ -0,0 +1,90 @@
1
+ import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ OneToMany,
8
+ ManyToOne,
9
+ PrimaryGeneratedColumn,
10
+ RelationId,
11
+ VersionColumn,
12
+ UpdateDateColumn
13
+ } from 'typeorm'
14
+
15
+ import { User } from '@things-factory/auth-base'
16
+ import { Domain, ScalarObject } from '@things-factory/shell'
17
+
18
+ import { ProcessInstance } from '../process-instance/process-instance'
19
+
20
+ export enum ProcessThreadStatus {
21
+ Assigned = 'assigned',
22
+ Started = 'started',
23
+ Delegated = 'delegated',
24
+ Submitted = 'submitted',
25
+ Escalated = 'escalated',
26
+ Rejected = 'rejected',
27
+ Ended = 'ended',
28
+ Aborted = 'aborted'
29
+ }
30
+
31
+ registerEnumType(ProcessThreadStatus, {
32
+ name: 'ProcessThreadStatus',
33
+ description: 'state enumeration of a ProcessThread'
34
+ })
35
+
36
+ @Entity()
37
+ @ObjectType({ description: 'Entity for ProcessThread' })
38
+ export class ProcessThread {
39
+ @PrimaryGeneratedColumn('uuid')
40
+ @Field(type => ID)
41
+ readonly id: string
42
+
43
+ @ManyToOne(type => Domain)
44
+ @Field(type => Domain)
45
+ domain?: Domain
46
+
47
+ @RelationId((processThread: ProcessThread) => processThread.domain)
48
+ domainId?: string
49
+
50
+ @VersionColumn({ default: 1 })
51
+ @Field({ nullable: true })
52
+ version?: number = 1
53
+
54
+ @ManyToOne(type => ProcessInstance, processInstance => processInstance.processThreads)
55
+ @Field(type => ProcessInstance, { nullable: true })
56
+ processInstance?: ProcessInstance
57
+
58
+ @RelationId((processThread: ProcessThread) => processThread.processInstance)
59
+ processInstanceId?: string
60
+
61
+ @Column({ nullable: true })
62
+ @Field({ nullable: true })
63
+ state?: ProcessThreadStatus
64
+
65
+ @Column({ nullable: true })
66
+ @Field({ nullable: true })
67
+ terminatedAt?: Date
68
+
69
+ @CreateDateColumn()
70
+ @Field({ nullable: true })
71
+ createdAt?: Date
72
+
73
+ @UpdateDateColumn()
74
+ @Field({ nullable: true })
75
+ updatedAt?: Date
76
+
77
+ @ManyToOne(type => User, { nullable: true })
78
+ @Field(type => User, { nullable: true })
79
+ creator?: User
80
+
81
+ @RelationId((processThread: ProcessThread) => processThread.creator)
82
+ creatorId?: string
83
+
84
+ @ManyToOne(type => User, { nullable: true })
85
+ @Field(type => User, { nullable: true })
86
+ updater?: User
87
+
88
+ @RelationId((processThread: ProcessThread) => processThread.updater)
89
+ updaterId?: string
90
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "strict": false,
5
+ "module": "commonjs",
6
+ "outDir": "../dist-server",
7
+ "baseUrl": "./"
8
+ },
9
+ "include": ["./**/*"]
10
+ }