@nocobase/server 2.0.0-alpha.50 → 2.0.0-alpha.52

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.
@@ -53,6 +53,7 @@ var import_start = __toESM(require("./start"));
53
53
  var import_stop = __toESM(require("./stop"));
54
54
  var import_upgrade = __toESM(require("./upgrade"));
55
55
  var import_console = __toESM(require("./console"));
56
+ var import_repair = __toESM(require("./repair"));
56
57
  /* istanbul ignore file -- @preserve */
57
58
  function registerCli(app) {
58
59
  (0, import_console.default)(app);
@@ -68,6 +69,7 @@ function registerCli(app) {
68
69
  (0, import_destroy.default)(app);
69
70
  (0, import_start.default)(app);
70
71
  (0, import_refresh.default)(app);
72
+ (0, import_repair.default)(app);
71
73
  app.command("build").argument("[packages...]");
72
74
  app.command("clean");
73
75
  app.command("dev").usage("[options]").option("-p, --port [port]").option("--client").option("--server");
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import Application from '../application';
10
+ declare const _default: (app: Application) => void;
11
+ export default _default;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var repair_exports = {};
29
+ __export(repair_exports, {
30
+ default: () => repair_default
31
+ });
32
+ module.exports = __toCommonJS(repair_exports);
33
+ var repair_default = /* @__PURE__ */ __name((app) => {
34
+ app.command("repair").auth().preload().action(async (options) => {
35
+ app.log.info("start repair data...");
36
+ const Collection = app.db.getCollection("collections");
37
+ if (Collection) {
38
+ await Collection.repository.setApp(app);
39
+ await Collection.repository.load();
40
+ }
41
+ await app.emitAsync("repair", options);
42
+ });
43
+ }, "default");
@@ -23,6 +23,12 @@ export type QueueEventOptions = {
23
23
  */
24
24
  interval?: number;
25
25
  concurrency?: number;
26
+ /**
27
+ * Shared across multiple applications.
28
+ * Will not use app prefix for channel name.
29
+ * @experimental
30
+ */
31
+ shared?: boolean;
26
32
  idle(): boolean;
27
33
  process: QueueCallback;
28
34
  };
@@ -84,7 +90,7 @@ export declare class EventQueue {
84
90
  protected events: Map<string, QueueEventOptions>;
85
91
  get channelPrefix(): string;
86
92
  constructor(app: Application, options?: EventQueueOptions);
87
- getFullChannel(channel: string): string;
93
+ getFullChannel(channel: string, shared?: boolean): string;
88
94
  setAdapter<A extends IEventQueueAdapter>(adapter: A): void;
89
95
  isConnected(): boolean;
90
96
  connect(): Promise<void>;
@@ -270,16 +270,14 @@ const _EventQueue = class _EventQueue {
270
270
  constructor(app, options = {}) {
271
271
  this.app = app;
272
272
  this.options = options;
273
- if (app.serving()) {
274
- this.setAdapter(new MemoryEventQueueAdapter({ appName: this.app.name, logger: this.app.logger }));
275
- app.on("afterStart", async () => {
276
- await this.connect();
277
- });
278
- app.on("beforeStop", async () => {
279
- app.logger.info("[queue] gracefully shutting down...");
280
- await this.close();
281
- });
282
- }
273
+ this.setAdapter(new MemoryEventQueueAdapter({ appName: this.app.name, logger: this.app.logger }));
274
+ app.on("afterStart", async () => {
275
+ await this.connect();
276
+ });
277
+ app.on("afterStop", async () => {
278
+ app.logger.info("[queue] gracefully shutting down...");
279
+ await this.close();
280
+ });
283
281
  }
284
282
  adapter;
285
283
  events = /* @__PURE__ */ new Map();
@@ -287,7 +285,10 @@ const _EventQueue = class _EventQueue {
287
285
  var _a;
288
286
  return (_a = this.options) == null ? void 0 : _a.channelPrefix;
289
287
  }
290
- getFullChannel(channel) {
288
+ getFullChannel(channel, shared = false) {
289
+ if (shared) {
290
+ return [this.channelPrefix, channel].filter(Boolean).join(".");
291
+ }
291
292
  return [this.app.name, this.channelPrefix, channel].filter(Boolean).join(".");
292
293
  }
293
294
  setAdapter(adapter) {
@@ -300,17 +301,13 @@ const _EventQueue = class _EventQueue {
300
301
  return this.adapter.isConnected();
301
302
  }
302
303
  async connect() {
303
- if (!this.app.serving()) {
304
- this.app.logger.warn("app is not serving, will not connect to event queue");
305
- return;
306
- }
307
304
  if (!this.adapter) {
308
305
  throw new Error("no adapter set, cannot connect");
309
306
  }
310
307
  await this.adapter.connect();
311
308
  this.app.logger.debug(`connected to adapter, using memory? ${this.adapter instanceof MemoryEventQueueAdapter}`);
312
309
  for (const [channel, event] of this.events.entries()) {
313
- this.adapter.subscribe(this.getFullChannel(channel), event);
310
+ this.adapter.subscribe(this.getFullChannel(channel, event.shared), event);
314
311
  }
315
312
  }
316
313
  async close() {
@@ -318,8 +315,8 @@ const _EventQueue = class _EventQueue {
318
315
  return;
319
316
  }
320
317
  await this.adapter.close();
321
- for (const channel of this.events.keys()) {
322
- this.adapter.unsubscribe(this.getFullChannel(channel));
318
+ for (const [channel, event] of this.events.entries()) {
319
+ this.adapter.unsubscribe(this.getFullChannel(channel, event.shared));
323
320
  }
324
321
  }
325
322
  subscribe(channel, options) {
@@ -329,30 +326,31 @@ const _EventQueue = class _EventQueue {
329
326
  }
330
327
  this.events.set(channel, options);
331
328
  if (this.isConnected()) {
332
- this.adapter.subscribe(this.getFullChannel(channel), options);
329
+ this.adapter.subscribe(this.getFullChannel(channel, options.shared), this.events.get(channel));
333
330
  }
334
331
  }
335
332
  unsubscribe(channel) {
333
+ var _a;
336
334
  if (!this.events.has(channel)) {
337
335
  return;
338
336
  }
339
337
  this.events.delete(channel);
340
338
  if (this.isConnected()) {
341
- this.adapter.unsubscribe(this.getFullChannel(channel));
339
+ this.adapter.unsubscribe(this.getFullChannel(channel, (_a = this.events.get(channel)) == null ? void 0 : _a.shared));
342
340
  }
343
341
  }
344
342
  async publish(channel, message, options = {}) {
345
- if (!this.app.serving()) {
346
- this.app.logger.warn("app is not serving, will not publish message to event queue");
347
- return;
348
- }
349
343
  if (!this.adapter) {
350
344
  throw new Error("no adapter set, cannot publish");
351
345
  }
352
346
  if (!this.isConnected()) {
353
347
  throw new Error("event queue not connected, cannot publish");
354
348
  }
355
- const c = this.getFullChannel(channel);
349
+ const event = this.events.get(channel);
350
+ if (!event) {
351
+ throw new Error(`event queue not subscribed on channel "${channel}", cannot publish`);
352
+ }
353
+ const c = this.getFullChannel(channel, event.shared);
356
354
  this.app.logger.debug(`event queue publishing to channel(${c})`, { message });
357
355
  await this.adapter.publish(c, message, {
358
356
  timeout: QUEUE_DEFAULT_ACK_TIMEOUT,
package/lib/helper.d.ts CHANGED
@@ -17,3 +17,362 @@ export declare const getCommandFullName: (command: Command) => string;
17
17
  export declare const tsxRerunning: () => Promise<void>;
18
18
  export declare const enablePerfHooks: (app: Application) => void;
19
19
  export declare function getBodyLimit(): string;
20
+ export declare function createContextVariablesScope(ctx: any): {
21
+ timezone: any;
22
+ now: string;
23
+ getField: (path: any) => any;
24
+ vars: {
25
+ ctx: {
26
+ state: any;
27
+ };
28
+ $system: {
29
+ now: string;
30
+ };
31
+ $date: {
32
+ now: string;
33
+ today: ({ now, timezone, field }: {
34
+ now?: any;
35
+ timezone?: string | number;
36
+ field?: {
37
+ timezone?: string | number;
38
+ };
39
+ }) => any;
40
+ yesterday: ({ now, timezone, field }: {
41
+ now?: any;
42
+ timezone?: string | number;
43
+ field?: {
44
+ timezone?: string | number;
45
+ };
46
+ }) => any;
47
+ tomorrow: ({ now, timezone, field }: {
48
+ now?: any;
49
+ timezone?: string | number;
50
+ field?: {
51
+ timezone?: string | number;
52
+ };
53
+ }) => any;
54
+ thisWeek: ({ now, timezone, field }: {
55
+ now?: any;
56
+ timezone?: string | number;
57
+ field?: {
58
+ timezone?: string | number;
59
+ };
60
+ }) => any;
61
+ lastWeek: ({ now, timezone, field }: {
62
+ now?: any;
63
+ timezone?: string | number;
64
+ field?: {
65
+ timezone?: string | number;
66
+ };
67
+ }) => any;
68
+ nextWeek: ({ now, timezone, field }: {
69
+ now?: any;
70
+ timezone?: string | number;
71
+ field?: {
72
+ timezone?: string | number;
73
+ };
74
+ }) => any;
75
+ thisIsoWeek: ({ now, timezone, field }: {
76
+ now?: any;
77
+ timezone?: string | number;
78
+ field?: {
79
+ timezone?: string | number;
80
+ };
81
+ }) => any;
82
+ lastIsoWeek: ({ now, timezone, field }: {
83
+ now?: any;
84
+ timezone?: string | number;
85
+ field?: {
86
+ timezone?: string | number;
87
+ };
88
+ }) => any;
89
+ nextIsoWeek: ({ now, timezone, field }: {
90
+ now?: any;
91
+ timezone?: string | number;
92
+ field?: {
93
+ timezone?: string | number;
94
+ };
95
+ }) => any;
96
+ thisMonth: ({ now, timezone, field }: {
97
+ now?: any;
98
+ timezone?: string | number;
99
+ field?: {
100
+ timezone?: string | number;
101
+ };
102
+ }) => any;
103
+ lastMonth: ({ now, timezone, field }: {
104
+ now?: any;
105
+ timezone?: string | number;
106
+ field?: {
107
+ timezone?: string | number;
108
+ };
109
+ }) => any;
110
+ nextMonth: ({ now, timezone, field }: {
111
+ now?: any;
112
+ timezone?: string | number;
113
+ field?: {
114
+ timezone?: string | number;
115
+ };
116
+ }) => any;
117
+ thisQuarter: ({ now, timezone, field }: {
118
+ now?: any;
119
+ timezone?: string | number;
120
+ field?: {
121
+ timezone?: string | number;
122
+ };
123
+ }) => any;
124
+ lastQuarter: ({ now, timezone, field }: {
125
+ now?: any;
126
+ timezone?: string | number;
127
+ field?: {
128
+ timezone?: string | number;
129
+ };
130
+ }) => any;
131
+ nextQuarter: ({ now, timezone, field }: {
132
+ now?: any;
133
+ timezone?: string | number;
134
+ field?: {
135
+ timezone?: string | number;
136
+ };
137
+ }) => any;
138
+ thisYear: ({ now, timezone, field }: {
139
+ now?: any;
140
+ timezone?: string | number;
141
+ field?: {
142
+ timezone?: string | number;
143
+ };
144
+ }) => any;
145
+ lastYear: ({ now, timezone, field }: {
146
+ now?: any;
147
+ timezone?: string | number;
148
+ field?: {
149
+ timezone?: string | number;
150
+ };
151
+ }) => any;
152
+ nextYear: ({ now, timezone, field }: {
153
+ now?: any;
154
+ timezone?: string | number;
155
+ field?: {
156
+ timezone?: string | number;
157
+ };
158
+ }) => any;
159
+ last7Days: ({ now, timezone, field }: {
160
+ now?: any;
161
+ timezone?: string | number;
162
+ field?: {
163
+ timezone?: string | number;
164
+ };
165
+ }) => (string | number)[];
166
+ next7Days: ({ now, timezone, field }: {
167
+ now?: any;
168
+ timezone?: string | number;
169
+ field?: {
170
+ timezone?: string | number;
171
+ };
172
+ }) => (string | number)[];
173
+ last30Days: ({ now, timezone, field }: {
174
+ now?: any;
175
+ timezone?: string | number;
176
+ field?: {
177
+ timezone?: string | number;
178
+ };
179
+ }) => (string | number)[];
180
+ next30Days: ({ now, timezone, field }: {
181
+ now?: any;
182
+ timezone?: string | number;
183
+ field?: {
184
+ timezone?: string | number;
185
+ };
186
+ }) => (string | number)[];
187
+ last90Days: ({ now, timezone, field }: {
188
+ now?: any;
189
+ timezone?: string | number;
190
+ field?: {
191
+ timezone?: string | number;
192
+ };
193
+ }) => (string | number)[];
194
+ next90Days: ({ now, timezone, field }: {
195
+ now?: any;
196
+ timezone?: string | number;
197
+ field?: {
198
+ timezone?: string | number;
199
+ };
200
+ }) => (string | number)[];
201
+ };
202
+ $nDate: {
203
+ now: string;
204
+ today: ({ now, timezone, field }: {
205
+ now?: any;
206
+ timezone?: string | number;
207
+ field?: {
208
+ timezone?: string | number;
209
+ };
210
+ }) => any;
211
+ yesterday: ({ now, timezone, field }: {
212
+ now?: any;
213
+ timezone?: string | number;
214
+ field?: {
215
+ timezone?: string | number;
216
+ };
217
+ }) => any;
218
+ tomorrow: ({ now, timezone, field }: {
219
+ now?: any;
220
+ timezone?: string | number;
221
+ field?: {
222
+ timezone?: string | number;
223
+ };
224
+ }) => any;
225
+ thisWeek: ({ now, timezone, field }: {
226
+ now?: any;
227
+ timezone?: string | number;
228
+ field?: {
229
+ timezone?: string | number;
230
+ };
231
+ }) => any;
232
+ lastWeek: ({ now, timezone, field }: {
233
+ now?: any;
234
+ timezone?: string | number;
235
+ field?: {
236
+ timezone?: string | number;
237
+ };
238
+ }) => any;
239
+ nextWeek: ({ now, timezone, field }: {
240
+ now?: any;
241
+ timezone?: string | number;
242
+ field?: {
243
+ timezone?: string | number;
244
+ };
245
+ }) => any;
246
+ thisIsoWeek: ({ now, timezone, field }: {
247
+ now?: any;
248
+ timezone?: string | number;
249
+ field?: {
250
+ timezone?: string | number;
251
+ };
252
+ }) => any;
253
+ lastIsoWeek: ({ now, timezone, field }: {
254
+ now?: any;
255
+ timezone?: string | number;
256
+ field?: {
257
+ timezone?: string | number;
258
+ };
259
+ }) => any;
260
+ nextIsoWeek: ({ now, timezone, field }: {
261
+ now?: any;
262
+ timezone?: string | number;
263
+ field?: {
264
+ timezone?: string | number;
265
+ };
266
+ }) => any;
267
+ thisMonth: ({ now, timezone, field }: {
268
+ now?: any;
269
+ timezone?: string | number;
270
+ field?: {
271
+ timezone?: string | number;
272
+ };
273
+ }) => any;
274
+ lastMonth: ({ now, timezone, field }: {
275
+ now?: any;
276
+ timezone?: string | number;
277
+ field?: {
278
+ timezone?: string | number;
279
+ };
280
+ }) => any;
281
+ nextMonth: ({ now, timezone, field }: {
282
+ now?: any;
283
+ timezone?: string | number;
284
+ field?: {
285
+ timezone?: string | number;
286
+ };
287
+ }) => any;
288
+ thisQuarter: ({ now, timezone, field }: {
289
+ now?: any;
290
+ timezone?: string | number;
291
+ field?: {
292
+ timezone?: string | number;
293
+ };
294
+ }) => any;
295
+ lastQuarter: ({ now, timezone, field }: {
296
+ now?: any;
297
+ timezone?: string | number;
298
+ field?: {
299
+ timezone?: string | number;
300
+ };
301
+ }) => any;
302
+ nextQuarter: ({ now, timezone, field }: {
303
+ now?: any;
304
+ timezone?: string | number;
305
+ field?: {
306
+ timezone?: string | number;
307
+ };
308
+ }) => any;
309
+ thisYear: ({ now, timezone, field }: {
310
+ now?: any;
311
+ timezone?: string | number;
312
+ field?: {
313
+ timezone?: string | number;
314
+ };
315
+ }) => any;
316
+ lastYear: ({ now, timezone, field }: {
317
+ now?: any;
318
+ timezone?: string | number;
319
+ field?: {
320
+ timezone?: string | number;
321
+ };
322
+ }) => any;
323
+ nextYear: ({ now, timezone, field }: {
324
+ now?: any;
325
+ timezone?: string | number;
326
+ field?: {
327
+ timezone?: string | number;
328
+ };
329
+ }) => any;
330
+ last7Days: ({ now, timezone, field }: {
331
+ now?: any;
332
+ timezone?: string | number;
333
+ field?: {
334
+ timezone?: string | number;
335
+ };
336
+ }) => (string | number)[];
337
+ next7Days: ({ now, timezone, field }: {
338
+ now?: any;
339
+ timezone?: string | number;
340
+ field?: {
341
+ timezone?: string | number;
342
+ };
343
+ }) => (string | number)[];
344
+ last30Days: ({ now, timezone, field }: {
345
+ now?: any;
346
+ timezone?: string | number;
347
+ field?: {
348
+ timezone?: string | number;
349
+ };
350
+ }) => (string | number)[];
351
+ next30Days: ({ now, timezone, field }: {
352
+ now?: any;
353
+ timezone?: string | number;
354
+ field?: {
355
+ timezone?: string | number;
356
+ };
357
+ }) => (string | number)[];
358
+ last90Days: ({ now, timezone, field }: {
359
+ now?: any;
360
+ timezone?: string | number;
361
+ field?: {
362
+ timezone?: string | number;
363
+ };
364
+ }) => (string | number)[];
365
+ next90Days: ({ now, timezone, field }: {
366
+ now?: any;
367
+ timezone?: string | number;
368
+ field?: {
369
+ timezone?: string | number;
370
+ };
371
+ }) => (string | number)[];
372
+ };
373
+ $user: ({ fields }: {
374
+ fields: any;
375
+ }) => Promise<any>;
376
+ $nRole: any;
377
+ };
378
+ };
package/lib/helper.js CHANGED
@@ -38,6 +38,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
38
38
  var helper_exports = {};
39
39
  __export(helper_exports, {
40
40
  createAppProxy: () => createAppProxy,
41
+ createContextVariablesScope: () => createContextVariablesScope,
41
42
  createI18n: () => createI18n,
42
43
  createResourcer: () => createResourcer,
43
44
  enablePerfHooks: () => enablePerfHooks,
@@ -193,9 +194,66 @@ function getBodyLimit() {
193
194
  return process.env.REQUEST_BODY_LIMIT || "10mb";
194
195
  }
195
196
  __name(getBodyLimit, "getBodyLimit");
197
+ function getUser(ctx) {
198
+ return async ({ fields }) => {
199
+ var _a, _b;
200
+ const userFields = fields.filter((f) => f && ctx.db.getFieldByPath("users." + f));
201
+ (_a = ctx.logger) == null ? void 0 : _a.info("filter-parse: ", { userFields });
202
+ if (!ctx.state.currentUser) {
203
+ return;
204
+ }
205
+ if (!userFields.length) {
206
+ return;
207
+ }
208
+ const user = await ctx.db.getRepository("users").findOne({
209
+ filterByTk: ctx.state.currentUser.id,
210
+ fields: userFields
211
+ });
212
+ (_b = ctx.logger) == null ? void 0 : _b.info("filter-parse: ", {
213
+ $user: user == null ? void 0 : user.toJSON()
214
+ });
215
+ return user;
216
+ };
217
+ }
218
+ __name(getUser, "getUser");
219
+ function isNumeric(str) {
220
+ if (typeof str === "number") return true;
221
+ if (typeof str != "string") return false;
222
+ return !isNaN(str) && !isNaN(parseFloat(str));
223
+ }
224
+ __name(isNumeric, "isNumeric");
225
+ function createContextVariablesScope(ctx) {
226
+ const state = JSON.parse(JSON.stringify(ctx.state));
227
+ return {
228
+ timezone: ctx.get("x-timezone"),
229
+ now: (/* @__PURE__ */ new Date()).toISOString(),
230
+ getField: /* @__PURE__ */ __name((path) => {
231
+ const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
232
+ const { resourceName } = ctx.action;
233
+ return ctx.db.getFieldByPath(`${resourceName}.${fieldPath}`);
234
+ }, "getField"),
235
+ vars: {
236
+ ctx: {
237
+ state
238
+ },
239
+ // @deprecated
240
+ $system: {
241
+ now: (/* @__PURE__ */ new Date()).toISOString()
242
+ },
243
+ // @deprecated
244
+ $date: (0, import_utils.getDateVars)(),
245
+ // 新的命名方式,防止和 formily 内置变量冲突
246
+ $nDate: (0, import_utils.getDateVars)(),
247
+ $user: getUser(ctx),
248
+ $nRole: ctx.state.currentRole === "__union__" ? ctx.state.currentRoles : ctx.state.currentRole
249
+ }
250
+ };
251
+ }
252
+ __name(createContextVariablesScope, "createContextVariablesScope");
196
253
  // Annotate the CommonJS export names for ESM import in node:
197
254
  0 && (module.exports = {
198
255
  createAppProxy,
256
+ createContextVariablesScope,
199
257
  createI18n,
200
258
  createResourcer,
201
259
  enablePerfHooks,
package/lib/index.d.ts CHANGED
@@ -25,3 +25,4 @@ export * from './main-data-source';
25
25
  export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
26
26
  export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
27
27
  export { runPluginStaticImports } from './run-plugin-static-imports';
28
+ export { createContextVariablesScope } from './helper';
package/lib/index.js CHANGED
@@ -39,6 +39,7 @@ var src_exports = {};
39
39
  __export(src_exports, {
40
40
  OFFICIAL_PLUGIN_PREFIX: () => OFFICIAL_PLUGIN_PREFIX,
41
41
  appendToBuiltInPlugins: () => import_findPackageNames.appendToBuiltInPlugins,
42
+ createContextVariablesScope: () => import_helper.createContextVariablesScope,
42
43
  default: () => import_application.Application,
43
44
  findAllPlugins: () => import_findPackageNames.findAllPlugins,
44
45
  findBuiltInPlugins: () => import_findPackageNames.findBuiltInPlugins,
@@ -66,11 +67,13 @@ __reExport(src_exports, require("./redis-connection-manager"), module.exports);
66
67
  __reExport(src_exports, require("./main-data-source"), module.exports);
67
68
  var import_findPackageNames = require("./plugin-manager/findPackageNames");
68
69
  var import_run_plugin_static_imports = require("./run-plugin-static-imports");
70
+ var import_helper = require("./helper");
69
71
  const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
70
72
  // Annotate the CommonJS export names for ESM import in node:
71
73
  0 && (module.exports = {
72
74
  OFFICIAL_PLUGIN_PREFIX,
73
75
  appendToBuiltInPlugins,
76
+ createContextVariablesScope,
74
77
  findAllPlugins,
75
78
  findBuiltInPlugins,
76
79
  findLocalPlugins,
@@ -31,64 +31,13 @@ __export(parse_variables_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(parse_variables_exports);
33
33
  var import_utils = require("@nocobase/utils");
34
- function getUser(ctx) {
35
- return async ({ fields }) => {
36
- var _a, _b;
37
- const userFields = fields.filter((f) => f && ctx.db.getFieldByPath("users." + f));
38
- (_a = ctx.logger) == null ? void 0 : _a.info("filter-parse: ", { userFields });
39
- if (!ctx.state.currentUser) {
40
- return;
41
- }
42
- if (!userFields.length) {
43
- return;
44
- }
45
- const user = await ctx.db.getRepository("users").findOne({
46
- filterByTk: ctx.state.currentUser.id,
47
- fields: userFields
48
- });
49
- (_b = ctx.logger) == null ? void 0 : _b.info("filter-parse: ", {
50
- $user: user == null ? void 0 : user.toJSON()
51
- });
52
- return user;
53
- };
54
- }
55
- __name(getUser, "getUser");
56
- function isNumeric(str) {
57
- if (typeof str === "number") return true;
58
- if (typeof str != "string") return false;
59
- return !isNaN(str) && !isNaN(parseFloat(str));
60
- }
61
- __name(isNumeric, "isNumeric");
34
+ var import_helper = require("../helper");
62
35
  async function parseVariables(ctx, next) {
63
36
  const filter = ctx.action.params.filter;
64
37
  if (!filter) {
65
38
  return next();
66
39
  }
67
- const state = JSON.parse(JSON.stringify(ctx.state));
68
- ctx.action.params.filter = await (0, import_utils.parseFilter)(filter, {
69
- timezone: ctx.get("x-timezone"),
70
- now: (/* @__PURE__ */ new Date()).toISOString(),
71
- getField: /* @__PURE__ */ __name((path) => {
72
- const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
73
- const { resourceName } = ctx.action;
74
- return ctx.db.getFieldByPath(`${resourceName}.${fieldPath}`);
75
- }, "getField"),
76
- vars: {
77
- ctx: {
78
- state
79
- },
80
- // @deprecated
81
- $system: {
82
- now: (/* @__PURE__ */ new Date()).toISOString()
83
- },
84
- // @deprecated
85
- $date: (0, import_utils.getDateVars)(),
86
- // 新的命名方式,防止和 formily 内置变量冲突
87
- $nDate: (0, import_utils.getDateVars)(),
88
- $user: getUser(ctx),
89
- $nRole: ctx.state.currentRole === "__union__" ? ctx.state.currentRoles : ctx.state.currentRole
90
- }
91
- });
40
+ ctx.action.params.filter = await (0, import_utils.parseFilter)(filter, (0, import_helper.createContextVariablesScope)(ctx));
92
41
  await next();
93
42
  }
94
43
  __name(parseVariables, "parseVariables");
@@ -35,14 +35,12 @@ var import_utils = require("@nocobase/utils");
35
35
  var import_handler_manager = require("./handler-manager");
36
36
  const createPubSubManager = /* @__PURE__ */ __name((app, options) => {
37
37
  const pubSubManager = new PubSubManager(app, options);
38
- if (app.serving()) {
39
- app.on("afterStart", async () => {
40
- await pubSubManager.connect();
41
- });
42
- app.on("afterStop", async () => {
43
- await pubSubManager.close();
44
- });
45
- }
38
+ app.on("afterStart", async () => {
39
+ await pubSubManager.connect();
40
+ });
41
+ app.on("afterStop", async () => {
42
+ await pubSubManager.close();
43
+ });
46
44
  return pubSubManager;
47
45
  }, "createPubSubManager");
48
46
  const _PubSubManager = class _PubSubManager {
@@ -72,10 +70,6 @@ const _PubSubManager = class _PubSubManager {
72
70
  if (!this.adapter) {
73
71
  return;
74
72
  }
75
- if (!this.app.serving()) {
76
- this.app.logger.warn("app is not serving, will not connect to event queue");
77
- return;
78
- }
79
73
  await this.adapter.connect();
80
74
  await this.handlerManager.each(async (channel, headler) => {
81
75
  this.app.logger.debug(`[PubSubManager] subscribe ${channel} added before connected`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.0.0-alpha.50",
3
+ "version": "2.0.0-alpha.52",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -10,20 +10,20 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.0.0-alpha.50",
14
- "@nocobase/actions": "2.0.0-alpha.50",
15
- "@nocobase/auth": "2.0.0-alpha.50",
16
- "@nocobase/cache": "2.0.0-alpha.50",
17
- "@nocobase/data-source-manager": "2.0.0-alpha.50",
18
- "@nocobase/database": "2.0.0-alpha.50",
19
- "@nocobase/evaluators": "2.0.0-alpha.50",
20
- "@nocobase/lock-manager": "2.0.0-alpha.50",
21
- "@nocobase/logger": "2.0.0-alpha.50",
22
- "@nocobase/resourcer": "2.0.0-alpha.50",
23
- "@nocobase/sdk": "2.0.0-alpha.50",
24
- "@nocobase/snowflake-id": "2.0.0-alpha.50",
25
- "@nocobase/telemetry": "2.0.0-alpha.50",
26
- "@nocobase/utils": "2.0.0-alpha.50",
13
+ "@nocobase/acl": "2.0.0-alpha.52",
14
+ "@nocobase/actions": "2.0.0-alpha.52",
15
+ "@nocobase/auth": "2.0.0-alpha.52",
16
+ "@nocobase/cache": "2.0.0-alpha.52",
17
+ "@nocobase/data-source-manager": "2.0.0-alpha.52",
18
+ "@nocobase/database": "2.0.0-alpha.52",
19
+ "@nocobase/evaluators": "2.0.0-alpha.52",
20
+ "@nocobase/lock-manager": "2.0.0-alpha.52",
21
+ "@nocobase/logger": "2.0.0-alpha.52",
22
+ "@nocobase/resourcer": "2.0.0-alpha.52",
23
+ "@nocobase/sdk": "2.0.0-alpha.52",
24
+ "@nocobase/snowflake-id": "2.0.0-alpha.52",
25
+ "@nocobase/telemetry": "2.0.0-alpha.52",
26
+ "@nocobase/utils": "2.0.0-alpha.52",
27
27
  "@types/decompress": "4.2.7",
28
28
  "@types/ini": "^1.3.31",
29
29
  "@types/koa-send": "^4.1.3",
@@ -60,5 +60,5 @@
60
60
  "@types/serve-handler": "^6.1.1",
61
61
  "@types/ws": "^8.5.5"
62
62
  },
63
- "gitHead": "a6eb64abf3632e116ad0b295a7f410270a1059d1"
63
+ "gitHead": "b32992d8baeb4ca6616d839ca2f9c023d49476a9"
64
64
  }