@things-factory/figure-service 10.1.68 → 10.1.70
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/dist-server/index.js +14 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/figure-recipe/figure-recipe-resolver.d.ts +7 -0
- package/dist-server/service/figure-recipe/figure-recipe-resolver.js +66 -0
- package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +1 -0
- package/dist-server/service/figure-recipe/figure-recipe-store.d.ts +41 -0
- package/dist-server/service/figure-recipe/figure-recipe-store.js +105 -0
- package/dist-server/service/figure-recipe/figure-recipe-store.js.map +1 -0
- package/dist-server/service/figure-recipe/figure-recipe.d.ts +19 -0
- package/dist-server/service/figure-recipe/figure-recipe.js +67 -0
- package/dist-server/service/figure-recipe/figure-recipe.js.map +1 -0
- package/dist-server/service/figure-recipe/index.d.ts +4 -0
- package/dist-server/service/figure-recipe/index.js +8 -0
- package/dist-server/service/figure-recipe/index.js.map +1 -0
- package/dist-server/service/index.d.ts +4 -2
- package/dist-server/service/index.js +10 -3
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/server/index.ts +14 -0
- package/server/service/figure-recipe/figure-recipe-db.test.ts +123 -0
- package/server/service/figure-recipe/figure-recipe-resolver.ts +42 -0
- package/server/service/figure-recipe/figure-recipe-store.ts +101 -0
- package/server/service/figure-recipe/figure-recipe.ts +51 -0
- package/server/service/figure-recipe/index.ts +5 -0
- package/server/service/index.ts +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/figure-service",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.70",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"@things-factory:registry": "https://registry.npmjs.org"
|
|
@@ -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
|
-
"@hatiolab/figure-model": "^0.1.
|
|
26
|
+
"@hatiolab/figure-model": "^0.1.82",
|
|
27
27
|
"@operato/typeorm-history": "^10.0.0",
|
|
28
28
|
"@things-factory/ai-client-base": "^10.1.53",
|
|
29
29
|
"@things-factory/auth-base": "^10.1.47",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"graphql-upload": "^15.0.2",
|
|
34
34
|
"koa-router": "^7.4.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "7c9c614b0cb1d02d401211db76ec0ca0ead344af"
|
|
37
37
|
}
|
package/server/index.ts
CHANGED
|
@@ -10,6 +10,20 @@ import './routes.js'
|
|
|
10
10
|
import { registerFigureToolCategories } from './service/figure/figure-tools.js'
|
|
11
11
|
registerFigureToolCategories()
|
|
12
12
|
|
|
13
|
+
/*
|
|
14
|
+
* The built-in recipes into the system domain, as auth-base fills its privileges: once, and again gives the same result
|
|
15
|
+
* (ADR-0095 condition 2). A recipe that fails its check is said here, not half put in.
|
|
16
|
+
*/
|
|
17
|
+
import { seedBuiltInRecipes } from './service/figure-recipe/figure-recipe-store.js'
|
|
18
|
+
process.on('bootstrap-module-start' as any, async () => {
|
|
19
|
+
try {
|
|
20
|
+
const { added, skipped, refused } = await seedBuiltInRecipes()
|
|
21
|
+
console.log(`[figure-service:bootstrap] recipes added ${added.length}, already there ${skipped.length}${refused.length ? `, refused: ${refused.join(' | ')}` : ''}`)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error('[figure-service:bootstrap] recipes were not seeded:', error)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
13
27
|
export * from './service/index.js'
|
|
14
28
|
export * from './migrations/index.js'
|
|
15
29
|
export { registerFigureToolCategories } from './service/figure/figure-tools.js'
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 조각 — 시드 · 도메인 규칙 · 저장 검사를 **sqlite 를 실제로 들고** 확인한다(ADR-0095 조건 2 · 3).
|
|
3
|
+
*
|
|
4
|
+
* 규칙이 질의에 있으므로 DB 없이 시험하면 초록이어도 뜻이 없다. figure-rename-db 와 같이 tsc 산출물을 든다.
|
|
5
|
+
*/
|
|
6
|
+
import type { DataSource } from 'typeorm'
|
|
7
|
+
|
|
8
|
+
const { DataSource: TypeOrmDataSource } = require('typeorm')
|
|
9
|
+
const shell = require('@things-factory/shell')
|
|
10
|
+
const authBase = require('@things-factory/auth-base')
|
|
11
|
+
|
|
12
|
+
let dataSource: DataSource | null = null
|
|
13
|
+
let FigureRecipe: any
|
|
14
|
+
let store: any
|
|
15
|
+
|
|
16
|
+
function loadCompiled(modulePath: string): any {
|
|
17
|
+
const { existsSync } = require('fs')
|
|
18
|
+
const { join } = require('path')
|
|
19
|
+
const resolved = join(__dirname, '..', '..', '..', 'dist-server', `${modulePath}.js`)
|
|
20
|
+
if (!existsSync(resolved)) throw new Error(`figure-service 산출물이 없다: ${resolved} — 먼저 빌드할 것: yarn workspace @things-factory/figure-service build:server`)
|
|
21
|
+
return require(resolved)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
FigureRecipe = loadCompiled('service/figure-recipe/figure-recipe').FigureRecipe
|
|
26
|
+
store = loadCompiled('service/figure-recipe/figure-recipe-store')
|
|
27
|
+
dataSource = new TypeOrmDataSource({
|
|
28
|
+
type: 'sqlite',
|
|
29
|
+
database: ':memory:',
|
|
30
|
+
synchronize: true,
|
|
31
|
+
dropSchema: true,
|
|
32
|
+
namingStrategy: new shell.NamingStrategy(),
|
|
33
|
+
entities: [...shell.entities, ...authBase.entities, FigureRecipe],
|
|
34
|
+
logging: false
|
|
35
|
+
})
|
|
36
|
+
await dataSource.initialize()
|
|
37
|
+
shell.addDataSource('default', dataSource)
|
|
38
|
+
shell.addDataSource('tx', dataSource)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
if (!dataSource) return
|
|
43
|
+
shell.removeDataSource('default')
|
|
44
|
+
shell.removeDataSource('tx')
|
|
45
|
+
await dataSource.destroy()
|
|
46
|
+
dataSource = null
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
let SYSTEM: any
|
|
50
|
+
let CHILD: any
|
|
51
|
+
|
|
52
|
+
beforeEach(async () => {
|
|
53
|
+
await dataSource!.synchronize(true)
|
|
54
|
+
const domains = dataSource!.getRepository(shell.Domain)
|
|
55
|
+
SYSTEM = await domains.save({ name: 'SYSTEM', subdomain: 'system', systemFlag: true })
|
|
56
|
+
CHILD = await domains.save({ name: 'plant', subdomain: 'plant', parentId: SYSTEM.id })
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const rows = async () => (await dataSource!.getRepository(FigureRecipe).find({ relations: ['domain'], order: { name: 'ASC' } })).map((r: any) => [r.domain.subdomain, r.name])
|
|
60
|
+
|
|
61
|
+
describe('조각 — 시드', () => {
|
|
62
|
+
it('★ figure-model 이 싣는 조각 셋이 system 에 들어가고, 다시 실어도 같다 — 있으면 건너뛰고 덮지 않는다', async () => {
|
|
63
|
+
const first = await store.seedBuiltInRecipes()
|
|
64
|
+
expect(first.added).toEqual(['hinged-door', 'roller-row', 'sliding-door'])
|
|
65
|
+
expect(first.refused).toEqual([])
|
|
66
|
+
const repo = dataSource!.getRepository(FigureRecipe)
|
|
67
|
+
const door = await repo.findOne({ where: { name: 'sliding-door' } })
|
|
68
|
+
await repo.save({ ...door, state: 'draft' })
|
|
69
|
+
|
|
70
|
+
const again = await store.seedBuiltInRecipes()
|
|
71
|
+
expect(again.added).toEqual([])
|
|
72
|
+
expect(again.skipped).toEqual(['hinged-door', 'roller-row', 'sliding-door'])
|
|
73
|
+
expect(await rows()).toEqual([['system', 'hinged-door'], ['system', 'roller-row'], ['system', 'sliding-door']])
|
|
74
|
+
expect((await repo.findOne({ where: { name: 'sliding-door' } })).state).toBe('draft')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('조각 — 읽기는 도형과 같은 도메인 규칙', () => {
|
|
79
|
+
it('★ 자식 도메인은 부모의 조각을 보고, 같은 이름의 제 조각이 그것을 대신한다; 초안은 모두를 물을 때만', async () => {
|
|
80
|
+
await store.seedBuiltInRecipes()
|
|
81
|
+
const door = JSON.parse(store.builtInRecipes().find((r: any) => r.name === 'sliding-door').source)
|
|
82
|
+
door.title = { ko: '우리 공장 미닫이 문' }
|
|
83
|
+
await store.saveRecipe(CHILD, JSON.stringify(door))
|
|
84
|
+
const seen = await store.recipesFor({ id: CHILD.id, parentId: SYSTEM.id }, 'released')
|
|
85
|
+
expect(seen.map((r: any) => r.name)).toEqual(['hinged-door', 'roller-row', 'sliding-door'])
|
|
86
|
+
expect(JSON.parse(seen.find((r: any) => r.name === 'sliding-door').source).title.ko).toBe('우리 공장 미닫이 문')
|
|
87
|
+
|
|
88
|
+
const hinged = JSON.parse(store.builtInRecipes().find((r: any) => r.name === 'hinged-door').source)
|
|
89
|
+
await store.saveRecipe(CHILD, JSON.stringify({ ...hinged, name: 'shop-door' }), 'draft')
|
|
90
|
+
expect((await store.recipesFor({ id: CHILD.id, parentId: SYSTEM.id }, 'released')).map((r: any) => r.name)).not.toContain('shop-door')
|
|
91
|
+
expect((await store.recipesFor({ id: CHILD.id, parentId: SYSTEM.id })).map((r: any) => r.name)).toContain('shop-door')
|
|
92
|
+
expect((await store.recipesFor({ id: SYSTEM.id })).map((r: any) => r.name)).not.toContain('shop-door')
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe('조각 — 저장은 빈 방에 넣어 본 뒤에', () => {
|
|
97
|
+
it('★ 기본값으로 넣을 수 없는 조각은 커널의 말 그대로 거절되고 저장되지 않는다', async () => {
|
|
98
|
+
const door = JSON.parse(store.builtInRecipes().find((r: any) => r.name === 'sliding-door').source)
|
|
99
|
+
door.steps[2].source.part = 'nowhere'
|
|
100
|
+
await expect(store.saveRecipe(CHILD, JSON.stringify(door))).rejects.toThrow(/steps\[2\]/)
|
|
101
|
+
expect(await rows()).toEqual([])
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
describe('조각 — 제 도메인 것만 바꾼다', () => {
|
|
106
|
+
it('★ 자식은 부모의 조각을 발행 · 삭제하지 못한다; 제 것은 초안으로 돌리면 모델러 목록에서 빠지고, 지우면 부모 것이 다시 보인다', async () => {
|
|
107
|
+
await store.seedBuiltInRecipes()
|
|
108
|
+
const child = { id: CHILD.id, parentId: SYSTEM.id }
|
|
109
|
+
await expect(store.deleteRecipe(child, 'sliding-door')).rejects.toThrow(/copied here to be changed/)
|
|
110
|
+
await expect(store.setRecipeState(child, 'sliding-door', 'draft')).rejects.toThrow(/copied here/)
|
|
111
|
+
|
|
112
|
+
const door = JSON.parse(store.builtInRecipes().find((r: any) => r.name === 'sliding-door').source)
|
|
113
|
+
door.title = { ko: '우리 문' }
|
|
114
|
+
await store.saveRecipe(CHILD, JSON.stringify(door))
|
|
115
|
+
await store.setRecipeState(child, 'sliding-door', 'draft')
|
|
116
|
+
const released = await store.recipesFor(child, 'released')
|
|
117
|
+
expect(JSON.parse(released.find((r: any) => r.name === 'sliding-door').source).title.ko).not.toBe('우리 문')
|
|
118
|
+
|
|
119
|
+
await store.deleteRecipe(child, 'sliding-door')
|
|
120
|
+
const all = await store.recipesFor(child)
|
|
121
|
+
expect(all.find((r: any) => r.name === 'sliding-door').domainId).toBe(SYSTEM.id)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Query, Resolver, UseMiddleware } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { SpeakRefusals } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { FigureRecipe } from './figure-recipe.js'
|
|
6
|
+
import { deleteRecipe, recipesFor, saveRecipe, setRecipeState } from './figure-recipe-store.js'
|
|
7
|
+
|
|
8
|
+
@Resolver(FigureRecipe)
|
|
9
|
+
@UseMiddleware(SpeakRefusals)
|
|
10
|
+
export class FigureRecipeResolver {
|
|
11
|
+
@Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
|
|
12
|
+
@Query(returns => [FigureRecipe], { description: "The recipes this domain sees: its own and its parent's (its own stand in by name). Released ones unless all is asked." })
|
|
13
|
+
async figureRecipes(@Arg('all', { nullable: true, description: 'Drafts as well.' }) all: boolean, @Ctx() context: ResolverContext): Promise<FigureRecipe[]> {
|
|
14
|
+
return await recipesFor(context.state.domain, all ? undefined : 'released')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Directive('@privilege(category: "figure", privilege: "mutation", domainOwnerGranted: true)')
|
|
18
|
+
@Mutation(returns => FigureRecipe, { description: 'Saves a recipe into this domain by its name, after putting it into an empty room with its defaults (ADR-0095).' })
|
|
19
|
+
async saveFigureRecipe(
|
|
20
|
+
@Arg('source', { description: 'The recipe JSON (figure-model V3Recipe).' }) source: string,
|
|
21
|
+
@Arg('state', { nullable: true, description: "'draft' or 'released' (the default)." }) state: string,
|
|
22
|
+
@Ctx() context: ResolverContext
|
|
23
|
+
): Promise<FigureRecipe> {
|
|
24
|
+
return await saveRecipe(context.state.domain, source, state === 'draft' ? 'draft' : 'released')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Directive('@privilege(category: "figure", privilege: "mutation", domainOwnerGranted: true)')
|
|
28
|
+
@Mutation(returns => FigureRecipe, { description: "Releases a recipe of this domain's own, or takes it back to draft. A parent's recipe is copied in to be changed." })
|
|
29
|
+
async setFigureRecipeState(
|
|
30
|
+
@Arg('name', { description: 'The recipe name.' }) name: string,
|
|
31
|
+
@Arg('state', { description: "'draft' or 'released'." }) state: string,
|
|
32
|
+
@Ctx() context: ResolverContext
|
|
33
|
+
): Promise<FigureRecipe> {
|
|
34
|
+
return await setRecipeState(context.state.domain, name, state === 'draft' ? 'draft' : 'released')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Directive('@privilege(category: "figure", privilege: "mutation", domainOwnerGranted: true)')
|
|
38
|
+
@Mutation(returns => Boolean, { description: "Deletes a recipe of this domain's own. Figures it was put into keep their parts." })
|
|
39
|
+
async deleteFigureRecipe(@Arg('name', { description: 'The recipe name.' }) name: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
40
|
+
return await deleteRecipe(context.state.domain, name)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'fs'
|
|
2
|
+
import { dirname, join } from 'path'
|
|
3
|
+
import { In } from 'typeorm'
|
|
4
|
+
|
|
5
|
+
import { checkV3Recipe } from '@hatiolab/figure-model'
|
|
6
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
7
|
+
|
|
8
|
+
import { FigureRecipe } from './figure-recipe.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The recipes a domain sees (ADR-0095 condition 2): its own and its parent's, as figures are read. A recipe of the
|
|
12
|
+
* domain's own stands in for the parent's of the same name.
|
|
13
|
+
*/
|
|
14
|
+
export async function recipesFor(domain: { id: string; parentId?: string | null }, state?: 'released'): Promise<FigureRecipe[]> {
|
|
15
|
+
const ids = [domain.id, domain.parentId].filter(Boolean) as string[]
|
|
16
|
+
const rows = await getRepository(FigureRecipe).find({
|
|
17
|
+
where: { domain: { id: In(ids) }, ...(state ? { state } : {}) },
|
|
18
|
+
relations: ['domain'],
|
|
19
|
+
order: { name: 'ASC' }
|
|
20
|
+
})
|
|
21
|
+
const byName = new Map<string, FigureRecipe>()
|
|
22
|
+
for (const row of rows) {
|
|
23
|
+
const mine = row.domainId === domain.id || (row.domain as Domain | undefined)?.id === domain.id
|
|
24
|
+
if (mine || !byName.has(row.name!)) byName.set(row.name!, row)
|
|
25
|
+
}
|
|
26
|
+
return [...byName.values()]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A recipe saved into a domain, by its name: checked first by putting it into the test room with its defaults
|
|
31
|
+
* (figure-model `checkV3Recipe`). Refused, it is not saved and the kernel's sentence goes back as it is.
|
|
32
|
+
*/
|
|
33
|
+
export async function saveRecipe(domain: Domain, source: unknown, state: 'draft' | 'released' = 'released'): Promise<FigureRecipe> {
|
|
34
|
+
const recipe = checkV3Recipe(typeof source === 'string' ? JSON.parse(source) : source)
|
|
35
|
+
const repository = getRepository(FigureRecipe)
|
|
36
|
+
const existing = await repository.findOne({ where: { domain: { id: domain.id }, name: recipe.name } })
|
|
37
|
+
return await repository.save({ ...(existing ?? {}), domain, name: recipe.name, source: JSON.stringify(recipe), state })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A recipe of the domain's own, by name. A parent's recipe is not the domain's to change: it is copied in under the same
|
|
42
|
+
* name (`saveRecipe`), and the copy stands in for it.
|
|
43
|
+
*/
|
|
44
|
+
async function ownRecipe(domain: { id: string }, name: string): Promise<FigureRecipe> {
|
|
45
|
+
const row = await getRepository(FigureRecipe).findOne({ where: { domain: { id: domain.id }, name } })
|
|
46
|
+
if (!row) throw new Error(`${name} is not a recipe of this domain; a parent's recipe is copied here to be changed`)
|
|
47
|
+
return row
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Released or back to draft: only released recipes are offered in the modeller. */
|
|
51
|
+
export async function setRecipeState(domain: { id: string }, name: string, state: 'draft' | 'released'): Promise<FigureRecipe> {
|
|
52
|
+
const row = await ownRecipe(domain, name)
|
|
53
|
+
return await getRepository(FigureRecipe).save({ ...row, state })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A recipe of the domain's own taken away. Figures it was put into keep their parts -- nothing ties them to it
|
|
58
|
+
* (ADR-0095). Where the parent has one by that name, the parent's is seen again.
|
|
59
|
+
*/
|
|
60
|
+
export async function deleteRecipe(domain: { id: string }, name: string): Promise<boolean> {
|
|
61
|
+
const row = await ownRecipe(domain, name)
|
|
62
|
+
await getRepository(FigureRecipe).softRemove(row)
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The recipes figure-model ships (`recipes/*.json`), as they are. */
|
|
67
|
+
export function builtInRecipes(): Array<{ name: string; source: string }> {
|
|
68
|
+
const dir = join(dirname(require.resolve('@hatiolab/figure-model/package.json')), 'recipes')
|
|
69
|
+
return readdirSync(dir)
|
|
70
|
+
.filter(file => file.endsWith('.json'))
|
|
71
|
+
.sort()
|
|
72
|
+
.map(file => {
|
|
73
|
+
const source = readFileSync(join(dir, file), 'utf-8')
|
|
74
|
+
return { name: JSON.parse(source).name, source }
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The built-in recipes put into the system domain (ADR-0095 condition 2): once, and again gives the same result -- a
|
|
80
|
+
* recipe already there by name is skipped, not overwritten, so a system recipe someone changed stays as they left it.
|
|
81
|
+
* Each is checked as a saved one is; one that fails is left out and said, not half put in.
|
|
82
|
+
*/
|
|
83
|
+
export async function seedBuiltInRecipes(): Promise<{ added: string[]; skipped: string[]; refused: string[] }> {
|
|
84
|
+
const system = await getRepository(Domain).findOne({ where: { systemFlag: true } })
|
|
85
|
+
const result = { added: [] as string[], skipped: [] as string[], refused: [] as string[] }
|
|
86
|
+
if (!system) return result
|
|
87
|
+
const repository = getRepository(FigureRecipe)
|
|
88
|
+
for (const { name, source } of builtInRecipes()) {
|
|
89
|
+
if (await repository.count({ where: { domain: { id: system.id }, name } })) {
|
|
90
|
+
result.skipped.push(name)
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await saveRecipe(system, source)
|
|
95
|
+
result.added.push(name)
|
|
96
|
+
} catch (error) {
|
|
97
|
+
result.refused.push(`${name}: ${error instanceof Error ? error.message : String(error)}`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result
|
|
101
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'
|
|
2
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
3
|
+
|
|
4
|
+
import { Domain, longTextColumn } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* FigureRecipe — 조각 하나(ADR-0095).
|
|
8
|
+
*
|
|
9
|
+
* 조각은 매개변수가 붙은 제안 명령 목록이다. 형식은 `@hatiolab/figure-model` 의 `V3Recipe` 가 정하고, 여기에는
|
|
10
|
+
* 그 원본을 통째로 담는다 — Figure 가 자산을 `source` 로 담는 것과 같다. 매개변수 · 명령을 컬럼으로 두지 않는다.
|
|
11
|
+
* 넣은 뒤의 부품은 조각과 이어지지 않으므로, 이 행을 고치거나 지워도 도형은 바뀌지 않는다.
|
|
12
|
+
*/
|
|
13
|
+
@Entity()
|
|
14
|
+
@Index('ix_figure_recipe_1', (recipe: FigureRecipe) => [recipe.domain, recipe.name], { unique: true, where: '"deleted_at" IS NULL' })
|
|
15
|
+
@ObjectType({ description: 'A recipe: a list of figure authoring commands with parameters (ADR-0095).' })
|
|
16
|
+
export class FigureRecipe {
|
|
17
|
+
@PrimaryGeneratedColumn('uuid')
|
|
18
|
+
@Field(type => ID, { nullable: true, description: 'Unique identifier for the recipe.' })
|
|
19
|
+
readonly id?: string
|
|
20
|
+
|
|
21
|
+
@ManyToOne(type => Domain)
|
|
22
|
+
@Field(type => Domain, { nullable: true, description: 'The domain this recipe belongs to.' })
|
|
23
|
+
domain?: Domain
|
|
24
|
+
|
|
25
|
+
@RelationId((recipe: FigureRecipe) => recipe.domain)
|
|
26
|
+
domainId?: string
|
|
27
|
+
|
|
28
|
+
@Column()
|
|
29
|
+
@Field({ description: 'The recipe name, unique per domain: lower case, digits and hyphens.' })
|
|
30
|
+
name?: string
|
|
31
|
+
|
|
32
|
+
@Column({ nullable: true, ...longTextColumn() })
|
|
33
|
+
@Field({ nullable: true, description: 'The recipe JSON (figure-model V3Recipe).' })
|
|
34
|
+
source?: string
|
|
35
|
+
|
|
36
|
+
@Column({ nullable: true, default: 'released' })
|
|
37
|
+
@Field({ nullable: true, description: "'draft' or 'released'. Only released recipes are offered in the modeller." })
|
|
38
|
+
state?: 'draft' | 'released'
|
|
39
|
+
|
|
40
|
+
@CreateDateColumn()
|
|
41
|
+
@Field({ nullable: true, description: 'When the recipe was created.' })
|
|
42
|
+
createdAt?: Date
|
|
43
|
+
|
|
44
|
+
@UpdateDateColumn()
|
|
45
|
+
@Field({ nullable: true, description: 'When the recipe was last changed.' })
|
|
46
|
+
updatedAt?: Date
|
|
47
|
+
|
|
48
|
+
@DeleteDateColumn()
|
|
49
|
+
@Field({ nullable: true, description: 'When the recipe was deleted.' })
|
|
50
|
+
deletedAt?: Date
|
|
51
|
+
}
|
package/server/service/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ export * from './figure/figure.js'
|
|
|
3
3
|
export * from './figure/figure-type.js'
|
|
4
4
|
export * from './figure/figure-format.js'
|
|
5
5
|
export * from './figure/figure-history.js'
|
|
6
|
+
export * from './figure-recipe/figure-recipe.js'
|
|
7
|
+
export { recipesFor, saveRecipe, seedBuiltInRecipes, builtInRecipes } from './figure-recipe/figure-recipe-store.js'
|
|
6
8
|
|
|
7
9
|
// Entities, resolvers
|
|
8
10
|
import {
|
|
@@ -10,8 +12,9 @@ import {
|
|
|
10
12
|
resolvers as FigureResolvers,
|
|
11
13
|
subscribers as FigureSubscribers
|
|
12
14
|
} from './figure/index.js'
|
|
15
|
+
import { entities as RecipeEntities, resolvers as RecipeResolvers } from './figure-recipe/index.js'
|
|
13
16
|
|
|
14
|
-
export const entities = [...FigureEntities]
|
|
17
|
+
export const entities = [...FigureEntities, ...RecipeEntities]
|
|
15
18
|
|
|
16
19
|
/* 판본 스냅샷을 뜨는 구독자. 셸이 이 이름으로 모아 TypeORM 에 등록한다(board-service 와 같다). */
|
|
17
20
|
export const subscribers = [...FigureSubscribers]
|
|
@@ -27,5 +30,5 @@ export const subscribers = [...FigureSubscribers]
|
|
|
27
30
|
* board-service, ops-master and font-base all export the shape below.
|
|
28
31
|
*/
|
|
29
32
|
export const schema = {
|
|
30
|
-
resolverClasses: [...FigureResolvers]
|
|
33
|
+
resolverClasses: [...FigureResolvers, ...RecipeResolvers]
|
|
31
34
|
}
|