@resolveio/server-lib 20.14.20 → 20.14.23

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.
@@ -0,0 +1 @@
1
+ export declare function loadPublicationMethods(methodManager: any): void;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
+ if (ar || !(i in from)) {
57
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
+ ar[i] = from[i];
59
+ }
60
+ }
61
+ return to.concat(ar || Array.prototype.slice.call(from));
62
+ };
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ exports.loadPublicationMethods = loadPublicationMethods;
65
+ var resolveio_server_app_1 = require("../resolveio-server-app");
66
+ var subscription_manager_1 = require("../managers/subscription.manager");
67
+ var subscription_dependency_context_1 = require("../util/subscription-dependency-context");
68
+ function normalizeSubscriptionData(subscriptionData) {
69
+ if (!Array.isArray(subscriptionData)) {
70
+ return [];
71
+ }
72
+ return subscriptionData;
73
+ }
74
+ function resolvePublicationContext(manager) {
75
+ return Object.assign({}, manager, subscription_manager_1.SubscriptionManager.prototype);
76
+ }
77
+ function getPublication(manager, publication) {
78
+ if (!manager || typeof manager.getPublication !== 'function') {
79
+ throw new Error("Subscription manager not available for publication: ".concat(publication));
80
+ }
81
+ var pub = manager.getPublication(publication);
82
+ if (!pub) {
83
+ throw new Error("Publication not found: ".concat(publication));
84
+ }
85
+ return pub;
86
+ }
87
+ function loadPublicationMethods(methodManager) {
88
+ methodManager.methods({
89
+ runPublication: {
90
+ skipValidation: true,
91
+ workerTaskWeight: parseInt(process.env.SUBSCRIPTION_WORKER_TASK_WEIGHT || '', 10) || 1,
92
+ maxConcurrency: parseInt(process.env.SUBSCRIPTION_WORKER_MAX_CONCURRENCY || '', 10) || undefined,
93
+ maxConcurrencyPerInstance: parseInt(process.env.SUBSCRIPTION_WORKER_MAX_CONCURRENCY_PER_INSTANCE || '', 10) || undefined,
94
+ function: function (publication_1) {
95
+ return __awaiter(this, arguments, void 0, function (publication, subscriptionData, userId) {
96
+ var manager, pub, normalizedData, context, valObj, valKeys, rootKeys, i, metadata, execution, _a, response;
97
+ if (subscriptionData === void 0) { subscriptionData = []; }
98
+ return __generator(this, function (_b) {
99
+ switch (_b.label) {
100
+ case 0:
101
+ if (this.user && this.user !== 'Internal System') {
102
+ throw new Error('Unauthorized publication execution');
103
+ }
104
+ manager = resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager();
105
+ pub = getPublication(manager, publication);
106
+ normalizedData = normalizeSubscriptionData(subscriptionData);
107
+ context = resolvePublicationContext(manager);
108
+ if (pub.check && pub.check._schema && (normalizedData.length > 1 || normalizedData[0])) {
109
+ valObj = {};
110
+ valKeys = Object.keys(pub.check._schema);
111
+ rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
112
+ for (i = 0; i < normalizedData.length; i++) {
113
+ valObj[rootKeys[i]] = normalizedData[i];
114
+ }
115
+ pub.check.validate(valObj);
116
+ }
117
+ metadata = {
118
+ publication: publication,
119
+ subscriptionData: normalizedData
120
+ };
121
+ if (!pub.user_specific) return [3 /*break*/, 2];
122
+ return [4 /*yield*/, (0, subscription_dependency_context_1.withDependencyTracking)(function () {
123
+ var _a;
124
+ return (_a = pub.function).call.apply(_a, __spreadArray([context, userId || ''], __read(normalizedData), false));
125
+ }, Object.assign({}, metadata, { userId: userId }))];
126
+ case 1:
127
+ _a = _b.sent();
128
+ return [3 /*break*/, 4];
129
+ case 2: return [4 /*yield*/, (0, subscription_dependency_context_1.withDependencyTracking)(function () {
130
+ var _a;
131
+ return (_a = pub.function).call.apply(_a, __spreadArray([context], __read(normalizedData), false));
132
+ }, metadata)];
133
+ case 3:
134
+ _a = _b.sent();
135
+ _b.label = 4;
136
+ case 4:
137
+ execution = _a;
138
+ response = {
139
+ __publicationResponse: true,
140
+ publication: publication,
141
+ subscriptionData: normalizedData,
142
+ userSpecific: !!pub.user_specific,
143
+ payload: execution.result,
144
+ snapshot: (0, subscription_dependency_context_1.serializeDependencySnapshot)(execution.snapshot)
145
+ };
146
+ return [2 /*return*/, response];
147
+ }
148
+ });
149
+ });
150
+ }
151
+ }
152
+ });
153
+ }
154
+
155
+ //# sourceMappingURL=publications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/methods/publications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,wDAuDC;AA9FD,gEAA0D;AAC1D,yEAAuE;AAEvE,2FAA8G;AAW9G,SAAS,yBAAyB,CAAC,gBAAuB;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED,SAAS,yBAAyB,CAAC,OAA4B;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,0CAAmB,CAAC,SAAS,CAAC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C7B;;oCAAM,OAAA,CAAA,KAAA,GAAG,CAAC,QAAQ,CAAA,CAAC,IAAI,0BAAC,OAAO,UAAK,cAAc;gCAA5C,CAA6C,EACnD,QAAQ,CACR,EAAA;;gCAHC,KAAA,SAGD,CAAA;;;gCARI,SAAS,KAQb;gCAEI,QAAQ,GAA8B;oCAC3C,qBAAqB,EAAE,IAAI;oCAC3B,WAAW,aAAA;oCACX,gBAAgB,EAAE,cAAc;oCAChC,YAAY,EAAE,CAAC,CAAC,GAAG,CAAC,aAAa;oCACjC,OAAO,EAAE,SAAS,CAAC,MAAM;oCACzB,QAAQ,EAAE,IAAA,6DAA2B,EAAC,SAAS,CAAC,QAAQ,CAAC;iCACzD,CAAC;gCAEF,sBAAO,QAAQ,EAAC;;;;aAChB;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"publications.js","sourcesContent":["import { ResolveIOServer } from '../resolveio-server-app';\nimport { SubscriptionManager } from '../managers/subscription.manager';\nimport { SubscriptionPubModel } from '../models/subscription.model';\nimport { serializeDependencySnapshot, withDependencyTracking } from '../util/subscription-dependency-context';\n\ninterface PublicationWorkerResponse {\n\t__publicationResponse: true;\n\tpublication: string;\n\tsubscriptionData: any[];\n\tuserSpecific: boolean;\n\tpayload: any;\n\tsnapshot: ReturnType<typeof serializeDependencySnapshot>;\n}\n\nfunction normalizeSubscriptionData(subscriptionData: any[]): any[] {\n\tif (!Array.isArray(subscriptionData)) {\n\t\treturn [];\n\t}\n\n\treturn subscriptionData;\n}\n\nfunction resolvePublicationContext(manager: SubscriptionManager) {\n\treturn Object.assign({}, manager, SubscriptionManager.prototype);\n}\n\nfunction getPublication(manager: SubscriptionManager, publication: string): SubscriptionPubModel {\n\tif (!manager || typeof manager.getPublication !== 'function') {\n\t\tthrow new Error(`Subscription manager not available for publication: ${publication}`);\n\t}\n\n\tconst pub = manager.getPublication(publication);\n\tif (!pub) {\n\t\tthrow new Error(`Publication not found: ${publication}`);\n\t}\n\n\treturn pub;\n}\n\nexport function loadPublicationMethods(methodManager) {\n\tmethodManager.methods({\n\t\trunPublication: {\n\t\t\tskipValidation: true,\n\t\t\tworkerTaskWeight: parseInt(process.env.SUBSCRIPTION_WORKER_TASK_WEIGHT || '', 10) || 1,\n\t\t\tmaxConcurrency: parseInt(process.env.SUBSCRIPTION_WORKER_MAX_CONCURRENCY || '', 10) || undefined,\n\t\t\tmaxConcurrencyPerInstance: parseInt(process.env.SUBSCRIPTION_WORKER_MAX_CONCURRENCY_PER_INSTANCE || '', 10) || undefined,\n\t\t\tfunction: async function(publication: string, subscriptionData: any[] = [], userId?: string) {\n\t\t\t\tif (this.user && this.user !== 'Internal System') {\n\t\t\t\t\tthrow new Error('Unauthorized publication execution');\n\t\t\t\t}\n\n\t\t\t\tconst manager = ResolveIOServer.getMainServer().getSubscriptionManager();\n\t\t\t\tconst pub = getPublication(manager, publication);\n\t\t\t\tconst normalizedData = normalizeSubscriptionData(subscriptionData);\n\t\t\t\tconst context = resolvePublicationContext(manager);\n\n\t\t\t\tif (pub.check && pub.check._schema && (normalizedData.length > 1 || normalizedData[0])) {\n\t\t\t\t\tconst valObj = {};\n\t\t\t\t\tconst valKeys = Object.keys(pub.check._schema);\n\t\t\t\t\tconst rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\tfor (let i = 0; i < normalizedData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = normalizedData[i];\n\t\t\t\t\t}\n\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t}\n\n\t\t\t\tconst metadata = {\n\t\t\t\t\tpublication,\n\t\t\t\t\tsubscriptionData: normalizedData\n\t\t\t\t};\n\n\t\t\t\tconst execution = pub.user_specific\n\t\t\t\t\t? await withDependencyTracking(\n\t\t\t\t\t\t() => pub.function.call(context, userId || '', ...normalizedData),\n\t\t\t\t\t\tObject.assign({}, metadata, { userId })\n\t\t\t\t\t)\n\t\t\t\t\t: await withDependencyTracking(\n\t\t\t\t\t\t() => pub.function.call(context, ...normalizedData),\n\t\t\t\t\t\tmetadata\n\t\t\t\t\t);\n\n\t\t\t\tconst response: PublicationWorkerResponse = {\n\t\t\t\t\t__publicationResponse: true,\n\t\t\t\t\tpublication,\n\t\t\t\t\tsubscriptionData: normalizedData,\n\t\t\t\t\tuserSpecific: !!pub.user_specific,\n\t\t\t\t\tpayload: execution.result,\n\t\t\t\t\tsnapshot: serializeDependencySnapshot(execution.snapshot)\n\t\t\t\t};\n\n\t\t\t\treturn response;\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
package/methods.ts CHANGED
@@ -195,6 +195,9 @@ export function SERVER_METHODS(resolveioServer) {
195
195
  resetUserPassword: (userId: string, cb?: Function): Promise<any> => {
196
196
  return resolveioServer.call('resetUserPassword', userId, cb);
197
197
  },
198
+ runPublication: (publication: string, subscriptionData: any[] = [], userId?: string, cb?: Function): Promise<any> => {
199
+ return resolveioServer.call('runPublication', publication, subscriptionData, userId, cb);
200
+ },
198
201
  saveUserStickySelects: (stickySelects: any[], id_user?: string, cb?: Function): Promise<any> => {
199
202
  return resolveioServer.call('saveUserStickySelects', stickySelects, id_user, cb);
200
203
  },
@@ -27,5 +27,6 @@ export interface TaskResponse extends Task {
27
27
  result: any;
28
28
  packedResult?: Uint8Array | Buffer;
29
29
  encoding?: 'msgpack' | 'json';
30
+ meta?: any;
30
31
  }
31
32
  export {};
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/server-message.model.ts"],"names":[],"mappings":"","file":"server-message.model.js","sourcesContent":["export interface ServerResponseModel {\n\tmessageId: number;\n\thasError: boolean;\n\tdata: any;\n}\n\ninterface Task {\n\ttaskId: string;\n\tmessageId: number;\n}\n\nexport interface TaskQueueItem extends Task {\n\tmethod: string;\n\tparams: any[];\n\tuserContext: { id_user?: string; user?: string; id_ws?: string };\n\tqueuedAt?: number;\n\tdispatchedAt?: number;\n}\n\nexport interface TaskPayload extends TaskQueueItem {\n type: 'task';\n}\n\nexport interface TaskResponse extends Task {\n\ttype: 'taskComplete';\n\terror: boolean;\n\tresult: any;\n\tpackedResult?: Uint8Array | Buffer;\n\tencoding?: 'msgpack' | 'json';\n}\n"]}
1
+ {"version":3,"sources":["../../src/models/server-message.model.ts"],"names":[],"mappings":"","file":"server-message.model.js","sourcesContent":["export interface ServerResponseModel {\n\tmessageId: number;\n\thasError: boolean;\n\tdata: any;\n}\n\ninterface Task {\n\ttaskId: string;\n\tmessageId: number;\n}\n\nexport interface TaskQueueItem extends Task {\n\tmethod: string;\n\tparams: any[];\n\tuserContext: { id_user?: string; user?: string; id_ws?: string };\n\tqueuedAt?: number;\n\tdispatchedAt?: number;\n}\n\nexport interface TaskPayload extends TaskQueueItem {\n type: 'task';\n}\n\nexport interface TaskResponse extends Task {\n\ttype: 'taskComplete';\n\terror: boolean;\n\tresult: any;\n\tpackedResult?: Uint8Array | Buffer;\n\tencoding?: 'msgpack' | 'json';\n\tmeta?: any;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.14.20",
3
+ "version": "20.14.23",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
package/server-app.js CHANGED
@@ -356,6 +356,7 @@ var ResolveIOMainServer = /** @class */ (function () {
356
356
  if (this._isWorkerInstance) {
357
357
  console.log('Running as a Worker instance', process.env.NODE_APP_INSTANCE);
358
358
  this._methodManager = method_manager_1.MethodManager.create(null, this._monitorManagerFunction, this._isWorkersEnabled, this._isWorkerInstance);
359
+ this._subscriptionManager = subscription_manager_1.SubscriptionManager.createPublicationRegistry(resolveio_server_app_1.ResolveIOServer.getServerConfig());
359
360
  this._workerServerManager = worker_server_manager_1.WorkerServerManager.create(this._methodManager, this.getServerConfig());
360
361
  if (process.env.WORKER_INDEX === '0') {
361
362
  this._cronManager = cron_manager_1.CronManager.create();