@things-factory/figure-service 10.1.179 → 10.1.180

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/figure-service",
3
- "version": "10.1.179",
3
+ "version": "10.1.180",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "@things-factory:registry": "https://registry.npmjs.org"
@@ -38,5 +38,5 @@
38
38
  "jszip": "^3.10.1",
39
39
  "koa-router": "^7.4.0"
40
40
  },
41
- "gitHead": "4c8263b08e06b2b15f11dc0575c61a280a0d9e27"
41
+ "gitHead": "2549e50c0790c05a75781d133f5d975cff3b02f9"
42
42
  }
@@ -398,7 +398,7 @@ export class FigureMutation {
398
398
 
399
399
  /* A release promises boards the full name {namespace}/{type}: it goes out only under a namespace the domain owns and has active. */
400
400
  const namespace = namespaceOf(figure)
401
- await assertReleasableNamespace(tx, domain, namespace)
401
+ await assertReleasableNamespace(tx, domain, namespace, user)
402
402
  assertReleasableCategory(figure.category, figure.type)
403
403
 
404
404
  /*
@@ -293,3 +293,23 @@ describe('the figure package', () => {
293
293
  await expect(ask(['CONVEYOR@1'])).rejects.toMatchObject({ code: 'figure-ref-malformed' })
294
294
  })
295
295
  })
296
+
297
+ /*
298
+ * A domain whose figures were made before namespaces were rows (the setting days): it owns no namespace row, and its
299
+ * figures carry its subdomain. Releasing one is the first need of a namespace, so the subdomain becomes its first, as
300
+ * creating a figure does -- seen on :3300 after 10.1.179, where the system domain owned none.
301
+ */
302
+ describe('a domain that owns no namespace row yet', () => {
303
+ it('releases a figure carrying its subdomain, and the subdomain becomes its default', async () => {
304
+ const { domain, context } = await domainWith(null)
305
+ const figure = await dataSource!.getRepository(Figure).save({ namespace: domain.subdomain, type: 'older', name: 'older', source: releasable(), state: 'draft', version: 0, domain })
306
+ await expect(new FigureMutation().releaseFigure(figure.id, 'first', context)).resolves.toMatchObject({ version: 1 })
307
+ expect((await resolver().figureNamespaces(context)).map((n: any) => [n.name, n.isDefault])).toEqual([[domain.subdomain, true]])
308
+ })
309
+
310
+ it('a figure carrying another namespace than its subdomain is still refused by name', async () => {
311
+ const { domain, context } = await domainWith(null)
312
+ const figure = await dataSource!.getRepository(Figure).save({ namespace: unique('elsewhere'), type: 'stray', name: 'stray', source: releasable(), state: 'draft', version: 0, domain })
313
+ await expect(new FigureMutation().releaseFigure(figure.id, 'first', context)).rejects.toMatchObject({ code: 'figure-namespace-not-owned' })
314
+ })
315
+ })
@@ -42,8 +42,15 @@ export async function namespaceForNewFigure(tx: EntityManager, domain: Domain, c
42
42
  return fallback.name!
43
43
  }
44
44
 
45
- /** A release promises boards `{namespace}/{type}`: it goes out only under a namespace the domain owns and has active. */
46
- export async function assertReleasableNamespace(tx: EntityManager, domain: Domain, namespace: string): Promise<void> {
45
+ /**
46
+ * A release promises boards `{namespace}/{type}`: it goes out only under a namespace the domain owns and has active. A
47
+ * domain that owns none yet -- its figures were made before namespaces were rows -- gets its subdomain as its first,
48
+ * as creating a figure does; a figure carrying another namespace is still refused by name.
49
+ */
50
+ export async function assertReleasableNamespace(tx: EntityManager, domain: Domain, namespace: string, user?: Actor): Promise<void> {
51
+ if ((await tx.getRepository(FigureNamespace).count({ where: { domain: { id: domain.id } } })) === 0) {
52
+ await firstNamespace(tx, domain, user)
53
+ }
47
54
  await activeOwn(tx, domain, namespace)
48
55
  }
49
56