org-core-js 0.0.2 → 0.0.4

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.
@@ -129,10 +129,8 @@ var _default = async config => {
129
129
  input = new TextDecoder().decode(m.data);
130
130
  }
131
131
  const res = await fn(input);
132
- if (m.respond(sc.encode(Buffer.from(JSON.stringify(res || {}))))) {
133
- // console.info(`[time] handled #${sub.getProcessed()}`);
134
- } else {
135
- // console.log(`[time] #${sub.getProcessed()} ignored - no reply subject`);
132
+ if (m.respond(sc.encode(Buffer.from(JSON.stringify(res || {}))))) {} else {
133
+ console.log(`[time] #${sub.getProcessed()} ignored - no reply subject`);
136
134
  }
137
135
  }
138
136
  })(nc.subscribe("service:" + name, config));
@@ -155,6 +153,27 @@ var _default = async config => {
155
153
  output = JSON.parse(output);
156
154
  } catch (error) {}
157
155
  return output;
156
+ },
157
+ fogu() {
158
+ const n = this;
159
+ return {
160
+ subscribe(virtual, channel, name, fn, config = {}) {
161
+ return n.sub({
162
+ topic: virtual + "::" + channel + ":" + name
163
+ }, fn, config);
164
+ },
165
+ publish(virtual, channel, name, data) {
166
+ return n.pub({
167
+ topic: virtual + "::" + channel + ":" + name
168
+ }, data);
169
+ },
170
+ action(virtual, channel, name, fn, auth = null, config = {}) {
171
+ return n.service(virtual + "::" + channel + ":" + name, fn, auth, config);
172
+ },
173
+ async call(virtual, channel, name, data = {}, _headers = {}, config = {}) {
174
+ return await n.command(virtual + "::" + channel + ":" + name, data, _headers, config);
175
+ }
176
+ };
158
177
  }
159
178
  };
160
179
  };
@@ -136,6 +136,26 @@ var _default = ({
136
136
  });
137
137
  });
138
138
  });
139
+ },
140
+ async "natsfogu"({
141
+ server
142
+ }) {
143
+ const nats = core.app.driver("nats");
144
+ await core.forawait.generate(server.services, async service => {
145
+ const actions = servicesGet(service.actions, {});
146
+ await core.forawait.generate(actions, async action => {
147
+ nats.fogu().action(service.virtual, service.channel, action.exec, core.app.service(action.exec).execute, async headers => {
148
+ if (!action.auth) return true;
149
+ try {
150
+ const [m, exec] = action.auth.split(":");
151
+ const [name, c] = exec.split(".");
152
+ return (await core.app[m](name)[c](headers)) || false;
153
+ } catch (error) {
154
+ return false;
155
+ }
156
+ });
157
+ });
158
+ });
139
159
  }
140
160
  };
141
161
  };
@@ -128,10 +128,11 @@ export default async (config) => {
128
128
  input =new TextDecoder().decode(m.data)
129
129
  }
130
130
  const res = await fn(input)
131
+
131
132
  if (m.respond(sc.encode(Buffer.from(JSON.stringify(res || {}))))) {
132
- // console.info(`[time] handled #${sub.getProcessed()}`);
133
+
133
134
  } else {
134
- // console.log(`[time] #${sub.getProcessed()} ignored - no reply subject`);
135
+ console.log(`[time] #${sub.getProcessed()} ignored - no reply subject`);
135
136
  }
136
137
  }
137
138
  })(nc.subscribe("service:" + name, config));
@@ -155,6 +156,24 @@ export default async (config) => {
155
156
  }
156
157
  return output
157
158
 
159
+ },
160
+ fogu(){
161
+ const n=this
162
+ return {
163
+ subscribe(virtual,channel,name,fn,config = {}){
164
+ return n.sub({topic:virtual+"::"+channel+":"+name},fn,config)
165
+ },
166
+ publish(virtual,channel,name,data){
167
+ return n.pub({topic:virtual+"::"+channel+":"+name},data)
168
+ },
169
+ action(virtual,channel,name,fn, auth = null, config = {}){
170
+ return n.service(virtual+"::"+channel+":"+name,fn, auth,config)
171
+ },
172
+ async call(virtual,channel,name,data = {}, _headers = {}, config = {}){
173
+ return await n.command(virtual+"::"+channel+":"+name,data, _headers,config)
174
+ }
175
+
176
+ }
158
177
  }
159
178
  }
160
179
  }
@@ -149,8 +149,32 @@ export default ({ core }) => {
149
149
 
150
150
 
151
151
 
152
- }
152
+ },
153
153
 
154
+ async "natsfogu"({ server }) {
155
+ const nats = core.app.driver("nats")
156
+ await core.forawait.generate(server.services, async (service) => {
157
+ const actions= servicesGet(service.actions,{})
158
+ await core.forawait.generate(actions, async (action) => {
159
+ nats.fogu().action(service.virtual,service.channel, action.exec, core.app.service(action.exec).execute, async (headers) => {
160
+ if (!action.auth) return true
161
+ try {
162
+ const [m, exec] = action.auth.split(":")
163
+ const [name, c] = exec.split(".")
164
+ return (await core.app[m](name)[c](headers)) || false
165
+ } catch (error) {
166
+ return false
167
+ }
168
+ })
169
+
170
+ })
171
+
172
+
173
+ })
174
+
175
+
176
+
177
+ }
154
178
  }
155
179
 
156
180
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "org-core-js",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "src/start.js",
6
6
  "scripts": {