@things-factory/ops-master 10.1.296 → 10.1.298

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.
@@ -35,6 +35,9 @@ export * from './asset/asset-query';
35
35
  export * from './location/operational-location';
36
36
  export * from './location/location-master';
37
37
  export * from './location/location-query';
38
+ export * from './location/sites-of-system';
39
+ export * from './location/zone-of-place';
40
+ export * from './location/zone-of-home-place';
38
41
  export * from './material/material-class';
39
42
  export * from './material/material-definition';
40
43
  export * from './material/material-revision';
@@ -71,6 +74,8 @@ export * from './quality/nonconformance-cause';
71
74
  import { MasterConformanceResolver } from './master-conformance-resolver';
72
75
  import { MasterChangePolicy, MasterChangePolicyResolver } from './master-change-policy';
73
76
  import { MasterValueClaim } from './assignment/master-value-claim';
77
+ import { SiteOfSystemSubscriber } from './location/sites-of-system';
78
+ export declare const subscribers: (typeof SiteOfSystemSubscriber)[];
74
79
  export declare const entities: (typeof import("./equipment/equipment").Equipment | typeof import("./equipment/equipment-class").EquipmentClass | typeof import("./quality/nonconformance-cause").NonconformanceCause | typeof import("./material/material-definition").MaterialDefinition | typeof import("./operation/operation-definition").OperationDefinition | typeof import("./location/operational-location").OperationalLocation | typeof import("./personnel/person").Person | typeof import("./asset/physical-asset").PhysicalAsset | typeof import("./recipe").RecipeDefinition | typeof import("./recipe").RouteDefinition | typeof import("./test-spec/test-specification").TestSpecification | typeof MasterChangePolicy | typeof import("./material/material-revision").MaterialDefinitionRevision | typeof import("./material/material-revision").MaterialDefinitionPlan | typeof import("./material/material-revision").MaterialDefinitionSegment | typeof import("./material/material-revision").MaterialDefinitionBasis | typeof import("./recipe/recipe-revision").RecipeRevision | typeof import("./recipe/recipe-revision-line").RecipeRevisionOutput | typeof import("./recipe/recipe-revision").RecipePlan | typeof import("./recipe/recipe-revision").RecipeSegment | typeof import("./recipe/recipe-revision").RecipeBasis | typeof import("./test-spec/test-spec-revision").TestSpecificationRevision | typeof import("./test-spec/test-spec-revision").TestSpecificationPlan | typeof import("./test-spec/test-spec-revision").TestSpecificationSegment | typeof import("./test-spec/test-spec-revision").TestSpecificationBasis | typeof MasterValueClaim)[];
75
80
  export declare const schema: {
76
81
  resolverClasses: (typeof MasterChangePolicyResolver | typeof import("./personnel/personnel-master-resolver").PersonnelClassResolver | typeof import("./personnel/personnel-master-resolver").PersonResolver | typeof import("./equipment/equipment-master-resolver").EquipmentClassResolver | typeof import("./equipment/equipment-master-resolver").EquipmentResolver | typeof import("./equipment/equipment-master-resolver").StopReasonResolver | typeof import("./asset/asset-master-resolver").PhysicalAssetClassResolver | typeof import("./asset/asset-master-resolver").PhysicalAssetResolver | typeof import("./material/material-master-resolver").MaterialClassResolver | typeof import("./material/material-master-resolver").MaterialDefinitionResolver | typeof import("./location/location-master-resolver").OperationalLocationResolver | typeof import("./operation/operation-master-resolver").OperationDefinitionResolver | typeof import("./recipe/recipe-master-resolver").RecipeDefinitionResolver | typeof import("./recipe/recipe-master-resolver").RouteDefinitionResolver | typeof import("./test-spec/test-spec-master-resolver").TestSpecificationResolver | typeof import("./master-change-approval").MasterChangeApprovalResolver | typeof MasterConformanceResolver | typeof import("./personnel/personnel-query").PersonnelQuery | typeof import("./equipment/equipment-query").EquipmentQuery | typeof import("./asset/asset-query").AssetQuery | typeof import("./location/location-query").LocationQuery | typeof import("./material/material-revision-resolver").MaterialDefinitionRevisionResolver | typeof import("./material/material-query").MaterialQuery | typeof import("./operation/operation-query").OperationQuery | typeof import("./operation/operation-readiness-resolver").OperationReadinessResolver | typeof import("./recipe/recipe-revision-resolver").RecipeRevisionResolver | typeof import("./recipe/recipe-query").RecipeQuery | typeof import("./test-spec/test-spec-revision-resolver").TestSpecificationRevisionResolver | typeof import("./test-spec/test-spec-query").TestSpecificationQuery | typeof import("./status/master-status").OpsMasterStatusQuery | typeof import("./equipment/stop-reason-query").StopReasonQuery | typeof import("./quality/nonconformance-cause-resolver").NonconformanceCauseResolver)[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.opsMasterEntryLabelKey = exports.opsMasterEntryKey = exports.OPS_MASTER_ENTRY_AXES = exports.OPS_MASTER_ENTRY_SPECS = exports.opsMasterEntryTargetOf = exports.opsMasterEntryTargets = exports.schema = exports.entities = void 0;
3
+ exports.opsMasterEntryLabelKey = exports.opsMasterEntryKey = exports.OPS_MASTER_ENTRY_AXES = exports.OPS_MASTER_ENTRY_SPECS = exports.opsMasterEntryTargetOf = exports.opsMasterEntryTargets = exports.schema = exports.entities = exports.subscribers = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /* EXPORT ENTITY TYPES */
6
6
  tslib_1.__exportStar(require("./resource/resource-class"), exports);
@@ -40,6 +40,9 @@ tslib_1.__exportStar(require("./asset/asset-query"), exports);
40
40
  tslib_1.__exportStar(require("./location/operational-location"), exports);
41
41
  tslib_1.__exportStar(require("./location/location-master"), exports);
42
42
  tslib_1.__exportStar(require("./location/location-query"), exports);
43
+ tslib_1.__exportStar(require("./location/sites-of-system"), exports);
44
+ tslib_1.__exportStar(require("./location/zone-of-place"), exports);
45
+ tslib_1.__exportStar(require("./location/zone-of-home-place"), exports);
43
46
  tslib_1.__exportStar(require("./material/material-class"), exports);
44
47
  tslib_1.__exportStar(require("./material/material-definition"), exports);
45
48
  tslib_1.__exportStar(require("./material/material-revision"), exports);
@@ -90,6 +93,9 @@ const master_change_policy_1 = require("./master-change-policy");
90
93
  const master_value_claim_1 = require("./assignment/master-value-claim");
91
94
  const test_spec_1 = require("./test-spec");
92
95
  const master_change_approval_1 = require("./master-change-approval");
96
+ /* A site that places its first place of a system gets that system's site steps (`onEachSiteOfSystem`). */
97
+ const sites_of_system_1 = require("./location/sites-of-system");
98
+ exports.subscribers = [sites_of_system_1.SiteOfSystemSubscriber];
93
99
  exports.entities = [
94
100
  /* ENTITIES */
95
101
  master_change_policy_1.MasterChangePolicy,
@@ -0,0 +1,31 @@
1
+ import { type EntityManager, type EntitySubscriberInterface, type InsertEvent } from 'typeorm';
2
+ import { Domain } from '@things-factory/shell';
3
+ import { OperationalLocation } from './operational-location';
4
+ /**
5
+ * **The sites that run a system** - the domains that declared places of it (`OperationalLocation.system`, and a `type`
6
+ * when given: a yard's dock doors, a warehouse's bins). A product works only where its places are: settings to seed,
7
+ * to-dos to install, a sweep to run.
8
+ *
9
+ * Lifted on 2026-11-18 from the yard and the warehouse, which each walked the places at boot and in their sweeps.
10
+ */
11
+ export declare function sitesOfSystem(manager: EntityManager, system: string, type?: string): Promise<Domain[]>;
12
+ /**
13
+ * **For every site of a system - at boot, and when a site becomes one** - in the boot's own turn (`inBootTurn`, shell: sqlite
14
+ * holds one connection, and two boot transactions crossing on it broke each other). A site that fails is logged and the
15
+ * next one runs; boot never stops half done - the next boot does it again.
16
+ *
17
+ * A domain becomes a site of a system when it places its first place of it - not when it is created, so `onDomainCreated`
18
+ * cannot see it. Walking only at boot left such a site without its settings and to-dos until the next restart (release check
19
+ * 2026-11-19: a yard site made after boot had no exception-card form). So the step also runs **once per site after the commit
20
+ * that inserted a place of the system** (`SiteOfSystemSubscriber`); a site already walked in this process is not walked again.
21
+ * The work must be safe to repeat - it already was, since every boot repeats it.
22
+ *
23
+ * ```ts
24
+ * onEachSiteOfSystem('yms', 'operato-yard', async (manager, domain) => { await YARD_SETTINGS.seed(manager, domain) })
25
+ * ```
26
+ */
27
+ export declare function onEachSiteOfSystem(system: string, label: string, work: (manager: EntityManager, domain: Domain) => Promise<unknown>): void;
28
+ export declare class SiteOfSystemSubscriber implements EntitySubscriberInterface<OperationalLocation> {
29
+ listenTo(): typeof OperationalLocation;
30
+ afterInsert(event: InsertEvent<OperationalLocation>): Promise<void>;
31
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SiteOfSystemSubscriber = void 0;
4
+ exports.sitesOfSystem = sitesOfSystem;
5
+ exports.onEachSiteOfSystem = onEachSiteOfSystem;
6
+ const tslib_1 = require("tslib");
7
+ const typeorm_1 = require("typeorm");
8
+ const shell_1 = require("@things-factory/shell");
9
+ const operational_location_1 = require("./operational-location");
10
+ /**
11
+ * **The sites that run a system** - the domains that declared places of it (`OperationalLocation.system`, and a `type`
12
+ * when given: a yard's dock doors, a warehouse's bins). A product works only where its places are: settings to seed,
13
+ * to-dos to install, a sweep to run.
14
+ *
15
+ * Lifted on 2026-11-18 from the yard and the warehouse, which each walked the places at boot and in their sweeps.
16
+ */
17
+ async function sitesOfSystem(manager, system, type) {
18
+ const places = await manager.getRepository(operational_location_1.OperationalLocation).find({ where: { system, ...(type ? { type } : {}) }, relations: ['domain'] });
19
+ const byId = new Map();
20
+ for (const place of places)
21
+ if (place.domain)
22
+ byId.set(place.domain.id, place.domain);
23
+ return [...byId.values()];
24
+ }
25
+ const steps = [];
26
+ /** step → the sites it has already walked in this process (at boot, or when the site placed its first place of the system). */
27
+ const walked = new Map();
28
+ async function walk(step, manager, domain) {
29
+ const seen = walked.get(step);
30
+ if (seen.has(domain.id))
31
+ return;
32
+ seen.add(domain.id);
33
+ try {
34
+ await step.work(manager, domain);
35
+ }
36
+ catch (error) {
37
+ console.warn(`[${step.label}] ${domain.subdomain}: site step failed - the next boot does it again. ${error?.message ?? error}`);
38
+ }
39
+ }
40
+ /**
41
+ * **For every site of a system - at boot, and when a site becomes one** - in the boot's own turn (`inBootTurn`, shell: sqlite
42
+ * holds one connection, and two boot transactions crossing on it broke each other). A site that fails is logged and the
43
+ * next one runs; boot never stops half done - the next boot does it again.
44
+ *
45
+ * A domain becomes a site of a system when it places its first place of it - not when it is created, so `onDomainCreated`
46
+ * cannot see it. Walking only at boot left such a site without its settings and to-dos until the next restart (release check
47
+ * 2026-11-19: a yard site made after boot had no exception-card form). So the step also runs **once per site after the commit
48
+ * that inserted a place of the system** (`SiteOfSystemSubscriber`); a site already walked in this process is not walked again.
49
+ * The work must be safe to repeat - it already was, since every boot repeats it.
50
+ *
51
+ * ```ts
52
+ * onEachSiteOfSystem('yms', 'operato-yard', async (manager, domain) => { await YARD_SETTINGS.seed(manager, domain) })
53
+ * ```
54
+ */
55
+ function onEachSiteOfSystem(system, label, work) {
56
+ const step = { system, label, work };
57
+ steps.push(step);
58
+ walked.set(step, new Set());
59
+ process.on('bootstrap-module-start', () => {
60
+ (0, shell_1.inBootTurn)(async () => {
61
+ const manager = (0, shell_1.getRepository)(shell_1.Domain).manager;
62
+ for (const domain of await sitesOfSystem(manager, system))
63
+ await walk(step, manager, domain);
64
+ }).catch(error => console.warn(`[${label}] could not walk the sites of ${system} at boot - ${error?.message ?? error}`));
65
+ });
66
+ }
67
+ let SiteOfSystemSubscriber = class SiteOfSystemSubscriber {
68
+ listenTo() {
69
+ return operational_location_1.OperationalLocation;
70
+ }
71
+ async afterInsert(event) {
72
+ const place = event.entity;
73
+ const domainId = place?.domain?.id ?? place?.domainId;
74
+ const due = steps.filter(step => step.system === place?.system && domainId && !walked.get(step).has(domainId));
75
+ if (!due.length)
76
+ return;
77
+ await (0, shell_1.afterManagerCommit)(event.manager, 'site of system', async () => {
78
+ const manager = (0, shell_1.getRepository)(shell_1.Domain).manager;
79
+ const domain = await manager.findOne(shell_1.Domain, { where: { id: domainId } });
80
+ if (domain)
81
+ for (const step of due)
82
+ await walk(step, manager, domain);
83
+ }, (message, error) => console.warn(`[ops-master] ${message}: ${error?.message ?? error}`));
84
+ }
85
+ };
86
+ exports.SiteOfSystemSubscriber = SiteOfSystemSubscriber;
87
+ exports.SiteOfSystemSubscriber = SiteOfSystemSubscriber = tslib_1.__decorate([
88
+ (0, typeorm_1.EventSubscriber)()
89
+ ], SiteOfSystemSubscriber);
90
+ //# sourceMappingURL=sites-of-system.js.map
@@ -0,0 +1,4 @@
1
+ import type { EntityManager } from 'typeorm';
2
+ import type { Domain } from '@things-factory/shell';
3
+ /** The same, read from a site's places - for a station ground reader: which zone a bench's home place stands in. */
4
+ export declare function zoneOfHomePlace(manager: EntityManager, domain: Domain, home: string | undefined): Promise<string | undefined>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zoneOfHomePlace = zoneOfHomePlace;
4
+ const operational_location_1 = require("./operational-location");
5
+ const zone_of_place_1 = require("./zone-of-place");
6
+ /** The same, read from a site's places - for a station ground reader: which zone a bench's home place stands in. */
7
+ async function zoneOfHomePlace(manager, domain, home) {
8
+ if (!home)
9
+ return undefined;
10
+ const places = (await manager.find(operational_location_1.OperationalLocation, {
11
+ where: { domain: { id: domain.id } },
12
+ select: { id: true, name: true, type: true, level: true, parentId: true, system: true }
13
+ }));
14
+ return (0, zone_of_place_1.zoneOfPlace)(places, home);
15
+ }
16
+ //# sourceMappingURL=zone-of-home-place.js.map
@@ -0,0 +1,20 @@
1
+ import { type EquipmentLevel } from '@operato/ops-contract';
2
+ /** The columns the walk reads - a place's own name, its type or declared level, its parent and its system. */
3
+ export interface PlaceRow {
4
+ /** The row id - a child may name its parent by it (`parentId` holds a row id in some sites and a name in others). */
5
+ id?: string;
6
+ name: string;
7
+ type?: string;
8
+ level?: string;
9
+ parentId?: string;
10
+ system?: string;
11
+ }
12
+ /**
13
+ * **The zone a place belongs to** - the place itself when it is a zone, else its nearest ancestor of level `StorageZone`
14
+ * (ISA-95). A pure walk over the rows given; a place's level is its declared `level`, else its type's level in its own
15
+ * system (`levelOfLocationType`, the contract's catalogue). Nothing found answers nothing - not a guess.
16
+ *
17
+ * Lifted on 2026-11-19 from operato-warehouse's station ground (`zoneOf`): the yard's station ground needs the same walk -
18
+ * a yard's staging area and a warehouse's storage zone are the same ISA-95 level - and a third product would copy it again.
19
+ */
20
+ export declare function zoneOfPlace(places: readonly PlaceRow[], home: string | undefined, level?: EquipmentLevel): string | undefined;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zoneOfPlace = zoneOfPlace;
4
+ const ops_contract_1 = require("@operato/ops-contract");
5
+ /**
6
+ * **The zone a place belongs to** - the place itself when it is a zone, else its nearest ancestor of level `StorageZone`
7
+ * (ISA-95). A pure walk over the rows given; a place's level is its declared `level`, else its type's level in its own
8
+ * system (`levelOfLocationType`, the contract's catalogue). Nothing found answers nothing - not a guess.
9
+ *
10
+ * Lifted on 2026-11-19 from operato-warehouse's station ground (`zoneOf`): the yard's station ground needs the same walk -
11
+ * a yard's staging area and a warehouse's storage zone are the same ISA-95 level - and a third product would copy it again.
12
+ */
13
+ function zoneOfPlace(places, home, level = 'StorageZone') {
14
+ if (!home)
15
+ return undefined;
16
+ const byName = new Map(places.map(place => [place.name, place]));
17
+ const levelOf = (place) => place?.level ?? (place?.type ? (0, ops_contract_1.levelOfLocationType)(place.type, place.system) : undefined);
18
+ /* A parent named by its row id is read as that row's name - both spellings stand in real data. */
19
+ const nameOfId = new Map(places.filter(place => place.id).map(place => [place.id, place.name]));
20
+ const parentOf = (place) => (place.parentId ? (nameOfId.get(place.parentId) ?? place.parentId) : undefined);
21
+ const own = byName.get(home);
22
+ if (!own)
23
+ return undefined;
24
+ if (levelOf(own) === level)
25
+ return home;
26
+ const hierarchy = (0, ops_contract_1.hierarchyOf)({ locations: places.map(place => ({ id: place.name, type: place.type, level: levelOf(place), parentId: parentOf(place) })) }, type => (0, ops_contract_1.levelOfLocationType)(type, own.system));
27
+ return hierarchy.ancestorOfLevel(home, level);
28
+ }
29
+ //# sourceMappingURL=zone-of-place.js.map
@@ -128,6 +128,18 @@ async function masterChangePolicy(manager, domainId, axis) {
128
128
  }
129
129
  if (!manager.queryRunner?.isTransactionActive)
130
130
  throw new shell_1.Refusal('TRANSACTION_REQUIRED', {}, 'A transaction is required.');
131
+ /*
132
+ * 처음 줄을 세우는 것은 **한 번에 한 사람만** 한다(2026-11-19). 안 그러면 새 사업장에서 서로 다른 기준정보를
133
+ * 동시에 저장한 트랜잭션들이 저마다 「줄이 없다」를 보고 저마다 기본 줄을 세웠다 — 한 축에 서 있는 줄이
134
+ * 여럿이 되고, 먼저 끝난 쪽의 줄이 나중에 다시 읽힐 때 「지금 정책」이 바뀌어 보여서 나머지가 발행에서
135
+ * `PLAN_CONFLICT` 를 받았다(postgres, `revision-locks.db.test`). 잡은 뒤 다시 읽는다 — 앞사람이 세운 줄이
136
+ * 보이면 그것을 쓴다. 줄이 이미 서 있으면 여기까지 오지 않으므로 평소 쓰기는 아무것도 기다리지 않는다.
137
+ */
138
+ await holdDomainPolicies(manager, domainId);
139
+ const stood = await standingPolicy(manager, domainId, axis);
140
+ if (stood) {
141
+ return stood;
142
+ }
131
143
  return manager.save(MasterChangePolicy, manager.create(MasterChangePolicy, {
132
144
  domain: { id: domainId },
133
145
  axis,
@@ -135,6 +147,21 @@ async function masterChangePolicy(manager, domainId, axis) {
135
147
  reason: 'nobody set this axis; it runs on the default'
136
148
  }));
137
149
  }
150
+ /**
151
+ * 이 도메인의 정책 줄을 세우거나 물리는 사람은 **한 번에 하나** — 도메인 줄을 잡아서 줄을 세운다.
152
+ *
153
+ * postgres 는 `FOR NO KEY UPDATE` 다. 같은 도메인에 무엇을 넣는 트랜잭션은 외래키 때문에 그 줄에
154
+ * `FOR KEY SHARE` 를 쥐는데, `FOR UPDATE` 는 그것과 부딪혀 둘이 서로를 기다리다 교착한다(`writeLockOn` 참조).
155
+ * `NO KEY UPDATE` 는 그것과 안 부딪히고 저희끼리만 줄을 세운다. sqlite 는 쓰는 이가 하나라 잡을 것이 없다.
156
+ */
157
+ async function holdDomainPolicies(manager, domainId) {
158
+ if (!(0, shell_1.writeLockSupported)(manager))
159
+ return;
160
+ const lock = manager.connection.options.type === 'postgres'
161
+ ? { mode: 'for_no_key_update', tables: [manager.connection.getMetadata(shell_1.Domain).tableNameWithoutPrefix] }
162
+ : { mode: 'pessimistic_write' };
163
+ await manager.findOne(shell_1.Domain, { where: { id: domainId }, lock });
164
+ }
138
165
  /** 이 축에서 물러나지 않은 줄 전부 — 보통 하나다. */
139
166
  function standingRows(manager, domainId, axis) {
140
167
  return manager.findBy(MasterChangePolicy, { domain: { id: domainId }, axis, supersededAt: (0, typeorm_2.IsNull)() });
@@ -178,6 +205,8 @@ async function declareMasterChangePolicy(manager, domainId, actorId, axis, appro
178
205
  throw new shell_1.Refusal('MASTER_AXIS_HAS_NO_REVISION', { axis }, 'This master cannot be sent for approval yet, so it cannot be set to change only after approval.');
179
206
  await (0, approval_route_1.assertApprovalRouteReady)(manager, domainId, axis);
180
207
  }
208
+ /* 기본 줄을 세우는 쪽(`masterChangePolicy`)과 같은 자리에 줄을 선다 — 둘이 겹쳐 줄이 둘 서지 않도록. */
209
+ await holdDomainPolicies(manager, domainId);
181
210
  const standing = await standingRows(manager, domainId, axis);
182
211
  /*
183
212
  * 같은 값을 다시 정하는 것은 아무 일도 아니다 — **하나만 서 있을 때** 그렇다. 여럿이 서 있으면
@@ -27,7 +27,7 @@ const material_class_1 = require("./material-class");
27
27
  const test_specification_1 = require("../test-spec/test-specification");
28
28
  const material_revision_1 = require("./material-revision");
29
29
  const approval_input_1 = require("../master-change-approval/approval-input");
30
- const row_lock_1 = require("../row-lock");
30
+ const shell_2 = require("@things-factory/shell");
31
31
  class MaterialDefinitionRefusal extends shell_1.Refusal {
32
32
  constructor(code, detail) {
33
33
  super(code, {}, detail ?? MATERIAL_DEFINITION_REFUSALS[code] ?? 'The material definition change could not be applied.');
@@ -168,7 +168,7 @@ function content(input) {
168
168
  async function subject(manager, domainId, materialId) {
169
169
  const material = await manager.findOne(material_definition_1.MaterialDefinition, {
170
170
  where: { id: materialId, domain: { id: domainId } },
171
- ...(0, row_lock_1.writeLockOn)(manager, material_definition_1.MaterialDefinition)
171
+ ...(0, shell_2.writeLockOn)(manager, material_definition_1.MaterialDefinition)
172
172
  });
173
173
  if (!material)
174
174
  refuse('MATERIAL_NOT_FOUND');
@@ -189,7 +189,7 @@ async function subject(manager, domainId, materialId) {
189
189
  async function revision(manager, domainId, revisionId, locked = true) {
190
190
  const found = await manager.findOne(material_revision_1.MaterialDefinitionRevision, {
191
191
  where: { id: revisionId, domain: { id: domainId } },
192
- ...(locked ? (0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionRevision) : {})
192
+ ...(locked ? (0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionRevision) : {})
193
193
  });
194
194
  if (!found)
195
195
  refuse('REVISION_NOT_FOUND');
@@ -229,7 +229,7 @@ async function createMaterialDefinitionDraft(manager, domainId, creatorId, asked
229
229
  }
230
230
  const previous = await manager.findOne(material_revision_1.MaterialDefinitionRevision, {
231
231
  where: { domain: { id: domainId }, material: { id: material.id } }, order: { revisionNumber: 'DESC' },
232
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionRevision)
232
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionRevision)
233
233
  });
234
234
  const revisionNumber = (previous?.revisionNumber ?? 0) + 1;
235
235
  let baseRevisionId = null;
@@ -373,7 +373,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
373
373
  text(decision.actorId, 'publisher');
374
374
  const previousDecision = await manager.findOne(material_revision_1.MaterialDefinitionPlan, {
375
375
  where: { domain: { id: domainId }, publishedRevision: { id: revisionId } },
376
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
376
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
377
377
  });
378
378
  if (previousDecision)
379
379
  return previousDecision;
@@ -383,12 +383,12 @@ async function publishRevision(manager, domainId, revisionId, decision) {
383
383
  await (0, material_revision_content_1.validateMaterialReferences)(manager, domainId, draft);
384
384
  if (await manager.findOne(material_revision_1.MaterialDefinitionBasis, {
385
385
  where: { domain: { id: domainId }, material: { id: material.id }, businessTime: (0, typeorm_1.MoreThanOrEqual)(draft.effectiveFrom) },
386
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionBasis)
386
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionBasis)
387
387
  }))
388
388
  refuse('RETROACTIVE_IMPACT');
389
389
  const oldPlan = await manager.findOne(material_revision_1.MaterialDefinitionPlan, {
390
390
  where: { domain: { id: domainId }, material: { id: material.id }, generation: material.planGeneration },
391
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
391
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
392
392
  });
393
393
  if (material.planGeneration > 0 && !oldPlan)
394
394
  refuse('PLAN_CONFLICT');
@@ -396,7 +396,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
396
396
  ? await manager.find(material_revision_1.MaterialDefinitionSegment, {
397
397
  where: { domain: { id: domainId }, material: { id: material.id }, plan: { id: oldPlan.id } },
398
398
  order: { validFrom: 'ASC' },
399
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionSegment)
399
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionSegment)
400
400
  })
401
401
  : [];
402
402
  // Do not silently erase an already approved future appointment.
@@ -445,7 +445,7 @@ async function resolveMaterialDefinition(manager, domainId, materialId, business
445
445
  const plan = await manager.findOne(material_revision_1.MaterialDefinitionPlan, {
446
446
  where: { domain: { id: domainId }, material: { id: materialId }, recordedAt: (0, typeorm_1.LessThanOrEqual)(known) },
447
447
  order: { generation: 'DESC' },
448
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
448
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionPlan)
449
449
  });
450
450
  if (!plan)
451
451
  refuse('NO_EFFECTIVE_REVISION');
@@ -455,7 +455,7 @@ async function resolveMaterialDefinition(manager, domainId, materialId, business
455
455
  .where({ domain: { id: domainId }, material: { id: materialId }, plan: { id: plan.id } })
456
456
  .andWhere('segment.validFrom <= :at', { at })
457
457
  .andWhere('(segment.validTo IS NULL OR segment.validTo > :at)', { at });
458
- (0, row_lock_1.lockRowsOf)(manager, query);
458
+ (0, shell_2.lockRowsOf)(manager, query);
459
459
  const segments = await query.getMany();
460
460
  if (!segments.length)
461
461
  await refuseBeforeBaseline(manager, domainId, materialId, at);
@@ -599,7 +599,7 @@ async function captureMaterialDefinitionBasis(manager, domainId, materialId, rec
599
599
  await lockSubject(manager, domainId, materialId);
600
600
  const existing = await manager.findOne(material_revision_1.MaterialDefinitionBasis, {
601
601
  where: { domain: { id: domainId }, recordKey },
602
- ...(0, row_lock_1.writeLockOn)(manager, material_revision_1.MaterialDefinitionBasis)
602
+ ...(0, shell_2.writeLockOn)(manager, material_revision_1.MaterialDefinitionBasis)
603
603
  });
604
604
  if (existing) {
605
605
  if (existing.materialId !== materialId || existing.businessTime.getTime() !== at.getTime())
@@ -29,7 +29,7 @@ const route_definition_1 = require("./route-definition");
29
29
  const recipe_revision_content_1 = require("./recipe-revision-content");
30
30
  const recipe_revision_1 = require("./recipe-revision");
31
31
  const approval_input_1 = require("../master-change-approval/approval-input");
32
- const row_lock_1 = require("../row-lock");
32
+ const shell_2 = require("@things-factory/shell");
33
33
  async function saveLines(manager, domainId, recipeId, revisionId, inputs, outputs) {
34
34
  const header = await manager.findOneByOrFail(recipe_revision_1.RecipeRevision, { id: revisionId, domain: { id: domainId } });
35
35
  const route = header.route ? await manager.findOneBy(route_definition_1.RouteDefinition, { domain: { id: domainId }, name: header.route }) : null;
@@ -201,7 +201,7 @@ async function assertRecipeApprovalInput(manager, domainId, input) {
201
201
  async function subject(manager, domainId, recipeId) {
202
202
  const recipe = await manager.findOne(recipe_definition_1.RecipeDefinition, {
203
203
  where: { id: recipeId, domain: { id: domainId } },
204
- ...(0, row_lock_1.writeLockOn)(manager, recipe_definition_1.RecipeDefinition)
204
+ ...(0, shell_2.writeLockOn)(manager, recipe_definition_1.RecipeDefinition)
205
205
  });
206
206
  if (!recipe)
207
207
  refuse('RECIPE_NOT_FOUND');
@@ -223,7 +223,7 @@ async function revision(manager, domainId, revisionId, locked = true) {
223
223
  const found = await manager.findOne(recipe_revision_1.RecipeRevision, {
224
224
  where: { id: revisionId, domain: { id: domainId } },
225
225
  relations: { inputs: true, outputs: true },
226
- ...(locked ? (0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipeRevision) : {})
226
+ ...(locked ? (0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipeRevision) : {})
227
227
  });
228
228
  if (!found)
229
229
  refuse('REVISION_NOT_FOUND');
@@ -267,7 +267,7 @@ async function createRecipeDraft(manager, domainId, creatorId, asked) {
267
267
  }
268
268
  const previous = await manager.findOne(recipe_revision_1.RecipeRevision, {
269
269
  where: { domain: { id: domainId }, recipe: { id: recipe.id } }, order: { revisionNumber: 'DESC' },
270
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipeRevision)
270
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipeRevision)
271
271
  });
272
272
  const revisionNumber = (previous?.revisionNumber ?? 0) + 1;
273
273
  let baseRevisionId = null;
@@ -417,7 +417,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
417
417
  text(decision.actorId, 'publisher');
418
418
  const previousDecision = await manager.findOne(recipe_revision_1.RecipePlan, {
419
419
  where: { domain: { id: domainId }, publishedRevision: { id: revisionId } },
420
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipePlan)
420
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipePlan)
421
421
  });
422
422
  if (previousDecision)
423
423
  return previousDecision;
@@ -426,12 +426,12 @@ async function publishRevision(manager, domainId, revisionId, decision) {
426
426
  // Only replacement from effectiveFrom onward is supported in this slice, not arbitrary rescheduling.
427
427
  if (await manager.findOne(recipe_revision_1.RecipeBasis, {
428
428
  where: { domain: { id: domainId }, recipe: { id: recipe.id }, businessTime: (0, typeorm_1.MoreThanOrEqual)(draft.effectiveFrom) },
429
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipeBasis)
429
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipeBasis)
430
430
  }))
431
431
  refuse('RETROACTIVE_IMPACT');
432
432
  const oldPlan = await manager.findOne(recipe_revision_1.RecipePlan, {
433
433
  where: { domain: { id: domainId }, recipe: { id: recipe.id }, generation: recipe.planGeneration },
434
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipePlan)
434
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipePlan)
435
435
  });
436
436
  if (recipe.planGeneration > 0 && !oldPlan)
437
437
  refuse('PLAN_CONFLICT');
@@ -439,7 +439,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
439
439
  ? await manager.find(recipe_revision_1.RecipeSegment, {
440
440
  where: { domain: { id: domainId }, recipe: { id: recipe.id }, plan: { id: oldPlan.id } },
441
441
  order: { validFrom: 'ASC' },
442
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipeSegment)
442
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipeSegment)
443
443
  })
444
444
  : [];
445
445
  // Do not silently erase an already approved future appointment.
@@ -488,7 +488,7 @@ async function resolveRecipe(manager, domainId, recipeId, businessTime, knownAt
488
488
  const plan = await manager.findOne(recipe_revision_1.RecipePlan, {
489
489
  where: { domain: { id: domainId }, recipe: { id: recipeId }, recordedAt: (0, typeorm_1.LessThanOrEqual)(known) },
490
490
  order: { generation: 'DESC' },
491
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipePlan)
491
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipePlan)
492
492
  });
493
493
  if (!plan)
494
494
  refuse('NO_EFFECTIVE_REVISION');
@@ -498,7 +498,7 @@ async function resolveRecipe(manager, domainId, recipeId, businessTime, knownAt
498
498
  .where({ domain: { id: domainId }, recipe: { id: recipeId }, plan: { id: plan.id } })
499
499
  .andWhere('segment.validFrom <= :at', { at })
500
500
  .andWhere('(segment.validTo IS NULL OR segment.validTo > :at)', { at });
501
- (0, row_lock_1.lockRowsOf)(manager, query);
501
+ (0, shell_2.lockRowsOf)(manager, query);
502
502
  const segments = await query.getMany();
503
503
  if (!segments.length)
504
504
  await refuseBeforeBaseline(manager, domainId, recipeId, at);
@@ -652,7 +652,7 @@ async function captureRecipeBasis(manager, domainId, recipeId, recordKey, busine
652
652
  await lockSubject(manager, domainId, recipeId);
653
653
  const existing = await manager.findOne(recipe_revision_1.RecipeBasis, {
654
654
  where: { domain: { id: domainId }, recordKey },
655
- ...(0, row_lock_1.writeLockOn)(manager, recipe_revision_1.RecipeBasis)
655
+ ...(0, shell_2.writeLockOn)(manager, recipe_revision_1.RecipeBasis)
656
656
  });
657
657
  if (existing) {
658
658
  if (existing.recipeId !== recipeId || existing.businessTime.getTime() !== at.getTime())
@@ -663,7 +663,7 @@ async function captureRecipeBasis(manager, domainId, recipeId, recordKey, busine
663
663
  const resolvedAt = new Date();
664
664
  const selected = await resolveRecipe(manager, domainId, recipeId, at, resolvedAt);
665
665
  const route = selected.revision.routeDefinitionId ? await manager.findOne(route_definition_1.RouteDefinition, {
666
- where: { id: selected.revision.routeDefinitionId, domain: { id: domainId } }, ...(0, row_lock_1.writeLockOn)(manager, route_definition_1.RouteDefinition)
666
+ where: { id: selected.revision.routeDefinitionId, domain: { id: domainId } }, ...(0, shell_2.writeLockOn)(manager, route_definition_1.RouteDefinition)
667
667
  }) : null;
668
668
  if (selected.revision.routeDefinitionId && (!route ||
669
669
  (route.effectiveStart && route.effectiveStart > at) || (route.effectiveEnd && route.effectiveEnd <= at)))
@@ -25,7 +25,7 @@ const criteria_check_1 = require("./criteria-check");
25
25
  const test_specification_1 = require("./test-specification");
26
26
  const test_spec_revision_1 = require("./test-spec-revision");
27
27
  const approval_input_1 = require("../master-change-approval/approval-input");
28
- const row_lock_1 = require("../row-lock");
28
+ const shell_2 = require("@things-factory/shell");
29
29
  class TestSpecificationRefusal extends shell_1.Refusal {
30
30
  constructor(code, detail) {
31
31
  super(code, {}, detail ?? TEST_SPECIFICATION_REFUSALS[code] ?? 'The test specification change could not be applied.');
@@ -181,7 +181,7 @@ function content(input) {
181
181
  async function subject(manager, domainId, specId) {
182
182
  const spec = await manager.findOne(test_specification_1.TestSpecification, {
183
183
  where: { id: specId, domain: { id: domainId } },
184
- ...(0, row_lock_1.writeLockOn)(manager, test_specification_1.TestSpecification)
184
+ ...(0, shell_2.writeLockOn)(manager, test_specification_1.TestSpecification)
185
185
  });
186
186
  if (!spec)
187
187
  refuse('SPECIFICATION_NOT_FOUND');
@@ -202,7 +202,7 @@ async function subject(manager, domainId, specId) {
202
202
  async function revision(manager, domainId, revisionId, locked = true) {
203
203
  const found = await manager.findOne(test_spec_revision_1.TestSpecificationRevision, {
204
204
  where: { id: revisionId, domain: { id: domainId } },
205
- ...(locked ? (0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationRevision) : {})
205
+ ...(locked ? (0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationRevision) : {})
206
206
  });
207
207
  if (!found)
208
208
  refuse('REVISION_NOT_FOUND');
@@ -241,7 +241,7 @@ async function createTestSpecificationDraft(manager, domainId, creatorId, asked)
241
241
  }
242
242
  const previous = await manager.findOne(test_spec_revision_1.TestSpecificationRevision, {
243
243
  where: { domain: { id: domainId }, spec: { id: spec.id } }, order: { revisionNumber: 'DESC' },
244
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationRevision)
244
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationRevision)
245
245
  });
246
246
  const revisionNumber = (previous?.revisionNumber ?? 0) + 1;
247
247
  let baseRevisionId = null;
@@ -383,7 +383,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
383
383
  text(decision.actorId, 'publisher');
384
384
  const previousDecision = await manager.findOne(test_spec_revision_1.TestSpecificationPlan, {
385
385
  where: { domain: { id: domainId }, publishedRevision: { id: revisionId } },
386
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
386
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
387
387
  });
388
388
  if (previousDecision)
389
389
  return previousDecision;
@@ -392,12 +392,12 @@ async function publishRevision(manager, domainId, revisionId, decision) {
392
392
  // Only replacement from effectiveFrom onward is supported in this slice, not arbitrary rescheduling.
393
393
  if (await manager.findOne(test_spec_revision_1.TestSpecificationBasis, {
394
394
  where: { domain: { id: domainId }, spec: { id: spec.id }, businessTime: (0, typeorm_1.MoreThanOrEqual)(draft.effectiveFrom) },
395
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationBasis)
395
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationBasis)
396
396
  }))
397
397
  refuse('RETROACTIVE_IMPACT');
398
398
  const oldPlan = await manager.findOne(test_spec_revision_1.TestSpecificationPlan, {
399
399
  where: { domain: { id: domainId }, spec: { id: spec.id }, generation: spec.planGeneration },
400
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
400
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
401
401
  });
402
402
  if (spec.planGeneration > 0 && !oldPlan)
403
403
  refuse('PLAN_CONFLICT');
@@ -405,7 +405,7 @@ async function publishRevision(manager, domainId, revisionId, decision) {
405
405
  ? await manager.find(test_spec_revision_1.TestSpecificationSegment, {
406
406
  where: { domain: { id: domainId }, spec: { id: spec.id }, plan: { id: oldPlan.id } },
407
407
  order: { validFrom: 'ASC' },
408
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationSegment)
408
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationSegment)
409
409
  })
410
410
  : [];
411
411
  // Do not silently erase an already approved future appointment.
@@ -454,7 +454,7 @@ async function resolveTestSpecification(manager, domainId, specId, businessTime,
454
454
  const plan = await manager.findOne(test_spec_revision_1.TestSpecificationPlan, {
455
455
  where: { domain: { id: domainId }, spec: { id: specId }, recordedAt: (0, typeorm_1.LessThanOrEqual)(known) },
456
456
  order: { generation: 'DESC' },
457
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
457
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationPlan)
458
458
  });
459
459
  if (!plan)
460
460
  refuse('NO_EFFECTIVE_REVISION');
@@ -465,7 +465,7 @@ async function resolveTestSpecification(manager, domainId, specId, businessTime,
465
465
  .where({ domain: { id: domainId }, spec: { id: specId }, plan: { id: plan.id } })
466
466
  .andWhere('segment.validFrom <= :at', { at })
467
467
  .andWhere('(segment.validTo IS NULL OR segment.validTo > :at)', { at });
468
- (0, row_lock_1.lockRowsOf)(manager, query);
468
+ (0, shell_2.lockRowsOf)(manager, query);
469
469
  const segments = await query.getMany();
470
470
  if (!segments.length)
471
471
  await refuseBeforeBaseline(manager, domainId, specId, at);
@@ -599,7 +599,7 @@ async function captureTestSpecificationBasis(manager, domainId, specId, recordKe
599
599
  await lockSubject(manager, domainId, specId);
600
600
  const existing = await manager.findOne(test_spec_revision_1.TestSpecificationBasis, {
601
601
  where: { domain: { id: domainId }, recordKey },
602
- ...(0, row_lock_1.writeLockOn)(manager, test_spec_revision_1.TestSpecificationBasis)
602
+ ...(0, shell_2.writeLockOn)(manager, test_spec_revision_1.TestSpecificationBasis)
603
603
  });
604
604
  if (existing) {
605
605
  if (existing.specId !== specId || existing.businessTime.getTime() !== at.getTime())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/ops-master",
3
- "version": "10.1.296",
3
+ "version": "10.1.298",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "author": "heartyoh <heartyoh@hatiolab.com>",
@@ -42,10 +42,10 @@
42
42
  "@operato/shell": "^10.29.69",
43
43
  "@operato/styles": "^10.0.0",
44
44
  "@operato/utils": "^10.29.39",
45
- "@things-factory/auth-base": "^10.1.296",
46
- "@things-factory/env": "^10.1.296",
47
- "@things-factory/shell": "^10.1.296",
48
- "@things-factory/worklist": "^10.1.296"
45
+ "@things-factory/auth-base": "^10.1.298",
46
+ "@things-factory/env": "^10.1.298",
47
+ "@things-factory/shell": "^10.1.298",
48
+ "@things-factory/worklist": "^10.1.298"
49
49
  },
50
50
  "browser": "dist-client/index.js",
51
51
  "files": [
@@ -64,8 +64,9 @@
64
64
  "!**/.DS_Store"
65
65
  ],
66
66
  "devDependencies": {
67
+ "@things-factory/notification": "^10.1.298",
67
68
  "copyfiles": "^2.4.1",
68
69
  "rimraf": "^6.1.3"
69
70
  },
70
- "gitHead": "0cd4b6207e4dfc557157f86630d82aed423b1dde"
71
+ "gitHead": "5b5dce33c891a02896ef3a9cb3974abefc3f53d6"
71
72
  }