@tachybase/utils 0.23.8

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.
Files changed (116) hide show
  1. package/.turbo/turbo-build.log +9 -0
  2. package/LICENSE +201 -0
  3. package/lib/assign.d.ts +9 -0
  4. package/lib/assign.js +136 -0
  5. package/lib/client.d.ts +21 -0
  6. package/lib/client.js +77 -0
  7. package/lib/cluster.d.ts +2 -0
  8. package/lib/cluster.js +39 -0
  9. package/lib/collections-graph.d.ts +16 -0
  10. package/lib/collections-graph.js +98 -0
  11. package/lib/common.d.ts +7 -0
  12. package/lib/common.js +98 -0
  13. package/lib/currencyUtils.d.ts +44 -0
  14. package/lib/currencyUtils.js +75 -0
  15. package/lib/date.d.ts +22 -0
  16. package/lib/date.js +186 -0
  17. package/lib/dayjs.d.ts +10 -0
  18. package/lib/dayjs.js +73 -0
  19. package/lib/decorators.d.ts +16 -0
  20. package/lib/decorators.js +94 -0
  21. package/lib/dom.d.ts +4 -0
  22. package/lib/dom.js +52 -0
  23. package/lib/forEach.d.ts +1 -0
  24. package/lib/forEach.js +36 -0
  25. package/lib/fs-exists.d.ts +1 -0
  26. package/lib/fs-exists.js +37 -0
  27. package/lib/getCurrentStacks.d.ts +1 -0
  28. package/lib/getCurrentStacks.js +35 -0
  29. package/lib/getValuesByPath.d.ts +1 -0
  30. package/lib/getValuesByPath.js +62 -0
  31. package/lib/index.d.ts +31 -0
  32. package/lib/index.js +97 -0
  33. package/lib/isPortalInBody.d.ts +5 -0
  34. package/lib/isPortalInBody.js +45 -0
  35. package/lib/json-templates.d.ts +1 -0
  36. package/lib/json-templates.js +145 -0
  37. package/lib/koa-multer.d.ts +6 -0
  38. package/lib/koa-multer.js +83 -0
  39. package/lib/log.d.ts +1 -0
  40. package/lib/log.js +30 -0
  41. package/lib/measure-execution-time.d.ts +1 -0
  42. package/lib/measure-execution-time.js +35 -0
  43. package/lib/merge.d.ts +1 -0
  44. package/lib/merge.js +46 -0
  45. package/lib/mixin/AsyncEmitter.d.ts +3 -0
  46. package/lib/mixin/AsyncEmitter.js +73 -0
  47. package/lib/mixin/index.d.ts +1 -0
  48. package/lib/mixin/index.js +39 -0
  49. package/lib/notification.d.ts +1 -0
  50. package/lib/notification.js +34 -0
  51. package/lib/number.d.ts +1 -0
  52. package/lib/number.js +36 -0
  53. package/lib/parse-date.d.ts +3 -0
  54. package/lib/parse-date.js +237 -0
  55. package/lib/parse-filter.d.ts +146 -0
  56. package/lib/parse-filter.js +305 -0
  57. package/lib/parseHTML.d.ts +7 -0
  58. package/lib/parseHTML.js +33 -0
  59. package/lib/perf-hooks.d.ts +6 -0
  60. package/lib/perf-hooks.js +60 -0
  61. package/lib/plugin-symlink.d.ts +4 -0
  62. package/lib/plugin-symlink.js +131 -0
  63. package/lib/registry.d.ts +14 -0
  64. package/lib/registry.js +60 -0
  65. package/lib/requireModule.d.ts +3 -0
  66. package/lib/requireModule.js +64 -0
  67. package/lib/toposort.d.ts +13 -0
  68. package/lib/toposort.js +90 -0
  69. package/lib/typedi/container-instance.class.d.ts +109 -0
  70. package/lib/typedi/container-instance.class.js +349 -0
  71. package/lib/typedi/container-registry.class.d.ts +51 -0
  72. package/lib/typedi/container-registry.class.js +97 -0
  73. package/lib/typedi/decorators/inject-many.decorator.d.ts +8 -0
  74. package/lib/typedi/decorators/inject-many.decorator.js +56 -0
  75. package/lib/typedi/decorators/inject.decorator.d.ts +9 -0
  76. package/lib/typedi/decorators/inject.decorator.js +56 -0
  77. package/lib/typedi/decorators/service.decorator.d.ts +6 -0
  78. package/lib/typedi/decorators/service.decorator.js +49 -0
  79. package/lib/typedi/empty.const.d.ts +6 -0
  80. package/lib/typedi/empty.const.js +27 -0
  81. package/lib/typedi/error/cannot-inject-value.error.d.ts +11 -0
  82. package/lib/typedi/error/cannot-inject-value.error.js +40 -0
  83. package/lib/typedi/error/cannot-instantiate-value.error.d.ts +11 -0
  84. package/lib/typedi/error/cannot-instantiate-value.error.js +49 -0
  85. package/lib/typedi/error/service-not-found.error.d.ts +11 -0
  86. package/lib/typedi/error/service-not-found.error.js +49 -0
  87. package/lib/typedi/index.d.ts +17 -0
  88. package/lib/typedi/index.js +64 -0
  89. package/lib/typedi/interfaces/container-options.interface.d.ts +45 -0
  90. package/lib/typedi/interfaces/container-options.interface.js +15 -0
  91. package/lib/typedi/interfaces/handler.interface.d.ts +27 -0
  92. package/lib/typedi/interfaces/handler.interface.js +15 -0
  93. package/lib/typedi/interfaces/service-metadata.interface.d.ts +53 -0
  94. package/lib/typedi/interfaces/service-metadata.interface.js +15 -0
  95. package/lib/typedi/interfaces/service-options.interface.d.ts +6 -0
  96. package/lib/typedi/interfaces/service-options.interface.js +15 -0
  97. package/lib/typedi/token.class.d.ts +11 -0
  98. package/lib/typedi/token.class.js +37 -0
  99. package/lib/typedi/types/abstract-constructable.type.d.ts +9 -0
  100. package/lib/typedi/types/abstract-constructable.type.js +15 -0
  101. package/lib/typedi/types/constructable.type.d.ts +10 -0
  102. package/lib/typedi/types/constructable.type.js +15 -0
  103. package/lib/typedi/types/container-identifier.type.d.ts +4 -0
  104. package/lib/typedi/types/container-identifier.type.js +15 -0
  105. package/lib/typedi/types/container-scope.type.d.ts +1 -0
  106. package/lib/typedi/types/container-scope.type.js +15 -0
  107. package/lib/typedi/types/service-identifier.type.d.ts +8 -0
  108. package/lib/typedi/types/service-identifier.type.js +15 -0
  109. package/lib/typedi/utils/resolve-to-type-wrapper.util.d.ts +15 -0
  110. package/lib/typedi/utils/resolve-to-type-wrapper.util.js +39 -0
  111. package/lib/uid.d.ts +1 -0
  112. package/lib/uid.js +35 -0
  113. package/lib/url.d.ts +1 -0
  114. package/lib/url.js +37 -0
  115. package/package.json +49 -0
  116. package/tsconfig.json +31 -0
@@ -0,0 +1,305 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var parse_filter_exports = {};
30
+ __export(parse_filter_exports, {
31
+ flatten: () => flatten,
32
+ getDateVars: () => getDateVars,
33
+ getDayRange: () => getDayRange,
34
+ parseFilter: () => parseFilter,
35
+ splitPathToTwoParts: () => splitPathToTwoParts,
36
+ unflatten: () => unflatten,
37
+ utc2unit: () => utc2unit
38
+ });
39
+ module.exports = __toCommonJS(parse_filter_exports);
40
+ var import_lodash = __toESM(require("lodash"));
41
+ var import_set = __toESM(require("lodash/set"));
42
+ var import_date = require("./date");
43
+ var import_dayjs = require("./dayjs");
44
+ var import_getValuesByPath = require("./getValuesByPath");
45
+ const re = /^\s*\{\{([\s\S]*)\}\}\s*$/;
46
+ function isBuffer(obj) {
47
+ return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
48
+ }
49
+ __name(isBuffer, "isBuffer");
50
+ function keyIdentity(key) {
51
+ return key;
52
+ }
53
+ __name(keyIdentity, "keyIdentity");
54
+ function flatten(target, opts) {
55
+ opts = opts || {};
56
+ const delimiter = opts.delimiter || ".";
57
+ const maxDepth = opts.maxDepth;
58
+ const transformKey = opts.transformKey || keyIdentity;
59
+ const transformValue = opts.transformValue || keyIdentity;
60
+ const output = {};
61
+ function step(object, prev, currentDepth) {
62
+ currentDepth = currentDepth || 1;
63
+ if (import_lodash.default.isObjectLike(object)) {
64
+ Object.keys(object).forEach(function(key) {
65
+ var _a;
66
+ const value = object[key];
67
+ const isarray = opts.safe && Array.isArray(value);
68
+ const type = Object.prototype.toString.call(value);
69
+ const isbuffer = isBuffer(value);
70
+ const isobject = type === "[object Object]" || type === "[object Array]";
71
+ const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
72
+ if ((_a = opts.breakOn) == null ? void 0 : _a.call(opts, { key, value, path: newKey })) {
73
+ output[newKey] = transformValue(value, newKey);
74
+ return;
75
+ }
76
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
77
+ return step(value, newKey, currentDepth + 1);
78
+ }
79
+ output[newKey] = transformValue(value, newKey);
80
+ });
81
+ }
82
+ }
83
+ __name(step, "step");
84
+ step(target);
85
+ return output;
86
+ }
87
+ __name(flatten, "flatten");
88
+ function unflatten(obj, opts = {}) {
89
+ const parsed = {};
90
+ const transformValue = opts.transformValue || keyIdentity;
91
+ for (const key of Object.keys(obj)) {
92
+ (0, import_set.default)(parsed, key, transformValue(obj[key], key));
93
+ }
94
+ return parsed;
95
+ }
96
+ __name(unflatten, "unflatten");
97
+ const parsePath = /* @__PURE__ */ __name((path) => {
98
+ let operator = path.split(".").pop() || "";
99
+ if (!operator.startsWith("$")) {
100
+ operator = "";
101
+ }
102
+ return { operator };
103
+ }, "parsePath");
104
+ const isDateOperator = /* @__PURE__ */ __name((op) => {
105
+ return [
106
+ "$dateOn",
107
+ "$dateNotOn",
108
+ "$dateBefore",
109
+ "$dateAfter",
110
+ "$dateNotBefore",
111
+ "$dateNotAfter",
112
+ "$dateBetween"
113
+ ].includes(op);
114
+ }, "isDateOperator");
115
+ function isDate(input) {
116
+ return input instanceof Date || Object.prototype.toString.call(input) === "[object Date]";
117
+ }
118
+ __name(isDate, "isDate");
119
+ const dateValueWrapper = /* @__PURE__ */ __name((value, timezone) => {
120
+ if (!value) {
121
+ return null;
122
+ }
123
+ if (Array.isArray(value)) {
124
+ if (value.length === 2) {
125
+ value.push("[]", timezone);
126
+ } else if (value.length === 3) {
127
+ value.push(timezone);
128
+ }
129
+ return value;
130
+ }
131
+ if (typeof value === "string") {
132
+ if (!timezone || /(\+|-)\d\d:\d\d$/.test(value)) {
133
+ return value;
134
+ }
135
+ return value + timezone;
136
+ }
137
+ if (isDate(value)) {
138
+ return value.toISOString();
139
+ }
140
+ }, "dateValueWrapper");
141
+ const parseFilter = /* @__PURE__ */ __name(async (filter, opts = {}) => {
142
+ const userFieldsSet = /* @__PURE__ */ new Set();
143
+ const vars = opts.vars || {};
144
+ const timezone = opts.timezone;
145
+ const now = opts.now;
146
+ const getField = opts.getField;
147
+ const flat = flatten(filter, {
148
+ breakOn({ key }) {
149
+ return key.startsWith("$") && key !== "$and" && key !== "$or";
150
+ },
151
+ transformValue(value) {
152
+ if (typeof value !== "string") {
153
+ return value;
154
+ }
155
+ const match = re.exec(value);
156
+ if (match) {
157
+ const key = match[1].trim();
158
+ if (key.startsWith("$user")) {
159
+ userFieldsSet.add(key.substring(6));
160
+ }
161
+ }
162
+ return value;
163
+ }
164
+ });
165
+ if (userFieldsSet.size > 0) {
166
+ const $user = await vars.$user({ fields: [...userFieldsSet.values()] });
167
+ Object.assign(vars, { $user });
168
+ }
169
+ return unflatten(flat, {
170
+ transformValue(value, path) {
171
+ const { operator } = parsePath(path);
172
+ if (typeof value === "string") {
173
+ const match = re.exec(value);
174
+ if (match) {
175
+ const key = match[1].trim();
176
+ const val = (0, import_getValuesByPath.getValuesByPath)(vars, key, null);
177
+ const field = getField == null ? void 0 : getField(path);
178
+ value = typeof val === "function" ? val == null ? void 0 : val({ field, operator, timezone, now }) : val;
179
+ }
180
+ }
181
+ if (isDateOperator(operator)) {
182
+ const field = getField == null ? void 0 : getField(path);
183
+ return dateValueWrapper(value, (field == null ? void 0 : field.timezone) || timezone);
184
+ }
185
+ return value;
186
+ }
187
+ });
188
+ }, "parseFilter");
189
+ function getDayRange(options) {
190
+ const { now, timezone = "+00:00", offset } = options;
191
+ let m = toMoment(now).utcOffset((0, import_date.offsetFromString)(timezone));
192
+ if (offset > 0) {
193
+ return [
194
+ // 第二天开始计算
195
+ (m = m.add(1, "day").startOf("day")).format("YYYY-MM-DD"),
196
+ // 第九天开始前结束
197
+ m.clone().add(offset, "day").startOf("day").format("YYYY-MM-DD"),
198
+ "[)",
199
+ timezone
200
+ ];
201
+ }
202
+ return [
203
+ // 今天开始前
204
+ m.clone().subtract(-1 * offset - 1, "day").startOf("day").format("YYYY-MM-DD"),
205
+ // 明天开始前
206
+ m.clone().add(1, "day").startOf("day").format("YYYY-MM-DD"),
207
+ "[)",
208
+ timezone
209
+ ];
210
+ }
211
+ __name(getDayRange, "getDayRange");
212
+ function toMoment(value) {
213
+ if (!value) {
214
+ return (0, import_dayjs.dayjs)();
215
+ }
216
+ if (import_dayjs.dayjs.isDayjs(value)) {
217
+ return value;
218
+ }
219
+ return (0, import_dayjs.dayjs)(value);
220
+ }
221
+ __name(toMoment, "toMoment");
222
+ function utc2unit(options) {
223
+ var _a;
224
+ const { now, unit, timezone = "+00:00", offset } = options;
225
+ let m = toMoment(now);
226
+ m = m.utcOffset((0, import_date.offsetFromString)(timezone));
227
+ m = m.startOf(unit);
228
+ if (offset > 0) {
229
+ m = m.add(offset, unit);
230
+ } else if (offset < 0) {
231
+ m = m.subtract(-1 * offset, unit);
232
+ }
233
+ const fn = {
234
+ year: /* @__PURE__ */ __name(() => m.format("YYYY"), "year"),
235
+ quarter: /* @__PURE__ */ __name(() => m.format("YYYY[Q]Q"), "quarter"),
236
+ month: /* @__PURE__ */ __name(() => m.format("YYYY-MM"), "month"),
237
+ week: /* @__PURE__ */ __name(() => m.format("gggg[w]ww"), "week"),
238
+ isoWeek: /* @__PURE__ */ __name(() => m.format("GGGG[W]WW"), "isoWeek"),
239
+ day: /* @__PURE__ */ __name(() => m.format("YYYY-MM-DD"), "day")
240
+ };
241
+ const r = (_a = fn[unit]) == null ? void 0 : _a.call(fn);
242
+ return timezone ? r + timezone : r;
243
+ }
244
+ __name(utc2unit, "utc2unit");
245
+ const toUnit = /* @__PURE__ */ __name((unit, offset) => {
246
+ return ({ now, timezone, field }) => {
247
+ if (field == null ? void 0 : field.timezone) {
248
+ timezone = field == null ? void 0 : field.timezone;
249
+ }
250
+ return utc2unit({ now, timezone, unit, offset });
251
+ };
252
+ }, "toUnit");
253
+ const toDays = /* @__PURE__ */ __name((offset) => {
254
+ return ({ now, timezone, field }) => {
255
+ if (field == null ? void 0 : field.timezone) {
256
+ timezone = field == null ? void 0 : field.timezone;
257
+ }
258
+ return getDayRange({ now, timezone, offset });
259
+ };
260
+ }, "toDays");
261
+ function getDateVars() {
262
+ return {
263
+ now: (/* @__PURE__ */ new Date()).toISOString(),
264
+ today: toUnit("day"),
265
+ yesterday: toUnit("day", -1),
266
+ tomorrow: toUnit("day", 1),
267
+ thisWeek: toUnit("week"),
268
+ lastWeek: toUnit("week", -1),
269
+ nextWeek: toUnit("week", 1),
270
+ thisIsoWeek: toUnit("isoWeek"),
271
+ lastIsoWeek: toUnit("isoWeek", -1),
272
+ nextIsoWeek: toUnit("isoWeek", 1),
273
+ thisMonth: toUnit("month"),
274
+ lastMonth: toUnit("month", -1),
275
+ nextMonth: toUnit("month", 1),
276
+ thisQuarter: toUnit("quarter"),
277
+ lastQuarter: toUnit("quarter", -1),
278
+ nextQuarter: toUnit("quarter", 1),
279
+ thisYear: toUnit("year"),
280
+ lastYear: toUnit("year", -1),
281
+ nextYear: toUnit("year", 1),
282
+ last7Days: toDays(-7),
283
+ next7Days: toDays(7),
284
+ last30Days: toDays(-30),
285
+ next30Days: toDays(30),
286
+ last90Days: toDays(-90),
287
+ next90Days: toDays(90)
288
+ };
289
+ }
290
+ __name(getDateVars, "getDateVars");
291
+ function splitPathToTwoParts(path) {
292
+ const parts = path.split(".");
293
+ return [parts.shift(), parts.join(".")];
294
+ }
295
+ __name(splitPathToTwoParts, "splitPathToTwoParts");
296
+ // Annotate the CommonJS export names for ESM import in node:
297
+ 0 && (module.exports = {
298
+ flatten,
299
+ getDateVars,
300
+ getDayRange,
301
+ parseFilter,
302
+ splitPathToTwoParts,
303
+ unflatten,
304
+ utc2unit
305
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * parseHTML('<span>{{version}}</span>', { version: '1.0.0' }) -> '<span>1.0.0</span>'
3
+ * @param html
4
+ * @param variables
5
+ * @returns
6
+ */
7
+ export declare function parseHTML(html: string, variables: Record<string, any>): string;
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var parseHTML_exports = {};
20
+ __export(parseHTML_exports, {
21
+ parseHTML: () => parseHTML
22
+ });
23
+ module.exports = __toCommonJS(parseHTML_exports);
24
+ function parseHTML(html, variables) {
25
+ return html.replace(/\{\{(\w+)\}\}/g, function(match, key) {
26
+ return typeof variables[key] !== "undefined" ? variables[key] : match;
27
+ });
28
+ }
29
+ __name(parseHTML, "parseHTML");
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ parseHTML
33
+ });
@@ -0,0 +1,6 @@
1
+ export declare const prePerfHooksWrap: (handler: any, options?: {
2
+ name?: string;
3
+ }) => (ctx: any, next: any) => Promise<any>;
4
+ export declare const postPerfHooksWrap: (handler: any, options: {
5
+ name?: string;
6
+ }) => (ctx: any, next: any) => Promise<any>;
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var perf_hooks_exports = {};
20
+ __export(perf_hooks_exports, {
21
+ postPerfHooksWrap: () => postPerfHooksWrap,
22
+ prePerfHooksWrap: () => prePerfHooksWrap
23
+ });
24
+ module.exports = __toCommonJS(perf_hooks_exports);
25
+ var import_perf_hooks = require("perf_hooks");
26
+ const prePerfHooksWrap = /* @__PURE__ */ __name((handler, options) => {
27
+ const { name } = options || {};
28
+ return async (ctx, next) => {
29
+ if (!ctx.getPerfHistogram) {
30
+ return await handler(ctx, next);
31
+ }
32
+ const histogram = ctx.getPerfHistogram(name || handler);
33
+ const start = import_perf_hooks.performance.now();
34
+ await handler(ctx, async () => {
35
+ const duration = import_perf_hooks.performance.now() - start;
36
+ histogram.record(Math.ceil(duration * 1e6));
37
+ await next();
38
+ });
39
+ };
40
+ }, "prePerfHooksWrap");
41
+ const postPerfHooksWrap = /* @__PURE__ */ __name((handler, options) => {
42
+ const { name } = options || {};
43
+ return async (ctx, next) => {
44
+ if (!ctx.getPerfHistogram) {
45
+ return await handler(ctx, next);
46
+ }
47
+ await next();
48
+ const histogram = ctx.getPerfHistogram(name || handler);
49
+ const start = import_perf_hooks.performance.now();
50
+ await handler(ctx, async () => {
51
+ });
52
+ const duration = import_perf_hooks.performance.now() - start;
53
+ histogram.record(Math.ceil(duration * 1e6));
54
+ };
55
+ }, "postPerfHooksWrap");
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ postPerfHooksWrap,
59
+ prePerfHooksWrap
60
+ });
@@ -0,0 +1,4 @@
1
+ export declare function createStoragePluginSymLink(pluginName: any): Promise<void>;
2
+ export declare function createStoragePluginsSymlink(): Promise<void>;
3
+ export declare function createDevPluginSymLink(pluginName: string): Promise<void>;
4
+ export declare function createDevPluginsSymlink(): Promise<void>;
@@ -0,0 +1,131 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var plugin_symlink_exports = {};
30
+ __export(plugin_symlink_exports, {
31
+ createDevPluginSymLink: () => createDevPluginSymLink,
32
+ createDevPluginsSymlink: () => createDevPluginsSymlink,
33
+ createStoragePluginSymLink: () => createStoragePluginSymLink,
34
+ createStoragePluginsSymlink: () => createStoragePluginsSymlink
35
+ });
36
+ module.exports = __toCommonJS(plugin_symlink_exports);
37
+ var import_node_fs = require("node:fs");
38
+ var import_promises = require("node:fs/promises");
39
+ var import_node_path = __toESM(require("node:path"));
40
+ var import_fs_exists = require("./fs-exists");
41
+ async function getStoragePluginNames(target) {
42
+ const plugins = [];
43
+ const items = await (0, import_promises.readdir)(target);
44
+ for (const item of items) {
45
+ if (item.startsWith("@")) {
46
+ const children = await getStoragePluginNames((0, import_node_path.resolve)(target, item));
47
+ plugins.push(
48
+ ...children.map((child) => {
49
+ return `${item}/${child}`;
50
+ })
51
+ );
52
+ } else if (await (0, import_fs_exists.fsExists)((0, import_node_path.resolve)(target, item, "package.json"))) {
53
+ plugins.push(item);
54
+ }
55
+ }
56
+ return plugins;
57
+ }
58
+ __name(getStoragePluginNames, "getStoragePluginNames");
59
+ async function createStoragePluginSymLink(pluginName) {
60
+ const storagePluginsPath = (0, import_node_path.resolve)(process.cwd(), "storage/plugins");
61
+ const nodeModulesPath = process.env.NODE_MODULES_PATH;
62
+ try {
63
+ if (pluginName.startsWith("@")) {
64
+ const [orgName] = pluginName.split("/");
65
+ if (!await (0, import_fs_exists.fsExists)((0, import_node_path.resolve)(nodeModulesPath, orgName))) {
66
+ await (0, import_promises.mkdir)((0, import_node_path.resolve)(nodeModulesPath, orgName), { recursive: true });
67
+ }
68
+ }
69
+ const link = (0, import_node_path.resolve)(nodeModulesPath, pluginName);
70
+ if (await (0, import_fs_exists.fsExists)(link)) {
71
+ await (0, import_promises.unlink)(link);
72
+ }
73
+ await (0, import_promises.symlink)((0, import_node_path.resolve)(storagePluginsPath, pluginName), link, "dir");
74
+ } catch (error) {
75
+ console.error(error);
76
+ }
77
+ }
78
+ __name(createStoragePluginSymLink, "createStoragePluginSymLink");
79
+ async function createStoragePluginsSymlink() {
80
+ const storagePluginsPath = (0, import_node_path.resolve)(process.cwd(), "storage/plugins");
81
+ if (!await (0, import_fs_exists.fsExists)(storagePluginsPath)) {
82
+ return;
83
+ }
84
+ const pluginNames = await getStoragePluginNames(storagePluginsPath);
85
+ await Promise.all(pluginNames.map((pluginName) => createStoragePluginSymLink(pluginName)));
86
+ }
87
+ __name(createStoragePluginsSymlink, "createStoragePluginsSymlink");
88
+ async function createDevPluginSymLink(pluginName) {
89
+ const packagePluginsPath = (0, import_node_path.resolve)(process.cwd(), "packages");
90
+ const nodeModulesPath = process.env.NODE_MODULES_PATH;
91
+ try {
92
+ const packageJson = JSON.parse(
93
+ (0, import_node_fs.readFileSync)((0, import_node_path.join)(packagePluginsPath, pluginName, "package.json"), { encoding: "utf-8" })
94
+ );
95
+ const fullname = packageJson.name;
96
+ if (fullname.startsWith("@")) {
97
+ const [orgName] = fullname.split("/");
98
+ if (!await (0, import_fs_exists.fsExists)((0, import_node_path.resolve)(nodeModulesPath, orgName))) {
99
+ await (0, import_promises.mkdir)((0, import_node_path.resolve)(nodeModulesPath, orgName), { recursive: true });
100
+ }
101
+ }
102
+ const link = (0, import_node_path.resolve)(nodeModulesPath, fullname);
103
+ if (await (0, import_fs_exists.fsExists)(link)) {
104
+ await (0, import_promises.unlink)(link);
105
+ }
106
+ const target = (0, import_node_path.resolve)(packagePluginsPath, pluginName);
107
+ const relativeTarget = import_node_path.default.relative(import_node_path.default.dirname(link), target);
108
+ await (0, import_promises.symlink)(relativeTarget, link, "dir");
109
+ } catch (error) {
110
+ console.error(error);
111
+ }
112
+ }
113
+ __name(createDevPluginSymLink, "createDevPluginSymLink");
114
+ async function createDevPluginsSymlink() {
115
+ const storagePluginsPath = (0, import_node_path.resolve)(process.cwd(), "packages");
116
+ if (!await (0, import_fs_exists.fsExists)(storagePluginsPath)) {
117
+ return;
118
+ }
119
+ const pluginNames = await getStoragePluginNames(storagePluginsPath);
120
+ await Promise.all(
121
+ pluginNames.filter((pluginName) => pluginName.startsWith("plugin-") || pluginName.startsWith("module-")).map((pluginName) => createDevPluginSymLink(pluginName))
122
+ );
123
+ }
124
+ __name(createDevPluginsSymlink, "createDevPluginsSymlink");
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ createDevPluginSymLink,
128
+ createDevPluginsSymlink,
129
+ createStoragePluginSymLink,
130
+ createStoragePluginsSymlink
131
+ });
@@ -0,0 +1,14 @@
1
+ export interface RegistryOptions {
2
+ override: boolean;
3
+ }
4
+ export declare class Registry<T> {
5
+ private map;
6
+ options: RegistryOptions;
7
+ constructor(options?: RegistryOptions);
8
+ register(key: string, value: T): void;
9
+ get(key: string): T;
10
+ getKeys(): Iterable<string>;
11
+ getValues(): Iterable<T>;
12
+ getEntities(): Iterable<[string, T]>;
13
+ }
14
+ export default Registry;
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var registry_exports = {};
20
+ __export(registry_exports, {
21
+ Registry: () => Registry,
22
+ default: () => registry_default
23
+ });
24
+ module.exports = __toCommonJS(registry_exports);
25
+ const _Registry = class _Registry {
26
+ map = /* @__PURE__ */ new Map();
27
+ options;
28
+ constructor(options = { override: false }) {
29
+ this.options = options;
30
+ }
31
+ register(key, value) {
32
+ if (!this.options.override && this.map.has(key)) {
33
+ throw new Error(`this registry does not allow to override existing keys: "${key}"`);
34
+ }
35
+ this.map.set(key, value);
36
+ }
37
+ // async import({ directory, extensions = ['.js', '.ts', '.json'] }) {
38
+ // const files = await fs.readdir(directory);
39
+ // return files.filter(file => extensions.includes(path.extname(file)))
40
+ // }
41
+ get(key) {
42
+ return this.map.get(key);
43
+ }
44
+ getKeys() {
45
+ return this.map.keys();
46
+ }
47
+ getValues() {
48
+ return this.map.values();
49
+ }
50
+ getEntities() {
51
+ return this.map.entries();
52
+ }
53
+ };
54
+ __name(_Registry, "Registry");
55
+ let Registry = _Registry;
56
+ var registry_default = Registry;
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ Registry
60
+ });
@@ -0,0 +1,3 @@
1
+ export declare function requireModule(m: any): any;
2
+ export default requireModule;
3
+ export declare function importModule(m: string): Promise<any>;