{"id":24965777,"url":"https://github.com/allnulled/lsw-trigger","last_synced_at":"2025-03-29T01:19:25.212Z","repository":{"id":274429243,"uuid":"922853878","full_name":"allnulled/lsw-trigger","owner":"allnulled","description":"Trigger tool for LSW","archived":false,"fork":false,"pushed_at":"2025-03-24T17:50:04.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T18:46:09.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allnulled.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-27T07:45:36.000Z","updated_at":"2025-03-24T17:50:08.000Z","dependencies_parsed_at":"2025-03-24T18:34:11.132Z","dependency_job_id":"0dab1a03-d54f-4790-8095-8f2fdc1e65fa","html_url":"https://github.com/allnulled/lsw-trigger","commit_stats":null,"previous_names":["allnulled/lsw-trigger"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-trigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-trigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-trigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Flsw-trigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allnulled","download_url":"https://codeload.github.com/allnulled/lsw-trigger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246122474,"owners_count":20726835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-03T11:16:11.049Z","updated_at":"2025-03-29T01:19:25.194Z","avatar_url":"https://github.com/allnulled.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lsw-trigger\n\nRegister and emit async triggers using asterisks, names, priority and parameters. Less than 100 lines script.\n\nBranch of [@allnulled/triggers-class](https://github.com/allnulled/triggers-class).\n\n## Installation\n\n```sh\nnpm i -s @allnulled/lsw-trigger\n```\n\n## Import\n\nIn node.js:\n\n```js\nrequire(\"@allnulled/lsw-trigger\");\n```\n\nIn html:\n\n```html\n\u003cscript src=\"node_modules/@allnulled/lsw-trigger/triggers-class.js\"\u003e\u003c/script\u003e\n```\n\nThen you can use `window.TriggersClass` or `global.TriggersClass`.\n\n## API\n\nThese are the signatures of the methods:\n\n```js\nTriggersClass.globMatch(patterns, list);\nconst triggersClass = new TriggersClass();\ntriggersClass.all = {};\ntriggersClass.register(triggerNamePattern, triggerIdentifier, triggerCallback, triggerConfigurations = {});\nawait triggersClass.emit(triggerName, parameters = {});\ntriggersClass.unregister(triggerIdentifier);\n```\n\nThe `globMatch` static method accepts a patterns list, and a texts list. It will return the texts that match at least one pattern.\n\nThe `register` method requires `name:string`, `identifier:string` and `callback:function`. Optionally, `configurations:object`. \n  - `name` is the name of the event. This one accepts `*` as any character/s, like glob patterns.\n  - `identifier` is the name of this registration.\n  - `callback` is the function triggered.\n  - `configurations` is an object. It can have `priority` as a number. The higher, the sooner. Passed to the callback too.\n\nThe `emit` method requires `name:string` with the name of the event (no `*` accepted here). Optionally, `parameters:object`, passed to the callback too.\n\nThe `unregister` method requires only `identifier:string`, the same used on `register` call previously.\n\n## Example\n\nThis is the current test of the library.\n\n```js\nconsole.log(TriggersClass.globMatch([\n    \"crud.insert.*.users\",\n    \"crud.*.many.users\"\n], [\n    \"crud.select.one.users\",\n    \"crud.select.many.users\",\n    \"crud.insert.one.users\",\n    \"crud.insert.many.users\",\n    \"crud.update.one.users\",\n    \"crud.update.many.users\",\n    \"crud.delete.one.users\",\n    \"crud.delete.many.users\",\n]));\nconst triggers = new TriggersClass();\nlet counter = 0;\ntriggers.register(\"crud.insert.one.tabla1\", \"temp1\", function () {\n    console.log(\"triggering temp1\");\n    counter -= 2;\n    return 100;\n}, {\n    priority: 20\n});\ntriggers.register(\"crud.insert.one.tabla1\", \"temp2\", function () {\n    console.log(\"triggering temp2\");\n    counter *= 10;\n    return 10;\n}, {\n    priority: 10\n});\ntriggers.register(\"crud.insert.one.tabla1\", \"temp3\", function () {\n    console.log(\"triggering temp3\");\n    counter += 5;\n    return 1;\n}, {\n    priority: 30\n});\nconst output = await triggers.emit(\"crud.insert.one.tabla1\", { in: 500 });\nconst outputSum = output.reduce((o,i) =\u003e {\n    o += i;\n    return o;\n}, 0);\nsetTimeout(() =\u003e {\n    console.log(counter);\n    console.log(outputSum);\n    if(counter !== 30) {\n        throw new Error(\"Triggers order is not as expected\");\n    }\n    if(outputSum !== 111) {\n        throw new Error(\"Emit is not working as expected\");\n    }\n}, 1000);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Flsw-trigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallnulled%2Flsw-trigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Flsw-trigger/lists"}