@operato/twin-figure-capabilities 0.0.0-stage → 0.5.3
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/entity.d.ts +59 -0
- package/dist/entity.js +101 -0
- package/dist/generate.d.ts +56 -0
- package/dist/generate.js +104 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +13 -0
- package/dist/mobile.d.ts +1 -0
- package/dist/mobile.js +19 -0
- package/dist/module.d.ts +8 -0
- package/dist/module.js +16 -0
- package/dist/operable.d.ts +1 -0
- package/dist/operable.js +20 -0
- package/dist/storable.d.ts +30 -0
- package/dist/storable.js +49 -0
- package/dist/twin-capabilities.module.mjs +1472 -0
- package/dist/values.d.ts +16 -0
- package/dist/values.js +34 -0
- package/dist/words.d.ts +13 -0
- package/dist/words.js +42 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/entity.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FigureAsset, FigureCapabilityDescriptor } from '@hatiolab/figure-model';
|
|
2
|
+
import { type CapabilityKey } from '@operato/ops-contract';
|
|
3
|
+
import { type Words } from './words.ts';
|
|
4
|
+
/** The twin's scene actions (ADR-0209 decision 3): `<provider>.<action>`. The twin app registers what each does. */
|
|
5
|
+
export declare const TWIN_ACTIONS: {
|
|
6
|
+
readonly preview: "twin.preview-entity";
|
|
7
|
+
readonly info: "twin.entity-info";
|
|
8
|
+
readonly open: "twin.open-entity";
|
|
9
|
+
readonly command: "twin.command";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What every twin entity answers to, by meaning (ADR-0209 decision 2). Each has its words: the actions menu shows them
|
|
13
|
+
* (amendment 1 decision 8), and the handler editor shows them as the action a meaning gets (decision 7).
|
|
14
|
+
*/
|
|
15
|
+
export declare const TWIN_ENTITY_INTERACTIONS: readonly ({
|
|
16
|
+
meaning: "preview";
|
|
17
|
+
action: "twin.preview-entity";
|
|
18
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
19
|
+
} | {
|
|
20
|
+
meaning: "select";
|
|
21
|
+
action: "twin.entity-info";
|
|
22
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
23
|
+
} | {
|
|
24
|
+
meaning: "enter";
|
|
25
|
+
action: "twin.open-entity";
|
|
26
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
27
|
+
} | {
|
|
28
|
+
meaning: "actions";
|
|
29
|
+
action: "twin.entity-info";
|
|
30
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
31
|
+
} | {
|
|
32
|
+
meaning: "actions";
|
|
33
|
+
action: "twin.open-entity";
|
|
34
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
35
|
+
})[];
|
|
36
|
+
/** The settings key of the entity types */
|
|
37
|
+
export declare const ENTITY_TYPES_SETTING = "types";
|
|
38
|
+
/** The entity types a figure declares, as written. */
|
|
39
|
+
export declare function entityTypesOf(settings: Record<string, unknown> | undefined): string[];
|
|
40
|
+
/** Why the settings cannot be taken: no type declared, keys out of place. */
|
|
41
|
+
export declare function entitySettingsIssues(settings: Record<string, unknown> | undefined): Words[];
|
|
42
|
+
/** The capabilities the contract's standard catalog gives a type, across its systems; none for a type it does not know. */
|
|
43
|
+
export declare function standardCapabilitiesOfType(type: string): CapabilityKey[];
|
|
44
|
+
/**
|
|
45
|
+
* What the declared types and the capabilities worn say about each other (decision 14): a capability a type has that the
|
|
46
|
+
* figure does not take on, and one the figure wears that no declared type has. Advice for the author -- the figure stands
|
|
47
|
+
* either way, so it is not the check, which would take the capability off. `typeCapabilities` is the domain catalog's
|
|
48
|
+
* answer (the choice list's data); left out, the contract's standard catalog answers for the types it knows.
|
|
49
|
+
*/
|
|
50
|
+
export declare function entityCapabilityAdvice(settings: Record<string, unknown> | undefined, asset: Pick<FigureAsset, 'document'>, typeCapabilities?: (type: string) => readonly string[]): {
|
|
51
|
+
missing: {
|
|
52
|
+
type: string;
|
|
53
|
+
capability: string;
|
|
54
|
+
}[];
|
|
55
|
+
extra: string[];
|
|
56
|
+
};
|
|
57
|
+
/** The twin capabilities a figure can wear besides the base (kept in step with module.ts by a test). */
|
|
58
|
+
export declare const TWIN_FIGURE_CAPABILITY_NAMES: string[];
|
|
59
|
+
export declare const ENTITY: FigureCapabilityDescriptor;
|
package/dist/entity.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { DOMAIN_SYSTEMS, capabilitiesForType } from '@operato/ops-contract';
|
|
2
|
+
import { TWIN_COMMAND_ACTION, TWIN_ENTITY_NAME, twinCapabilityName } from "./generate.js";
|
|
3
|
+
import { NO_ENTITY_TYPE_WORDS, unusedSettingWords } from "./words.js";
|
|
4
|
+
/*
|
|
5
|
+
* `twin.Entity` (ADR-0208 amendment 1 decision 12): the base every twin capability stands on. It says which entity types
|
|
6
|
+
* the figure draws -- a location's `type`, equipment's `kind` -- and that saying is the mapping: the twin draws an entity
|
|
7
|
+
* of a declared type with this figure (decision 16). The list a modeller offers comes from the linked twin domain's
|
|
8
|
+
* catalog (ADR-0172 amendment 2), not from this module. The interactions every entity shares (preview, select, enter its
|
|
9
|
+
* 360) take their place here once ADR-0209 decision 4 lands.
|
|
10
|
+
*/
|
|
11
|
+
/** The twin's scene actions (ADR-0209 decision 3): `<provider>.<action>`. The twin app registers what each does. */
|
|
12
|
+
export const TWIN_ACTIONS = {
|
|
13
|
+
preview: 'twin.preview-entity',
|
|
14
|
+
info: 'twin.entity-info',
|
|
15
|
+
open: 'twin.open-entity',
|
|
16
|
+
command: TWIN_COMMAND_ACTION
|
|
17
|
+
};
|
|
18
|
+
/* The words of each action, the same on every meaning it is given on */
|
|
19
|
+
const PREVIEW_WORDS = { ko: '미리보기', en: 'Preview', ja: 'プレビュー', zh: '预览', es: 'Vista previa', ms: 'Pratonton' };
|
|
20
|
+
const INFO_WORDS = { ko: '정보', en: 'Info', ja: '情報', zh: '信息', es: 'Información', ms: 'Maklumat' };
|
|
21
|
+
const OPEN_WORDS = { ko: '360 열기', en: 'Open 360', ja: '360 を開く', zh: '打开 360', es: 'Abrir 360', ms: 'Buka 360' };
|
|
22
|
+
/**
|
|
23
|
+
* What every twin entity answers to, by meaning (ADR-0209 decision 2). Each has its words: the actions menu shows them
|
|
24
|
+
* (amendment 1 decision 8), and the handler editor shows them as the action a meaning gets (decision 7).
|
|
25
|
+
*/
|
|
26
|
+
export const TWIN_ENTITY_INTERACTIONS = Object.freeze([
|
|
27
|
+
{ meaning: 'preview', action: TWIN_ACTIONS.preview, label: PREVIEW_WORDS },
|
|
28
|
+
{ meaning: 'select', action: TWIN_ACTIONS.info, label: INFO_WORDS },
|
|
29
|
+
{ meaning: 'enter', action: TWIN_ACTIONS.open, label: OPEN_WORDS },
|
|
30
|
+
/* The actions menu (amendment 1 decision 8): these two, then each capability's commands (`commandInteractionsOf`) */
|
|
31
|
+
{ meaning: 'actions', action: TWIN_ACTIONS.info, label: INFO_WORDS },
|
|
32
|
+
{ meaning: 'actions', action: TWIN_ACTIONS.open, label: OPEN_WORDS }
|
|
33
|
+
]);
|
|
34
|
+
/** The settings key of the entity types */
|
|
35
|
+
export const ENTITY_TYPES_SETTING = 'types';
|
|
36
|
+
/** The entity types a figure declares, as written. */
|
|
37
|
+
export function entityTypesOf(settings) {
|
|
38
|
+
const types = (settings ?? {})[ENTITY_TYPES_SETTING];
|
|
39
|
+
return Array.isArray(types) ? types.filter((t) => typeof t === 'string' && t.trim() !== '') : [];
|
|
40
|
+
}
|
|
41
|
+
/** Why the settings cannot be taken: no type declared, keys out of place. */
|
|
42
|
+
export function entitySettingsIssues(settings) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const key of Object.keys(settings ?? {}))
|
|
45
|
+
if (key !== ENTITY_TYPES_SETTING)
|
|
46
|
+
out.push(unusedSettingWords(key));
|
|
47
|
+
if (!entityTypesOf(settings).length)
|
|
48
|
+
out.push(NO_ENTITY_TYPE_WORDS);
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** The capabilities the contract's standard catalog gives a type, across its systems; none for a type it does not know. */
|
|
52
|
+
export function standardCapabilitiesOfType(type) {
|
|
53
|
+
return [...new Set(DOMAIN_SYSTEMS.flatMap(system => capabilitiesForType(system, type)))];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* What the declared types and the capabilities worn say about each other (decision 14): a capability a type has that the
|
|
57
|
+
* figure does not take on, and one the figure wears that no declared type has. Advice for the author -- the figure stands
|
|
58
|
+
* either way, so it is not the check, which would take the capability off. `typeCapabilities` is the domain catalog's
|
|
59
|
+
* answer (the choice list's data); left out, the contract's standard catalog answers for the types it knows.
|
|
60
|
+
*/
|
|
61
|
+
export function entityCapabilityAdvice(settings, asset, typeCapabilities = standardCapabilitiesOfType) {
|
|
62
|
+
const worn = new Set(asset.document.capabilities.names ?? []);
|
|
63
|
+
const types = entityTypesOf(settings);
|
|
64
|
+
const missing = [];
|
|
65
|
+
const covered = new Set();
|
|
66
|
+
for (const type of types)
|
|
67
|
+
for (const key of typeCapabilities(type)) {
|
|
68
|
+
const name = twinCapabilityName(key);
|
|
69
|
+
covered.add(name);
|
|
70
|
+
if (TWIN_FIGURE_CAPABILITY_NAMES.includes(name) && !worn.has(name))
|
|
71
|
+
missing.push({ type, capability: name });
|
|
72
|
+
}
|
|
73
|
+
const extra = [...worn].filter(name => TWIN_FIGURE_CAPABILITY_NAMES.includes(name) && types.length > 0 && !covered.has(name));
|
|
74
|
+
return { missing, extra };
|
|
75
|
+
}
|
|
76
|
+
/** The twin capabilities a figure can wear besides the base (kept in step with module.ts by a test). */
|
|
77
|
+
export const TWIN_FIGURE_CAPABILITY_NAMES = ['twin.Operable', 'twin.Storable', 'twin.Mobile'];
|
|
78
|
+
export const ENTITY = {
|
|
79
|
+
name: TWIN_ENTITY_NAME,
|
|
80
|
+
label: { ko: '트윈 엔티티', en: 'Twin entity', ja: 'ツインエンティティ', zh: '孪生实体', es: 'Entidad del gemelo', ms: 'Entiti kembar' },
|
|
81
|
+
note: {
|
|
82
|
+
ko: '이 피규어가 나타내는 트윈 엔티티 종류를 정합니다. 트윈은 이 종류의 엔티티를 이 피규어로 그립니다. 운영 상태 · 보관 · 이동 능력은 이 능력 위에 켭니다.',
|
|
83
|
+
en: 'Sets the twin entity types this figure draws. The twin draws entities of these types with it. Operating status, storage and motion are turned on over this capability.',
|
|
84
|
+
ja: 'この図形が表すツインエンティティの種類を決めます。ツインはこの種類のエンティティをこの図形で描きます。運用状態・保管・移動の機能はこの機能の上でオンにします。',
|
|
85
|
+
zh: '设置此图形表示的孪生实体类型。孪生用此图形绘制这些类型的实体。运行状态、存放和移动能力在此能力之上开启。',
|
|
86
|
+
es: 'Define los tipos de entidad del gemelo que dibuja esta figura. El gemelo dibuja con ella las entidades de esos tipos. El estado operativo, el almacenamiento y el movimiento se activan sobre esta capacidad.',
|
|
87
|
+
ms: 'Menetapkan jenis entiti kembar yang dilukis oleh figura ini. Kembar melukis entiti jenis tersebut dengan figura ini. Status operasi, simpanan dan pergerakan dihidupkan di atas keupayaan ini.'
|
|
88
|
+
},
|
|
89
|
+
version: '2',
|
|
90
|
+
needs: [],
|
|
91
|
+
/* The marker the twin sends with every entity's data (headless-twin entity-delta `entity`) */
|
|
92
|
+
data: [{ name: 'entity' }],
|
|
93
|
+
settings: [{ key: ENTITY_TYPES_SETTING, kind: 'choice', label: { ko: '엔티티 종류', en: 'Entity types', ja: 'エンティティの種類', zh: '实体类型', es: 'Tipos de entidad', ms: 'Jenis entiti' }, multiple: true, required: true }],
|
|
94
|
+
check: settings => entitySettingsIssues(settings),
|
|
95
|
+
takes: () => ({}),
|
|
96
|
+
/*
|
|
97
|
+
* 엔티티 공통의 상호작용(ADR-0209 결정 4, ADR-0208 개정 1 결정 12): 미리보기는 이름과 핵심 상태, 선택은 정보 창, 들어가기는 엔티티 360, 동작
|
|
98
|
+
* 메뉴는 그 엔티티에 할 수 있는 일. 무엇을 할지는 트윈 보드에 등록된 동작이 정한다 — 다른 보드에서는 정의만 남고 아무 일도 하지 않는다.
|
|
99
|
+
*/
|
|
100
|
+
interactions: () => TWIN_ENTITY_INTERACTIONS
|
|
101
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { FigureAsset, FigureCapabilityCard, FigureCapabilityDescriptor, FigureDataBinding } from '@hatiolab/figure-model';
|
|
2
|
+
import { type CapabilityKey } from '@operato/ops-contract';
|
|
3
|
+
import { type Words } from './words.ts';
|
|
4
|
+
/** The base capability every twin capability stands on. */
|
|
5
|
+
export declare const TWIN_ENTITY_NAME = "twin.Entity";
|
|
6
|
+
/** The scene action that sends one contract command to the entity (ADR-0209 decision 3); the twin app registers it. */
|
|
7
|
+
export declare const TWIN_COMMAND_ACTION = "twin.command";
|
|
8
|
+
/**
|
|
9
|
+
* The words of the contract's commands, wherever a command is offered: the actions menu (ADR-0209 amendment 1
|
|
10
|
+
* decision 8), the popup boards' buttons and the 2D cards' buttons. The module carries its own words (ADR-0172
|
|
11
|
+
* decision 7); screens read them with `capabilityText`. A capability's command with no words here is a test failure,
|
|
12
|
+
* not a menu item named by its code.
|
|
13
|
+
*/
|
|
14
|
+
export declare const COMMAND_WORDS: Readonly<Record<string, Words>>;
|
|
15
|
+
/** A capability's commands as `actions` menu items: each sends its command, with the twin's confirmation. */
|
|
16
|
+
export declare const commandInteractionsOf: (key: CapabilityKey) => {
|
|
17
|
+
meaning: "actions";
|
|
18
|
+
action: string;
|
|
19
|
+
value: string;
|
|
20
|
+
label: Readonly<Record<"ko" | "en" | "ja" | "zh" | "es" | "ms", string>>;
|
|
21
|
+
}[];
|
|
22
|
+
/** `twin.<Capability>`, as the contract names the capability. */
|
|
23
|
+
export declare const twinCapabilityName: (key: CapabilityKey) => string;
|
|
24
|
+
/** The legend role of a listed field: `twin-<field>` (the operating status: `twin-status`). */
|
|
25
|
+
export declare const legendRoleOf: (field: string) => string;
|
|
26
|
+
/** The settings key of a listed field's parts: `<field>Parts` (the operating status: `statusParts`). */
|
|
27
|
+
export declare const partsSettingOf: (field: string) => string;
|
|
28
|
+
export interface TwinCapabilitySpec {
|
|
29
|
+
key: CapabilityKey;
|
|
30
|
+
label: Words;
|
|
31
|
+
note: Words;
|
|
32
|
+
version: string;
|
|
33
|
+
/** What it needs besides `twin.Entity` */
|
|
34
|
+
needs?: ReadonlyArray<string | readonly string[]>;
|
|
35
|
+
/** Data it reads besides the contract's state fields (Storable: its location's items) */
|
|
36
|
+
moreData?: readonly string[];
|
|
37
|
+
/** What its own mixin takes over besides the listed fields' parts (Storable: the item list) */
|
|
38
|
+
takesItems?: boolean;
|
|
39
|
+
/** The 2D card places it offers (ADR-0209 decision 5): the twin board puts its card there. */
|
|
40
|
+
cards?: readonly FigureCapabilityCard[];
|
|
41
|
+
}
|
|
42
|
+
/** The listed fields of a capability: its state fields the contract gives a closed list for. */
|
|
43
|
+
export declare const listedFieldsOf: (key: CapabilityKey) => string[];
|
|
44
|
+
/** Why the settings cannot be taken: a listed field with no part, parts the figure lacks, keys out of place. */
|
|
45
|
+
export declare function listedSettingsIssues(key: CapabilityKey, settings: Record<string, unknown> | undefined, asset: FigureAsset): Words[];
|
|
46
|
+
/** The tables the capability hands the figure engine (ADR-0166): each listed field's rows on its parts, by its legend role. */
|
|
47
|
+
export declare function listedDataInterface(key: CapabilityKey, settings: Record<string, unknown> | undefined): {
|
|
48
|
+
schema: {
|
|
49
|
+
name: string;
|
|
50
|
+
label: string;
|
|
51
|
+
kind: 'text';
|
|
52
|
+
}[];
|
|
53
|
+
bindings: FigureDataBinding[];
|
|
54
|
+
} | undefined;
|
|
55
|
+
/** A twin capability's descriptor, made from the contract and the spec. */
|
|
56
|
+
export declare function twinCapability(spec: TwinCapabilitySpec): FigureCapabilityDescriptor;
|
package/dist/generate.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { CAPABILITIES } from '@operato/ops-contract';
|
|
2
|
+
import { STATE_FIELD_WORDS, STATE_VALUE_LISTS, legendRowsOf } from "./values.js";
|
|
3
|
+
import { missingPartWords, noPartWords, unusedSettingWords } from "./words.js";
|
|
4
|
+
/*
|
|
5
|
+
* A twin capability's definition made from the contract (ADR-0208 amendment 1 decision 15): the data it reads is the
|
|
6
|
+
* capability's state fields, and each field with a closed value list gets its legend rows and a parts setting -- the one
|
|
7
|
+
* thing left to the author is which parts show it. What a capability does beyond that (putting items in places, moving)
|
|
8
|
+
* is a mixin written by hand in the twin app. Every twin capability needs `twin.Entity` (decision 13).
|
|
9
|
+
*/
|
|
10
|
+
/** The base capability every twin capability stands on. */
|
|
11
|
+
export const TWIN_ENTITY_NAME = 'twin.Entity';
|
|
12
|
+
/** The scene action that sends one contract command to the entity (ADR-0209 decision 3); the twin app registers it. */
|
|
13
|
+
export const TWIN_COMMAND_ACTION = 'twin.command';
|
|
14
|
+
/**
|
|
15
|
+
* The words of the contract's commands, wherever a command is offered: the actions menu (ADR-0209 amendment 1
|
|
16
|
+
* decision 8), the popup boards' buttons and the 2D cards' buttons. The module carries its own words (ADR-0172
|
|
17
|
+
* decision 7); screens read them with `capabilityText`. A capability's command with no words here is a test failure,
|
|
18
|
+
* not a menu item named by its code.
|
|
19
|
+
*/
|
|
20
|
+
export const COMMAND_WORDS = Object.freeze({
|
|
21
|
+
'resource.hold': { ko: '계획 정지', en: 'Plan stop', ja: '計画停止', zh: '计划停机', es: 'Parada planificada', ms: 'Henti terancang' },
|
|
22
|
+
'resource.resume': { ko: '재개', en: 'Resume', ja: '再開', zh: '恢复', es: 'Reanudar', ms: 'Sambung semula' },
|
|
23
|
+
'resource.down': { ko: '고장 주입', en: 'Inject fault', ja: '故障注入', zh: '注入故障', es: 'Inyectar fallo', ms: 'Suntik kerosakan' },
|
|
24
|
+
'resource.repair': { ko: '수리', en: 'Repair', ja: '修理', zh: '维修', es: 'Reparar', ms: 'Baiki' },
|
|
25
|
+
'resource.reset-metrics': { ko: '지표 리셋', en: 'Reset metrics', ja: '指標リセット', zh: '重置指标', es: 'Reiniciar métricas', ms: 'Set semula metrik' }
|
|
26
|
+
});
|
|
27
|
+
/** A capability's commands as `actions` menu items: each sends its command, with the twin's confirmation. */
|
|
28
|
+
export const commandInteractionsOf = (key) => CAPABILITIES[key].commands.map(command => ({ meaning: 'actions', action: TWIN_COMMAND_ACTION, value: command, label: COMMAND_WORDS[command] }));
|
|
29
|
+
/** `twin.<Capability>`, as the contract names the capability. */
|
|
30
|
+
export const twinCapabilityName = (key) => `twin.${key[0].toUpperCase()}${key.slice(1)}`;
|
|
31
|
+
/** The legend role of a listed field: `twin-<field>` (the operating status: `twin-status`). */
|
|
32
|
+
export const legendRoleOf = (field) => `twin-${field}`;
|
|
33
|
+
/** The settings key of a listed field's parts: `<field>Parts` (the operating status: `statusParts`). */
|
|
34
|
+
export const partsSettingOf = (field) => `${field}Parts`;
|
|
35
|
+
/** The listed fields of a capability: its state fields the contract gives a closed list for. */
|
|
36
|
+
export const listedFieldsOf = (key) => CAPABILITIES[key].stateFields.filter(field => STATE_VALUE_LISTS[field]);
|
|
37
|
+
const partsOf = (settings, field) => {
|
|
38
|
+
const parts = (settings ?? {})[partsSettingOf(field)];
|
|
39
|
+
return Array.isArray(parts) ? parts.filter((p) => typeof p === 'string') : [];
|
|
40
|
+
};
|
|
41
|
+
/** Why the settings cannot be taken: a listed field with no part, parts the figure lacks, keys out of place. */
|
|
42
|
+
export function listedSettingsIssues(key, settings, asset) {
|
|
43
|
+
const fields = listedFieldsOf(key);
|
|
44
|
+
const keys = fields.map(partsSettingOf);
|
|
45
|
+
const parts = new Set(asset.appearance.map(a => a.target));
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const k of Object.keys(settings ?? {}))
|
|
48
|
+
if (!keys.includes(k))
|
|
49
|
+
out.push(unusedSettingWords(k));
|
|
50
|
+
for (const field of fields) {
|
|
51
|
+
const chosen = partsOf(settings, field);
|
|
52
|
+
if (!chosen.length)
|
|
53
|
+
out.push(noPartWords(STATE_FIELD_WORDS[field]));
|
|
54
|
+
for (const part of chosen)
|
|
55
|
+
if (!parts.has(part))
|
|
56
|
+
out.push(missingPartWords(part));
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** The tables the capability hands the figure engine (ADR-0166): each listed field's rows on its parts, by its legend role. */
|
|
61
|
+
export function listedDataInterface(key, settings) {
|
|
62
|
+
const fields = listedFieldsOf(key).filter(field => partsOf(settings, field).length);
|
|
63
|
+
if (!fields.length)
|
|
64
|
+
return undefined;
|
|
65
|
+
return {
|
|
66
|
+
schema: fields.map(field => ({ name: field, label: STATE_FIELD_WORDS[field].ko, kind: 'text' })),
|
|
67
|
+
bindings: fields.map(field => ({
|
|
68
|
+
id: legendRoleOf(field),
|
|
69
|
+
label: STATE_FIELD_WORDS[field].ko,
|
|
70
|
+
accessor: field,
|
|
71
|
+
rule: 'table',
|
|
72
|
+
lookup: 'code',
|
|
73
|
+
targets: { parts: partsOf(settings, field) },
|
|
74
|
+
table: legendRowsOf(field),
|
|
75
|
+
legend: { role: legendRoleOf(field) }
|
|
76
|
+
}))
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** A twin capability's descriptor, made from the contract and the spec. */
|
|
80
|
+
export function twinCapability(spec) {
|
|
81
|
+
const { key } = spec;
|
|
82
|
+
const fields = listedFieldsOf(key);
|
|
83
|
+
return {
|
|
84
|
+
name: twinCapabilityName(key),
|
|
85
|
+
label: spec.label,
|
|
86
|
+
note: spec.note,
|
|
87
|
+
version: spec.version,
|
|
88
|
+
needs: [TWIN_ENTITY_NAME, ...(spec.needs ?? [])],
|
|
89
|
+
data: [...CAPABILITIES[key].stateFields, ...(spec.moreData ?? [])].map(name => ({ name })),
|
|
90
|
+
...(fields.length
|
|
91
|
+
? {
|
|
92
|
+
settings: fields.map(field => ({ key: partsSettingOf(field), kind: 'parts', label: STATE_FIELD_WORDS[field], required: true })),
|
|
93
|
+
check: (settings, asset) => listedSettingsIssues(key, settings, asset),
|
|
94
|
+
dataInterface: (settings) => listedDataInterface(key, settings)
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
...(spec.cards?.length ? { cards: () => spec.cards } : {}),
|
|
98
|
+
...(CAPABILITIES[key].commands.length ? { interactions: () => commandInteractionsOf(key) } : {}),
|
|
99
|
+
takes: (settings) => ({
|
|
100
|
+
...(spec.takesItems ? { items: true } : {}),
|
|
101
|
+
...(fields.length ? { parts: fields.flatMap(field => partsOf(settings, field)) } : {})
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ENTITY, ENTITY_TYPES_SETTING, TWIN_ACTIONS, TWIN_ENTITY_INTERACTIONS, TWIN_FIGURE_CAPABILITY_NAMES, entityCapabilityAdvice, entitySettingsIssues, entityTypesOf, standardCapabilitiesOfType } from './entity.ts';
|
|
2
|
+
export { COMMAND_WORDS, TWIN_COMMAND_ACTION, TWIN_ENTITY_NAME, commandInteractionsOf, legendRoleOf, listedDataInterface, listedFieldsOf, listedSettingsIssues, partsSettingOf, twinCapability, twinCapabilityName, type TwinCapabilitySpec } from './generate.ts';
|
|
3
|
+
export { DEFAULT_VALUE_COLOUR, STATE_FIELD_WORDS, STATE_VALUE_LISTS, VALUE_COLOURS, legendRowsOf } from './values.ts';
|
|
4
|
+
export { OPERABLE } from './operable.ts';
|
|
5
|
+
export { STORABLE, twinItemId, twinItemRecords, type TwinItemRecord, type TwinLocationItem } from './storable.ts';
|
|
6
|
+
export { MOBILE } from './mobile.ts';
|
|
7
|
+
export { capabilities as TWIN_FIGURE_CAPABILITIES, label as TWIN_CAPABILITY_PROVIDER_LABEL, provider as TWIN_CAPABILITY_PROVIDER, version as TWIN_CAPABILITY_MODULE_VERSION } from './module.ts';
|
|
8
|
+
export { TWIN_LANGUAGES, type TwinLanguage, type Words } from './words.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What the twin puts on a figure (ADR-0208, amendment 1): the base capability twin.Entity, the capabilities made from the
|
|
3
|
+
* ops-contract (twin.Operable, twin.Storable, twin.Mobile) and their pure functions -- no scene, DOM or API. The twin
|
|
4
|
+
* app registers them with its mixins; a figure server loads the module.
|
|
5
|
+
*/
|
|
6
|
+
export { ENTITY, ENTITY_TYPES_SETTING, TWIN_ACTIONS, TWIN_ENTITY_INTERACTIONS, TWIN_FIGURE_CAPABILITY_NAMES, entityCapabilityAdvice, entitySettingsIssues, entityTypesOf, standardCapabilitiesOfType } from "./entity.js";
|
|
7
|
+
export { COMMAND_WORDS, TWIN_COMMAND_ACTION, TWIN_ENTITY_NAME, commandInteractionsOf, legendRoleOf, listedDataInterface, listedFieldsOf, listedSettingsIssues, partsSettingOf, twinCapability, twinCapabilityName } from "./generate.js";
|
|
8
|
+
export { DEFAULT_VALUE_COLOUR, STATE_FIELD_WORDS, STATE_VALUE_LISTS, VALUE_COLOURS, legendRowsOf } from "./values.js";
|
|
9
|
+
export { OPERABLE } from "./operable.js";
|
|
10
|
+
export { STORABLE, twinItemId, twinItemRecords } from "./storable.js";
|
|
11
|
+
export { MOBILE } from "./mobile.js";
|
|
12
|
+
export { capabilities as TWIN_FIGURE_CAPABILITIES, label as TWIN_CAPABILITY_PROVIDER_LABEL, provider as TWIN_CAPABILITY_PROVIDER, version as TWIN_CAPABILITY_MODULE_VERSION } from "./module.js";
|
|
13
|
+
export { TWIN_LANGUAGES } from "./words.js";
|
package/dist/mobile.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MOBILE: import("@hatiolab/figure-model").FigureCapabilityDescriptor;
|
package/dist/mobile.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { twinCapability } from "./generate.js";
|
|
2
|
+
/*
|
|
3
|
+
* `twin.Mobile`: the figure stands where the twin observes the resource -- at its location, or on the way between two
|
|
4
|
+
* locations by its motion's progress -- with its front face (+Z) ahead. The kernel has no coordinates, so the scene finds
|
|
5
|
+
* the locations by their placed components (ADR-0208 미결 1: a straight line first). The moving is the scene's mixin.
|
|
6
|
+
*/
|
|
7
|
+
export const MOBILE = twinCapability({
|
|
8
|
+
key: 'mobile',
|
|
9
|
+
label: { ko: '이동', en: 'Mobile', ja: '移動', zh: '移动', es: 'Movimiento', ms: 'Pergerakan' },
|
|
10
|
+
note: {
|
|
11
|
+
ko: '트윈이 관측한 위치와 이동으로 피규어를 자리 사이에서 움직입니다. 피규어의 앞면이 진행 방향을 향합니다.',
|
|
12
|
+
en: 'Moves the figure between locations as the twin observes it moving, its front face ahead.',
|
|
13
|
+
ja: 'ツインが観測した位置と移動で、図形を場所の間で動かします。図形の前面が進行方向を向きます。',
|
|
14
|
+
zh: '按孪生观测到的位置和移动,在位置之间移动图形。图形的正面朝向前进方向。',
|
|
15
|
+
es: 'Mueve la figura entre ubicaciones según el gemelo la observa moverse, con su cara frontal por delante.',
|
|
16
|
+
ms: 'Menggerakkan figura antara lokasi seperti yang diperhatikan oleh kembar, dengan muka hadapannya menghala ke arah pergerakan.'
|
|
17
|
+
},
|
|
18
|
+
version: '2'
|
|
19
|
+
});
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Words } from './words.ts';
|
|
2
|
+
export declare const provider = "twin";
|
|
3
|
+
/** The provider's name on the modeller's screen. */
|
|
4
|
+
export declare const label: Words;
|
|
5
|
+
/** The module's version: the package's (a test keeps them the same). */
|
|
6
|
+
export declare const version = "0.5.3";
|
|
7
|
+
/** The base first, then the capabilities that stand on it. */
|
|
8
|
+
export declare const capabilities: import("@hatiolab/figure-model").FigureCapabilityDescriptor[];
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The twin's capability module (ADR-0172 decision 3): one provider, its version and its descriptors, in one file the
|
|
3
|
+
* build bundles (`dist/twin-capabilities.module.mjs`) for a figure server to load. Nothing outside the file is imported
|
|
4
|
+
* at run time.
|
|
5
|
+
*/
|
|
6
|
+
import { ENTITY } from "./entity.js";
|
|
7
|
+
import { MOBILE } from "./mobile.js";
|
|
8
|
+
import { OPERABLE } from "./operable.js";
|
|
9
|
+
import { STORABLE } from "./storable.js";
|
|
10
|
+
export const provider = 'twin';
|
|
11
|
+
/** The provider's name on the modeller's screen. */
|
|
12
|
+
export const label = { ko: '트윈', en: 'Twin', ja: 'ツイン', zh: '孪生', es: 'Gemelo', ms: 'Kembar' };
|
|
13
|
+
/** The module's version: the package's (a test keeps them the same). */
|
|
14
|
+
export const version = '0.5.3';
|
|
15
|
+
/** The base first, then the capabilities that stand on it. */
|
|
16
|
+
export const capabilities = [ENTITY, OPERABLE, STORABLE, MOBILE];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const OPERABLE: import("@hatiolab/figure-model").FigureCapabilityDescriptor;
|
package/dist/operable.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { twinCapability } from "./generate.js";
|
|
2
|
+
/*
|
|
3
|
+
* `twin.Operable`: the operating status the twin observes -- the five equipment statuses -- on the parts the author
|
|
4
|
+
* picks, by the legend role `twin-status`. All of it is made from the contract; the scene adds no behaviour.
|
|
5
|
+
*/
|
|
6
|
+
export const OPERABLE = twinCapability({
|
|
7
|
+
key: 'operable',
|
|
8
|
+
label: { ko: '운영 상태', en: 'Operable', ja: '運用状態', zh: '运行状态', es: 'Estado operativo', ms: 'Status operasi' },
|
|
9
|
+
note: {
|
|
10
|
+
ko: '트윈이 관측한 설비 상태(가동 · 준비 · 고장 · 대기 · 계획정지)를 선택한 부품의 색으로 표시합니다. 색은 설비 상태 범례를 따릅니다.',
|
|
11
|
+
en: 'Shows the equipment status the twin observes (busy, setup, down, idle, planned stop) as the colour of the parts you pick, by the equipment status legend.',
|
|
12
|
+
ja: 'ツインが観測した設備状態(稼働・段取り・故障・待機・計画停止)を、選んだ部品の色で表示します。色は設備状態の凡例に従います。',
|
|
13
|
+
zh: '用所选部件的颜色显示孪生观测到的设备状态(运行、准备、故障、空闲、计划停机)。颜色遵循设备状态图例。',
|
|
14
|
+
es: 'Muestra el estado del equipo que observa el gemelo (en marcha, preparación, averiado, inactivo, parada planificada) con el color de las piezas que elija, según la leyenda de estado del equipo.',
|
|
15
|
+
ms: 'Menunjukkan status peralatan yang diperhatikan oleh kembar (sibuk, persediaan, rosak, melahu, henti terancang) dengan warna bahagian yang anda pilih, mengikut petunjuk status peralatan.'
|
|
16
|
+
},
|
|
17
|
+
version: '3',
|
|
18
|
+
/* 설비 상태 배지 — 피규어 위 */
|
|
19
|
+
cards: [{ id: 'status', anchor: 'top', label: { ko: '설비 상태', en: 'Equipment status', ja: '設備状態', zh: '设备状态', es: 'Estado del equipo', ms: 'Status peralatan' } }]
|
|
20
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One item as the location's payload carries it (headless-twin `entity-delta`). */
|
|
2
|
+
export interface TwinLocationItem {
|
|
3
|
+
epc: string;
|
|
4
|
+
/** The part of a lot, when one lot lies in more than one part (ops-contract `ItemState.subLotId`). */
|
|
5
|
+
subLotId?: string;
|
|
6
|
+
itemType?: string;
|
|
7
|
+
status?: string;
|
|
8
|
+
}
|
|
9
|
+
/** The id an item is held by: the part of a lot when it has one, else its epc (ops-contract `ItemState.subLotId`). */
|
|
10
|
+
export declare const twinItemId: (item: TwinLocationItem) => string;
|
|
11
|
+
/** One record a holder reconciles its items by (things-scene `SlotRecord`): where it is, its id, type and state. */
|
|
12
|
+
export interface TwinItemRecord {
|
|
13
|
+
slotId: string;
|
|
14
|
+
itemId: string;
|
|
15
|
+
itemType?: string;
|
|
16
|
+
itemState: {
|
|
17
|
+
id: string;
|
|
18
|
+
status?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The location's items as the records a figure holds them by: in the payload's order, into the figure's places one after
|
|
23
|
+
* another, each up to its capacity (a place with no capacity takes the rest). What no place has room for is held with no
|
|
24
|
+
* place -- kept, not dropped, so the figure says what it holds.
|
|
25
|
+
*/
|
|
26
|
+
export declare function twinItemRecords(items: readonly TwinLocationItem[], places: ReadonlyArray<{
|
|
27
|
+
id: string;
|
|
28
|
+
maxCount?: number;
|
|
29
|
+
}>): TwinItemRecord[];
|
|
30
|
+
export declare const STORABLE: import("@hatiolab/figure-model").FigureCapabilityDescriptor;
|
package/dist/storable.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { twinCapability } from "./generate.js";
|
|
2
|
+
/** The id an item is held by: the part of a lot when it has one, else its epc (ops-contract `ItemState.subLotId`). */
|
|
3
|
+
export const twinItemId = (item) => item.subLotId ?? item.epc;
|
|
4
|
+
/**
|
|
5
|
+
* The location's items as the records a figure holds them by: in the payload's order, into the figure's places one after
|
|
6
|
+
* another, each up to its capacity (a place with no capacity takes the rest). What no place has room for is held with no
|
|
7
|
+
* place -- kept, not dropped, so the figure says what it holds.
|
|
8
|
+
*/
|
|
9
|
+
export function twinItemRecords(items, places) {
|
|
10
|
+
let at = 0;
|
|
11
|
+
let used = 0;
|
|
12
|
+
return items
|
|
13
|
+
.filter(item => item?.epc)
|
|
14
|
+
.map(item => {
|
|
15
|
+
while (at < places.length && typeof places[at].maxCount === 'number' && used >= places[at].maxCount) {
|
|
16
|
+
at++;
|
|
17
|
+
used = 0;
|
|
18
|
+
}
|
|
19
|
+
used++;
|
|
20
|
+
const id = twinItemId(item);
|
|
21
|
+
return {
|
|
22
|
+
slotId: places[at]?.id ?? '',
|
|
23
|
+
itemId: id,
|
|
24
|
+
...(item.itemType ? { itemType: item.itemType } : {}),
|
|
25
|
+
itemState: { id, ...(item.status !== undefined ? { status: item.status } : {}) }
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export const STORABLE = twinCapability({
|
|
30
|
+
key: 'storable',
|
|
31
|
+
label: { ko: '보관', en: 'Storable', ja: '保管', zh: '存放', es: 'Almacenamiento', ms: 'Simpanan' },
|
|
32
|
+
note: {
|
|
33
|
+
ko: '트윈이 관측한 이 자리의 물품을 피규어의 적재 위치에 놓습니다. 물품의 모양은 사업장의 아이템 타입 표가 정합니다.',
|
|
34
|
+
en: 'Puts the items the twin observes at this location in the figure\'s places. How an item looks is set by the workspace\'s item type table.',
|
|
35
|
+
ja: 'ツインが観測したこの場所の物品を、図形の積載位置に置きます。物品の形は事業所のアイテムタイプ表が決めます。',
|
|
36
|
+
zh: '把孪生观测到的此位置的物品放到图形的装载位置。物品的外观由工作区的物品类型表决定。',
|
|
37
|
+
es: 'Coloca en los puestos de la figura los artículos que el gemelo observa en esta ubicación. El aspecto de cada artículo lo define la tabla de tipos de artículo del espacio de trabajo.',
|
|
38
|
+
ms: 'Meletakkan item yang diperhatikan oleh kembar di lokasi ini pada tempat muatan figura. Rupa item ditetapkan oleh jadual jenis item ruang kerja.'
|
|
39
|
+
},
|
|
40
|
+
version: '2',
|
|
41
|
+
needs: [
|
|
42
|
+
['Holdable', 'FlowNode'],
|
|
43
|
+
['Capacity', 'FlowNode']
|
|
44
|
+
],
|
|
45
|
+
moreData: ['items'],
|
|
46
|
+
takesItems: true,
|
|
47
|
+
/* 점유 게이지 — 피규어 아래(상태 배지와 겹치지 않게) */
|
|
48
|
+
cards: [{ id: 'occupancy', anchor: 'bottom', label: { ko: '점유', en: 'Occupancy', ja: '占有', zh: '占用', es: 'Ocupación', ms: 'Penghunian' } }]
|
|
49
|
+
});
|