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.
- package/cjs/core/drivers/nats.js +23 -4
- package/cjs/core/serverCore.js +20 -0
- package/esm/core/drivers/nats.js +21 -2
- package/esm/core/serverCore.js +25 -1
- package/package.json +1 -1
package/cjs/core/drivers/nats.js
CHANGED
|
@@ -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
|
-
|
|
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
|
};
|
package/cjs/core/serverCore.js
CHANGED
|
@@ -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
|
};
|
package/esm/core/drivers/nats.js
CHANGED
|
@@ -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
|
-
|
|
133
|
+
|
|
133
134
|
} else {
|
|
134
|
-
|
|
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
|
}
|
package/esm/core/serverCore.js
CHANGED
|
@@ -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
|
|