in packages/sqrl-redis-functions/src/LabelFunctions.ts [35:110]
export function registerLabelFunctions(
instance: Instance,
service: LabelService
) {
instance.registerStatement(
"SqrlLabelStatements",
async function addLabel(
state: Execution,
cause: WhenCause,
entities: SqrlEntity | SqrlEntity[],
label: string
) {
ensureArray(entities).forEach((entity) => {
if (entity !== null) {
service.addLabel(state.manipulator, entity, label, cause);
}
});
},
{
args: [
AT.state,
AT.whenCause,
AT.any.sqrlEntityOrEntities,
AT.constant.string,
],
allowNull: true,
allowSqrlObjects: true,
argstring: "entity | entity list, label",
docstring: "Adds the provided label to the specified entities",
}
);
instance.registerStatement(
"SqrlLabelStatements",
async function removeLabel(
state: Execution,
cause: WhenCause,
entities: SqrlEntity | SqrlEntity[],
label: string
) {
ensureArray(entities).forEach((entity) => {
if (entity !== null) {
service.removeLabel(state.manipulator, entity, label, cause);
}
});
},
{
args: [
AT.state,
AT.whenCause,
AT.any.sqrlEntityOrEntities,
AT.constant.string,
],
allowNull: true,
allowSqrlObjects: true,
argstring: "entity | entity list, label",
docstring: "Removes the provided label to the specified entities",
}
);
instance.register(
async function hasLabel(
state: Execution,
entity: SqrlEntity,
label: string
) {
return service.hasLabel(state.ctx, entity, label);
},
{
args: [AT.state, AT.any.sqrlEntity, AT.constant.string],
allowSqrlObjects: true,
argstring: "entity, label",
docstring: "Returns true if the provided entity has the given label",
}
);
}