API support for Get/SetParameterAttributes
This commit is contained in:
1 parent
d311dad861
commit
96add7efe2
4 files changed
+74
-11
No files matched your search
@@ -241,6 +241,18 @@ function sanitizeTask(task): void {
|
|||||||
)
|
)
|
||||||
throw new Error("Invalid 'targetFileName' property");
|
throw new Error("Invalid 'targetFileName' property");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "provisions":
|
||||||
|
if (
|
||||||
|
!Array.isArray(task.provisions) ||
|
||||||
|
!task.provisions.every(arr =>
|
||||||
|
arr.every(
|
||||||
|
s => s == null || ["boolean", "number", "string"].includes(typeof s)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
throw new Error("Invalid 'provisions' property");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|||||||
@@ -686,6 +686,13 @@ async function nextRpc(sessionContext: SessionContext): Promise<void> {
|
|||||||
["instances", task.objectName, 0]
|
["instances", task.objectName, 0]
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
case "provisions":
|
||||||
|
session.addProvisions(
|
||||||
|
sessionContext,
|
||||||
|
`task_${task._id}`,
|
||||||
|
task.provisions
|
||||||
|
);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Task name not recognized");
|
throw new Error("Task name not recognized");
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-11
@@ -29,25 +29,45 @@ export function refresh(sessionContext, provision, declarations): boolean {
|
|||||||
(provision.length !== 2 || typeof provision[1] !== "string") &&
|
(provision.length !== 2 || typeof provision[1] !== "string") &&
|
||||||
(provision.length !== 3 ||
|
(provision.length !== 3 ||
|
||||||
typeof provision[1] !== "string" ||
|
typeof provision[1] !== "string" ||
|
||||||
typeof provision[2] !== "number")
|
typeof provision[2] !== "number") &&
|
||||||
|
(provision.length < 4 ||
|
||||||
|
typeof provision[1] !== "string" ||
|
||||||
|
typeof provision[2] !== "number" ||
|
||||||
|
typeof provision[3] !== "boolean")
|
||||||
)
|
)
|
||||||
throw new Error("Invalid arguments");
|
throw new Error("Invalid arguments");
|
||||||
|
|
||||||
const segments = Path.parse(provision[1]).segments.slice();
|
|
||||||
const l = segments.length;
|
|
||||||
segments.length = MAX_DEPTH;
|
|
||||||
segments.fill("*", l);
|
|
||||||
const path = Path.parse(segments.join("."));
|
|
||||||
const every = 1000 * (provision[2] || 1);
|
const every = 1000 * (provision[2] || 1);
|
||||||
const offset = scheduling.variance(sessionContext.deviceId, every);
|
const offset = scheduling.variance(sessionContext.deviceId, every);
|
||||||
const t = scheduling.interval(sessionContext.timestamp, every, offset);
|
const t = scheduling.interval(sessionContext.timestamp, every, offset);
|
||||||
|
|
||||||
for (let i = l; i < path.length; ++i) {
|
let attrGet;
|
||||||
|
let refreshChildren;
|
||||||
|
if (provision[3] == null) {
|
||||||
|
refreshChildren = true;
|
||||||
|
attrGet = { object: 1, writable: 1, value: t };
|
||||||
|
} else {
|
||||||
|
attrGet = {};
|
||||||
|
refreshChildren = !!provision[3];
|
||||||
|
for (const a of provision.slice(4)) attrGet[a] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = Path.parse(provision[1]);
|
||||||
|
let l = path.length;
|
||||||
|
if (refreshChildren) {
|
||||||
|
const segments = path.segments.slice();
|
||||||
|
l = segments.length;
|
||||||
|
segments.length = MAX_DEPTH;
|
||||||
|
segments.fill("*", l);
|
||||||
|
path = Path.parse(segments.join("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = l; i <= path.length; ++i) {
|
||||||
declarations.push({
|
declarations.push({
|
||||||
path: path.slice(0, i),
|
path: path.slice(0, i),
|
||||||
pathGet: t,
|
pathGet: t,
|
||||||
pathSet: null,
|
pathSet: null,
|
||||||
attrGet: { object: 1, writable: 1, value: t },
|
attrGet: attrGet,
|
||||||
attrSet: null,
|
attrSet: null,
|
||||||
defer: true
|
defer: true
|
||||||
});
|
});
|
||||||
@@ -57,15 +77,38 @@ export function refresh(sessionContext, provision, declarations): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function value(sessionContext, provision, declarations): boolean {
|
export function value(sessionContext, provision, declarations): boolean {
|
||||||
if (provision.length !== 3 || typeof provision[1] !== "string")
|
if (
|
||||||
|
provision.length < 3 ||
|
||||||
|
provision.length > 4 ||
|
||||||
|
typeof provision[1] !== "string"
|
||||||
|
)
|
||||||
throw new Error("Invalid arguments");
|
throw new Error("Invalid arguments");
|
||||||
|
|
||||||
|
let attr: string, val: any;
|
||||||
|
|
||||||
|
if (provision.length === 3) {
|
||||||
|
attr = "value";
|
||||||
|
val = provision[2];
|
||||||
|
} else {
|
||||||
|
attr = provision[2] || "";
|
||||||
|
val = provision[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr === "accessList") {
|
||||||
|
val = (val || "")
|
||||||
|
.split(",")
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(s => !!s);
|
||||||
|
} else if (attr === "value") {
|
||||||
|
val = [val];
|
||||||
|
}
|
||||||
|
|
||||||
declarations.push({
|
declarations.push({
|
||||||
path: Path.parse(provision[1]),
|
path: Path.parse(provision[1]),
|
||||||
pathGet: 1,
|
pathGet: 1,
|
||||||
pathSet: null,
|
pathSet: null,
|
||||||
attrGet: { value: 1 },
|
attrGet: { [attr]: 1 },
|
||||||
attrSet: { value: [provision[2]] },
|
attrSet: { [attr]: val },
|
||||||
defer: true
|
defer: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ export interface Task {
|
|||||||
fileName?: string;
|
fileName?: string;
|
||||||
targetFileName?: string;
|
targetFileName?: string;
|
||||||
expiry?: number;
|
expiry?: number;
|
||||||
|
provisions?: (string | number | boolean)[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Operation {
|
export interface Operation {
|
||||||
|
|||||||
Reference in new issue
Block a user