@kmlckj/licos-platform-sdk 0.8.5 → 0.8.6
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/README.md +31 -22
- package/dist/uns.d.ts +36 -31
- package/dist/uns.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,36 +136,45 @@ const schema = await uns.schemaCurrent();
|
|
|
136
136
|
const checked = await uns.validate(document);
|
|
137
137
|
const reviewedPlan = await uns.plan(document);
|
|
138
138
|
|
|
139
|
-
await uns.apply(document, {
|
|
139
|
+
await uns.apply(document, {
|
|
140
140
|
expectedDocumentHash: reviewedPlan.documentHash,
|
|
141
141
|
expectedPlanHash: reviewedPlan.planHash,
|
|
142
142
|
confirmed: true,
|
|
143
|
-
});
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Use a `UNSChangeSet` for an isolated structural change. Review the dedicated
|
|
147
|
-
plan and pass both hashes back unchanged. Destructive or replacement actions
|
|
148
|
-
also require `impactConfirmed: true`.
|
|
149
|
-
|
|
150
|
-
```js
|
|
151
|
-
const changes = await uns.planChanges(changeSet);
|
|
152
|
-
await uns.applyChanges(changeSet, {
|
|
153
|
-
expectedDocumentHash: changes.documentHash,
|
|
154
|
-
expectedPlanHash: changes.planHash,
|
|
155
|
-
confirmed: true,
|
|
156
|
-
impactConfirmed: true,
|
|
157
|
-
});
|
|
158
|
-
```
|
|
143
|
+
});
|
|
144
|
+
```
|
|
159
145
|
|
|
160
|
-
Use `
|
|
161
|
-
|
|
146
|
+
Use a `UNSChangeSet` for an isolated structural change. Review the dedicated
|
|
147
|
+
plan and pass both hashes back unchanged. Destructive or replacement actions
|
|
148
|
+
also require `impactConfirmed: true`.
|
|
162
149
|
|
|
163
150
|
```js
|
|
164
|
-
const
|
|
165
|
-
|
|
151
|
+
const changes = await uns.planChanges(changeSet);
|
|
152
|
+
await uns.applyChanges(changeSet, {
|
|
153
|
+
expectedDocumentHash: changes.documentHash,
|
|
154
|
+
expectedPlanHash: changes.planHash,
|
|
155
|
+
confirmed: true,
|
|
156
|
+
impactConfirmed: true,
|
|
157
|
+
});
|
|
166
158
|
```
|
|
167
159
|
|
|
168
|
-
|
|
160
|
+
Use `uns.openPath(path)` when business code targets an existing enterprise UNS
|
|
161
|
+
path without creating or changing `UNS.json`:
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
const temperature = uns.openPath('project:/production-line/temperature');
|
|
165
|
+
const current = await temperature.pointCurrent();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Realtime point consumers obtain the server-side WebSocket endpoint through the
|
|
169
|
+
authorized project runtime API. Create one upstream connection per returned
|
|
170
|
+
`nodeCode`; do not derive or hardcode a DataFactory address:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
const realtime = await uns.pointRealtimeConfig('TEMP_01');
|
|
174
|
+
// Connect to realtime.websocketUrl and register with realtime.nodeCode.
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Resource apply, data writes, point writes, and video controls require explicit
|
|
169
178
|
confirmation. Data deletion accepts the exact rows returned by a prior query
|
|
170
179
|
and also requires explicit confirmation. Point writes require a reason and ticket. The browser entry
|
|
171
180
|
does not export UNS helpers.
|
package/dist/uns.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export function listUnsBindings(): Promise<UnsObject[]>;
|
|
|
50
50
|
export function resolveUnsPath(path: string): Promise<UnsObject>;
|
|
51
51
|
export function validateUnsDocument(document: UnsObject): Promise<UnsObject>;
|
|
52
52
|
export function planUnsDocument(document: UnsObject): Promise<UnsObject>;
|
|
53
|
-
export function applyUnsDocument(
|
|
53
|
+
export function applyUnsDocument(
|
|
54
54
|
document: UnsObject,
|
|
55
55
|
options: {
|
|
56
56
|
expectedDocumentHash?: string;
|
|
@@ -59,21 +59,21 @@ export function applyUnsDocument(
|
|
|
59
59
|
expected_plan_hash?: string;
|
|
60
60
|
confirmed: boolean;
|
|
61
61
|
},
|
|
62
|
-
): Promise<UnsObject>;
|
|
63
|
-
export function validateUnsChanges(document: UnsObject): Promise<UnsObject>;
|
|
64
|
-
export function planUnsChanges(document: UnsObject): Promise<UnsObject>;
|
|
65
|
-
export function applyUnsChanges(
|
|
66
|
-
document: UnsObject,
|
|
67
|
-
options: {
|
|
68
|
-
expectedDocumentHash?: string;
|
|
69
|
-
expected_document_hash?: string;
|
|
70
|
-
expectedPlanHash?: string;
|
|
71
|
-
expected_plan_hash?: string;
|
|
72
|
-
confirmed: boolean;
|
|
73
|
-
impactConfirmed?: boolean;
|
|
74
|
-
impact_confirmed?: boolean;
|
|
75
|
-
},
|
|
76
|
-
): Promise<UnsObject>;
|
|
62
|
+
): Promise<UnsObject>;
|
|
63
|
+
export function validateUnsChanges(document: UnsObject): Promise<UnsObject>;
|
|
64
|
+
export function planUnsChanges(document: UnsObject): Promise<UnsObject>;
|
|
65
|
+
export function applyUnsChanges(
|
|
66
|
+
document: UnsObject,
|
|
67
|
+
options: {
|
|
68
|
+
expectedDocumentHash?: string;
|
|
69
|
+
expected_document_hash?: string;
|
|
70
|
+
expectedPlanHash?: string;
|
|
71
|
+
expected_plan_hash?: string;
|
|
72
|
+
confirmed: boolean;
|
|
73
|
+
impactConfirmed?: boolean;
|
|
74
|
+
impact_confirmed?: boolean;
|
|
75
|
+
},
|
|
76
|
+
): Promise<UnsObject>;
|
|
77
77
|
export function queryUnsNodeData(nodeCode: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
|
|
78
78
|
export function writeUnsNodeData(
|
|
79
79
|
nodeCode: string,
|
|
@@ -84,9 +84,11 @@ export function deleteUnsNodeData(nodeCode: string, rows: UnsObject[], options:
|
|
|
84
84
|
export function queryUnsPathData(path: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
|
|
85
85
|
export function writeUnsPathData(path: string, fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
|
|
86
86
|
export function deleteUnsPathData(path: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
|
|
87
|
-
export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
|
|
88
|
-
export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
|
|
89
|
-
export function
|
|
87
|
+
export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
|
|
88
|
+
export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
|
|
89
|
+
export function getUnsPointRealtimeConfig(nodeCode: string): Promise<UnsObject>;
|
|
90
|
+
export function getUnsPathPointRealtimeConfig(path: string): Promise<UnsObject>;
|
|
91
|
+
export function getUnsPointHistory(nodeCode: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
|
|
90
92
|
export function getUnsPathPointHistory(path: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
|
|
91
93
|
export function writeUnsPoint(nodeCode: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
|
|
92
94
|
export function writeUnsPathPoint(path: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
|
|
@@ -103,9 +105,10 @@ export class UnsPathNode {
|
|
|
103
105
|
resolve(): Promise<UnsObject>;
|
|
104
106
|
queryData(options?: UnsDataQueryOptions): Promise<UnsObject>;
|
|
105
107
|
writeData(fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
|
|
106
|
-
deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
|
|
107
|
-
pointCurrent(): Promise<UnsObject>;
|
|
108
|
-
|
|
108
|
+
deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
|
|
109
|
+
pointCurrent(): Promise<UnsObject>;
|
|
110
|
+
pointRealtimeConfig(): Promise<UnsObject>;
|
|
111
|
+
pointHistory(options: UnsPointHistoryOptions): Promise<UnsObject>;
|
|
109
112
|
writePoint(value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
|
|
110
113
|
videoStreamOptions(): Promise<UnsObject>;
|
|
111
114
|
videoSnapshot(): Promise<UnsObject>;
|
|
@@ -124,21 +127,23 @@ export const uns: {
|
|
|
124
127
|
searchResources: typeof searchUnsResources;
|
|
125
128
|
bindings: typeof listUnsBindings;
|
|
126
129
|
resolvePath: typeof resolveUnsPath;
|
|
127
|
-
validate: typeof validateUnsDocument;
|
|
128
|
-
plan: typeof planUnsDocument;
|
|
129
|
-
apply: typeof applyUnsDocument;
|
|
130
|
-
validateChanges: typeof validateUnsChanges;
|
|
131
|
-
planChanges: typeof planUnsChanges;
|
|
132
|
-
applyChanges: typeof applyUnsChanges;
|
|
130
|
+
validate: typeof validateUnsDocument;
|
|
131
|
+
plan: typeof planUnsDocument;
|
|
132
|
+
apply: typeof applyUnsDocument;
|
|
133
|
+
validateChanges: typeof validateUnsChanges;
|
|
134
|
+
planChanges: typeof planUnsChanges;
|
|
135
|
+
applyChanges: typeof applyUnsChanges;
|
|
133
136
|
queryNodeData: typeof queryUnsNodeData;
|
|
134
137
|
writeNodeData: typeof writeUnsNodeData;
|
|
135
138
|
deleteNodeData: typeof deleteUnsNodeData;
|
|
136
139
|
queryPathData: typeof queryUnsPathData;
|
|
137
140
|
writePathData: typeof writeUnsPathData;
|
|
138
141
|
deletePathData: typeof deleteUnsPathData;
|
|
139
|
-
pointCurrent: typeof getUnsPointCurrent;
|
|
140
|
-
pathPointCurrent: typeof getUnsPathPointCurrent;
|
|
141
|
-
|
|
142
|
+
pointCurrent: typeof getUnsPointCurrent;
|
|
143
|
+
pathPointCurrent: typeof getUnsPathPointCurrent;
|
|
144
|
+
pointRealtimeConfig: typeof getUnsPointRealtimeConfig;
|
|
145
|
+
pathPointRealtimeConfig: typeof getUnsPathPointRealtimeConfig;
|
|
146
|
+
pointHistory: typeof getUnsPointHistory;
|
|
142
147
|
pathPointHistory: typeof getUnsPathPointHistory;
|
|
143
148
|
writePoint: typeof writeUnsPoint;
|
|
144
149
|
writePathPoint: typeof writeUnsPathPoint;
|
package/dist/uns.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ApiError as t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as r}from"./runtime.js";function a(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function i(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}function s(t,e,n,o){return i(t,`/uns/runtime/${e}/${encodeURIComponent(n)}/${o}`)}function c(t,e,n){const o=String(n||"").trim();if(!o)throw new TypeError("UNS path cannot be empty");return`${i(t,`/uns/runtime/path/${e}`)}?${new URLSearchParams({path:o})}`}function p(t,e){return new URL(`${t.baseUrl}/api/v1${e}`)}async function u(e){const n=await e.text();let o=null;try{o=n?JSON.parse(n):null}catch{throw new t(n||`platform UNS API returned ${e.status}`,{status:e.status,details:n})}if(!e.ok)throw new t(o?.message||n||`platform UNS API returned ${e.status}`,{status:e.status,code:"number"==typeof o?.code?o.code:void 0,details:o});if(!o||"object"!=typeof o)return o;if(void 0!==o.code&&0!==o.code||!1===o.success)throw new t(o.message||"platform UNS API failed",{status:e.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function d(i,s,{body:c,config:d}={}){let h=d||await o();for(let t=0;t<2;t+=1)try{const t="function"==typeof s?s(h):s,n=await fetch(p(h,t),{method:i,headers:e(h,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(a(c))});return await u(n)}catch(e){if(0===t&&r(e)){h=await n(h);continue}throw e}throw new t("platform UNS API failed")}export function getCurrentUnsSchema(){return d("GET","/uns/schemas/current")}export function getUnsSchema(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}`)}export function listUnsSchemaBlocks(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks`)}export function getUnsSchemaBlock(t,{version:e="1.0",depth:n=1}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/${encodeURIComponent(t)}?depth=${encodeURIComponent(n)}`)}export function getUnsProtocolSchema(t,{version:e="1.0"}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/collection-point/protocols/${encodeURIComponent(t)}`)}export async function discoverUnsResources({resourceTypes:t=[],protocols:e=[]}={}){const n=await o();return d("POST",i(n,"/uns/discover"),{body:{resourceTypes:t,protocols:e},config:n})}export async function searchUnsResources(t,e={}){const n=await o();return d("POST",i(n,"/uns/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:n})}export async function listUnsBindings(){const t=await o();return d("GET",i(t,"/uns/bindings"),{config:t})}export async function resolveUnsPath(t){const e=await o();return d("GET",c(e,"resolve",t),{config:e})}export async function validateUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/validate"),{body:{document:t},config:e})}export async function planUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/plan"),{body:{document:t},config:e})}export async function applyUnsDocument(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("UNS apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS apply requires document and plan hashes");const a=await o();return d("POST",i(a,"/uns/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0},config:a})}export async function validateUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/validate"),{body:{document:t},config:e})}export async function planUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/plan"),{body:{document:t},config:e})}export async function applyUnsChanges(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("UNS changes apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS changes apply requires document and plan hashes");const a=await o();return d("POST",i(a,"/uns/changes/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:a})}function h(t={}){return a({pageNum:t.pageNum??t.page_num??1,pageSize:t.pageSize??t.page_size??50,paginationMode:t.paginationMode??t.pagination_mode??"OFFSET",pageToken:t.pageToken??t.page_token})}export async function queryUnsNodeData(t,e={}){const n=await o();return d("POST",s(n,"nodes",t,"query"),{body:h(e),config:n})}function f(t,e){if(!0!==e)throw new TypeError("UNS data write requires explicit confirmation");if(!t||"object"!=typeof t||0===Object.keys(t).length)throw new TypeError("UNS data write field values cannot be empty")}export async function writeUnsNodeData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",s(r,"nodes",t,"write"),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}function m(t,e){if(!0!==e)throw new TypeError("UNS data deletion requires explicit confirmation");if(!Array.isArray(t)||0===t.length||t.some(t=>!t||"object"!=typeof t||Array.isArray(t)||0===Object.keys(t).length))throw new TypeError("UNS data deletion rows cannot be empty")}export async function deleteUnsNodeData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",s(r,"nodes",t,"delete"),{body:{rows:e,confirmed:!0},config:r})}export async function queryUnsPathData(t,e={}){const n=await o();return d("POST",c(n,"data/query",t),{body:h(e),config:n})}export async function writeUnsPathData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",c(r,"data/write",t),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}export async function deleteUnsPathData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",c(r,"data/delete",t),{body:{rows:e,confirmed:!0},config:r})}export async function getUnsPointCurrent(t){const e=await o();return d("GET",s(e,"points",t,"current"),{config:e})}export async function getUnsPathPointCurrent(t){const e=await o();return d("GET",c(e,"point/current",t),{config:e})}function l(t={}){return{startTime:t.startTime??t.start_time,endTime:t.endTime??t.end_time,page:t.page??1,pageSize:t.pageSize??t.page_size??100}}export async function getUnsPointHistory(t,e){const n=await o();return d("POST",s(n,"points",t,"history"),{body:l(e),config:n})}export async function getUnsPathPointHistory(t,e){const n=await o();return d("POST",c(n,"point/history",t),{body:l(e),config:n})}function y(t,e={}){const n=String(e.reason||"").trim(),o=String(e.ticket||"").trim(),r=e.dryRun??e.dry_run??!1,i=e.confirmed??!1;if(!r&&!0!==i)throw new TypeError("UNS point write requires explicit confirmation");if(!n||!o)throw new TypeError("UNS point write requires reason and ticket");return a({value:t,reason:n,ticket:o,requestId:e.requestId??e.request_id,dryRun:r,confirmed:i})}export async function writeUnsPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",s(a,"points",t,"write"),{body:r,config:a})}export async function writeUnsPathPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",c(a,"point/write",t),{body:r,config:a})}export async function getUnsVideoStreamOptions(t){const e=await o();return d("GET",s(e,"videos",t,"stream-options"),{config:e})}export async function getUnsPathVideoStreamOptions(t){const e=await o();return d("GET",c(e,"video/stream-options",t),{config:e})}export async function createUnsVideoSnapshot(t){const e=await o();return d("POST",s(e,"videos",t,"snapshot"),{config:e})}export async function createUnsPathVideoSnapshot(t){const e=await o();return d("POST",c(e,"video/snapshot",t),{config:e})}function U(t,e={}){if(!0!==e.confirmed)throw new TypeError("UNS video control requires explicit confirmation");return{action:t,parameters:e.parameters||{},confirmed:!0}}export async function controlUnsVideo(t,e,n={}){const r=U(e,n),a=await o();return d("POST",s(a,"videos",t,"control"),{body:r,config:a})}export async function controlUnsPathVideo(t,e,n={}){const r=U(e,n),a=await o();return d("POST",c(a,"video/control",t),{body:r,config:a})}export class UnsPathNode{constructor(t){if(this.path=String(t||"").trim(),!this.path)throw new TypeError("UNS path cannot be empty")}resolve(){return resolveUnsPath(this.path)}queryData(t){return queryUnsPathData(this.path,t)}writeData(t,e){return writeUnsPathData(this.path,t,e)}deleteData(t,e){return deleteUnsPathData(this.path,t,e)}pointCurrent(){return getUnsPathPointCurrent(this.path)}pointHistory(t){return getUnsPathPointHistory(this.path,t)}writePoint(t,e){return writeUnsPathPoint(this.path,t,e)}videoStreamOptions(){return getUnsPathVideoStreamOptions(this.path)}videoSnapshot(){return createUnsPathVideoSnapshot(this.path)}controlVideo(t,e){return controlUnsPathVideo(this.path,t,e)}}export function openUnsPath(t){return new UnsPathNode(t)}export const uns={schemaCurrent:getCurrentUnsSchema,schema:getUnsSchema,schemaBlocks:listUnsSchemaBlocks,schemaBlock:getUnsSchemaBlock,protocolSchema:getUnsProtocolSchema,discover:discoverUnsResources,searchResources:searchUnsResources,bindings:listUnsBindings,resolvePath:resolveUnsPath,validate:validateUnsDocument,plan:planUnsDocument,apply:applyUnsDocument,validateChanges:validateUnsChanges,planChanges:planUnsChanges,applyChanges:applyUnsChanges,queryNodeData:queryUnsNodeData,writeNodeData:writeUnsNodeData,deleteNodeData:deleteUnsNodeData,queryPathData:queryUnsPathData,writePathData:writeUnsPathData,deletePathData:deleteUnsPathData,pointCurrent:getUnsPointCurrent,pathPointCurrent:getUnsPathPointCurrent,pointHistory:getUnsPointHistory,pathPointHistory:getUnsPathPointHistory,writePoint:writeUnsPoint,writePathPoint:writeUnsPathPoint,videoStreamOptions:getUnsVideoStreamOptions,pathVideoStreamOptions:getUnsPathVideoStreamOptions,videoSnapshot:createUnsVideoSnapshot,pathVideoSnapshot:createUnsPathVideoSnapshot,controlVideo:controlUnsVideo,controlPathVideo:controlUnsPathVideo,openPath:openUnsPath};
|
|
1
|
+
import{ApiError as t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as r}from"./runtime.js";function a(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function i(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}function s(t,e,n,o){return i(t,`/uns/runtime/${e}/${encodeURIComponent(n)}/${o}`)}function c(t,e,n){const o=String(n||"").trim();if(!o)throw new TypeError("UNS path cannot be empty");return`${i(t,`/uns/runtime/path/${e}`)}?${new URLSearchParams({path:o})}`}function p(t,e){return new URL(`${t.baseUrl}/api/v1${e}`)}async function u(e){const n=await e.text();let o=null;try{o=n?JSON.parse(n):null}catch{throw new t(n||`platform UNS API returned ${e.status}`,{status:e.status,details:n})}if(!e.ok)throw new t(o?.message||n||`platform UNS API returned ${e.status}`,{status:e.status,code:"number"==typeof o?.code?o.code:void 0,details:o});if(!o||"object"!=typeof o)return o;if(void 0!==o.code&&0!==o.code||!1===o.success)throw new t(o.message||"platform UNS API failed",{status:e.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function d(i,s,{body:c,config:d}={}){let h=d||await o();for(let t=0;t<2;t+=1)try{const t="function"==typeof s?s(h):s,n=await fetch(p(h,t),{method:i,headers:e(h,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(a(c))});return await u(n)}catch(e){if(0===t&&r(e)){h=await n(h);continue}throw e}throw new t("platform UNS API failed")}export function getCurrentUnsSchema(){return d("GET","/uns/schemas/current")}export function getUnsSchema(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}`)}export function listUnsSchemaBlocks(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks`)}export function getUnsSchemaBlock(t,{version:e="1.0",depth:n=1}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/${encodeURIComponent(t)}?depth=${encodeURIComponent(n)}`)}export function getUnsProtocolSchema(t,{version:e="1.0"}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/collection-point/protocols/${encodeURIComponent(t)}`)}export async function discoverUnsResources({resourceTypes:t=[],protocols:e=[]}={}){const n=await o();return d("POST",i(n,"/uns/discover"),{body:{resourceTypes:t,protocols:e},config:n})}export async function searchUnsResources(t,e={}){const n=await o();return d("POST",i(n,"/uns/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:n})}export async function listUnsBindings(){const t=await o();return d("GET",i(t,"/uns/bindings"),{config:t})}export async function resolveUnsPath(t){const e=await o();return d("GET",c(e,"resolve",t),{config:e})}export async function validateUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/validate"),{body:{document:t},config:e})}export async function planUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/plan"),{body:{document:t},config:e})}export async function applyUnsDocument(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("UNS apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS apply requires document and plan hashes");const a=await o();return d("POST",i(a,"/uns/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0},config:a})}export async function validateUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/validate"),{body:{document:t},config:e})}export async function planUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/plan"),{body:{document:t},config:e})}export async function applyUnsChanges(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("UNS changes apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS changes apply requires document and plan hashes");const a=await o();return d("POST",i(a,"/uns/changes/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:a})}function h(t={}){return a({pageNum:t.pageNum??t.page_num??1,pageSize:t.pageSize??t.page_size??50,paginationMode:t.paginationMode??t.pagination_mode??"OFFSET",pageToken:t.pageToken??t.page_token})}export async function queryUnsNodeData(t,e={}){const n=await o();return d("POST",s(n,"nodes",t,"query"),{body:h(e),config:n})}function f(t,e){if(!0!==e)throw new TypeError("UNS data write requires explicit confirmation");if(!t||"object"!=typeof t||0===Object.keys(t).length)throw new TypeError("UNS data write field values cannot be empty")}export async function writeUnsNodeData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",s(r,"nodes",t,"write"),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}function m(t,e){if(!0!==e)throw new TypeError("UNS data deletion requires explicit confirmation");if(!Array.isArray(t)||0===t.length||t.some(t=>!t||"object"!=typeof t||Array.isArray(t)||0===Object.keys(t).length))throw new TypeError("UNS data deletion rows cannot be empty")}export async function deleteUnsNodeData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",s(r,"nodes",t,"delete"),{body:{rows:e,confirmed:!0},config:r})}export async function queryUnsPathData(t,e={}){const n=await o();return d("POST",c(n,"data/query",t),{body:h(e),config:n})}export async function writeUnsPathData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",c(r,"data/write",t),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}export async function deleteUnsPathData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",c(r,"data/delete",t),{body:{rows:e,confirmed:!0},config:r})}export async function getUnsPointCurrent(t){const e=await o();return d("GET",s(e,"points",t,"current"),{config:e})}export async function getUnsPathPointCurrent(t){const e=await o();return d("GET",c(e,"point/current",t),{config:e})}export async function getUnsPointRealtimeConfig(t){const e=await o();return d("GET",s(e,"points",t,"realtime-config"),{config:e})}export async function getUnsPathPointRealtimeConfig(t){const e=await o();return d("GET",c(e,"point/realtime-config",t),{config:e})}function l(t={}){return{startTime:t.startTime??t.start_time,endTime:t.endTime??t.end_time,page:t.page??1,pageSize:t.pageSize??t.page_size??100}}export async function getUnsPointHistory(t,e){const n=await o();return d("POST",s(n,"points",t,"history"),{body:l(e),config:n})}export async function getUnsPathPointHistory(t,e){const n=await o();return d("POST",c(n,"point/history",t),{body:l(e),config:n})}function y(t,e={}){const n=String(e.reason||"").trim(),o=String(e.ticket||"").trim(),r=e.dryRun??e.dry_run??!1,i=e.confirmed??!1;if(!r&&!0!==i)throw new TypeError("UNS point write requires explicit confirmation");if(!n||!o)throw new TypeError("UNS point write requires reason and ticket");return a({value:t,reason:n,ticket:o,requestId:e.requestId??e.request_id,dryRun:r,confirmed:i})}export async function writeUnsPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",s(a,"points",t,"write"),{body:r,config:a})}export async function writeUnsPathPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",c(a,"point/write",t),{body:r,config:a})}export async function getUnsVideoStreamOptions(t){const e=await o();return d("GET",s(e,"videos",t,"stream-options"),{config:e})}export async function getUnsPathVideoStreamOptions(t){const e=await o();return d("GET",c(e,"video/stream-options",t),{config:e})}export async function createUnsVideoSnapshot(t){const e=await o();return d("POST",s(e,"videos",t,"snapshot"),{config:e})}export async function createUnsPathVideoSnapshot(t){const e=await o();return d("POST",c(e,"video/snapshot",t),{config:e})}function g(t,e={}){if(!0!==e.confirmed)throw new TypeError("UNS video control requires explicit confirmation");return{action:t,parameters:e.parameters||{},confirmed:!0}}export async function controlUnsVideo(t,e,n={}){const r=g(e,n),a=await o();return d("POST",s(a,"videos",t,"control"),{body:r,config:a})}export async function controlUnsPathVideo(t,e,n={}){const r=g(e,n),a=await o();return d("POST",c(a,"video/control",t),{body:r,config:a})}export class UnsPathNode{constructor(t){if(this.path=String(t||"").trim(),!this.path)throw new TypeError("UNS path cannot be empty")}resolve(){return resolveUnsPath(this.path)}queryData(t){return queryUnsPathData(this.path,t)}writeData(t,e){return writeUnsPathData(this.path,t,e)}deleteData(t,e){return deleteUnsPathData(this.path,t,e)}pointCurrent(){return getUnsPathPointCurrent(this.path)}pointRealtimeConfig(){return getUnsPathPointRealtimeConfig(this.path)}pointHistory(t){return getUnsPathPointHistory(this.path,t)}writePoint(t,e){return writeUnsPathPoint(this.path,t,e)}videoStreamOptions(){return getUnsPathVideoStreamOptions(this.path)}videoSnapshot(){return createUnsPathVideoSnapshot(this.path)}controlVideo(t,e){return controlUnsPathVideo(this.path,t,e)}}export function openUnsPath(t){return new UnsPathNode(t)}export const uns={schemaCurrent:getCurrentUnsSchema,schema:getUnsSchema,schemaBlocks:listUnsSchemaBlocks,schemaBlock:getUnsSchemaBlock,protocolSchema:getUnsProtocolSchema,discover:discoverUnsResources,searchResources:searchUnsResources,bindings:listUnsBindings,resolvePath:resolveUnsPath,validate:validateUnsDocument,plan:planUnsDocument,apply:applyUnsDocument,validateChanges:validateUnsChanges,planChanges:planUnsChanges,applyChanges:applyUnsChanges,queryNodeData:queryUnsNodeData,writeNodeData:writeUnsNodeData,deleteNodeData:deleteUnsNodeData,queryPathData:queryUnsPathData,writePathData:writeUnsPathData,deletePathData:deleteUnsPathData,pointCurrent:getUnsPointCurrent,pathPointCurrent:getUnsPathPointCurrent,pointRealtimeConfig:getUnsPointRealtimeConfig,pathPointRealtimeConfig:getUnsPathPointRealtimeConfig,pointHistory:getUnsPointHistory,pathPointHistory:getUnsPathPointHistory,writePoint:writeUnsPoint,writePathPoint:writeUnsPathPoint,videoStreamOptions:getUnsVideoStreamOptions,pathVideoStreamOptions:getUnsPathVideoStreamOptions,videoSnapshot:createUnsVideoSnapshot,pathVideoSnapshot:createUnsPathVideoSnapshot,controlVideo:controlUnsVideo,controlPathVideo:controlUnsPathVideo,openPath:openUnsPath};
|