@nocobase/plugin-field-sequence 2.0.0-alpha.50 → 2.0.0-alpha.51
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/dist/externalVersion.js
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"react": "18.2.0",
|
|
12
|
-
"@nocobase/client": "2.0.0-alpha.
|
|
13
|
-
"@nocobase/flow-engine": "2.0.0-alpha.
|
|
12
|
+
"@nocobase/client": "2.0.0-alpha.51",
|
|
13
|
+
"@nocobase/flow-engine": "2.0.0-alpha.51",
|
|
14
14
|
"@formily/antd-v5": "1.2.3",
|
|
15
15
|
"@formily/core": "2.3.7",
|
|
16
16
|
"@formily/react": "2.3.7",
|
|
17
|
-
"@nocobase/utils": "2.0.0-alpha.
|
|
17
|
+
"@nocobase/utils": "2.0.0-alpha.51",
|
|
18
18
|
"antd": "5.24.2",
|
|
19
19
|
"react-i18next": "11.18.6",
|
|
20
|
-
"@nocobase/server": "2.0.0-alpha.
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"@nocobase/server": "2.0.0-alpha.51",
|
|
21
|
+
"lodash": "4.17.21",
|
|
22
|
+
"@nocobase/database": "2.0.0-alpha.51",
|
|
23
|
+
"dayjs": "1.11.13"
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"cron-parser","version":"4.4.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"index.d.ts","typesVersions":{"<4.1":{"*":["types/ts3/*"]}},"directories":{"test":"test"},"scripts":{"test:tsd":"tsd","test:unit":"TZ=UTC tap ./test/*.js","test:cover":"TZ=UTC tap --coverage-report=html ./test/*.js","lint":"eslint .","lint:fix":"eslint --fix .","test":"npm run lint && npm run test:unit && npm run test:tsd"},"repository":{"type":"git","url":"https://github.com/harrisiirak/cron-parser.git"},"keywords":["cron","crontab","parser"],"author":"Harri Siirak","contributors":["Nicholas Clawson","Daniel Prentis <daniel@salsitasoft.com>","Renault John Lecoultre","Richard Astbury <richard.astbury@gmail.com>","Meaglin Wasabi <Meaglin.wasabi@gmail.com>","Mike Kusold <hello@mikekusold.com>","Alex Kit <alex.kit@atmajs.com>","Santiago Gimeno <santiago.gimeno@gmail.com>","Daniel <darc.tec@gmail.com>","Christian Steininger <christian.steininger.cs@gmail.com>","Mykola Piskovyi <m.piskovyi@gmail.com>","Brian Vaughn <brian.david.vaughn@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Yasuhiroki <yasuhiroki.duck@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Brendan Warkentin <faazshift@gmail.com>","Charlie Fish <fishcharlie.code@gmail.com>","Ian Graves <ian+diskimage@iangrav.es>","Andy Thompson <me@andytson.com>","Regev Brody <regevbr@gmail.com>"],"license":"MIT","dependencies":{"luxon":"^1.28.0"},"devDependencies":{"eslint":"^8.2.0","sinon":"^10.0.0","tap":"^16.0.1","tsd":"^0.19.0"},"engines":{"node":">=0.8"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"_lastModified":"2025-12-
|
|
1
|
+
{"name":"cron-parser","version":"4.4.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"index.d.ts","typesVersions":{"<4.1":{"*":["types/ts3/*"]}},"directories":{"test":"test"},"scripts":{"test:tsd":"tsd","test:unit":"TZ=UTC tap ./test/*.js","test:cover":"TZ=UTC tap --coverage-report=html ./test/*.js","lint":"eslint .","lint:fix":"eslint --fix .","test":"npm run lint && npm run test:unit && npm run test:tsd"},"repository":{"type":"git","url":"https://github.com/harrisiirak/cron-parser.git"},"keywords":["cron","crontab","parser"],"author":"Harri Siirak","contributors":["Nicholas Clawson","Daniel Prentis <daniel@salsitasoft.com>","Renault John Lecoultre","Richard Astbury <richard.astbury@gmail.com>","Meaglin Wasabi <Meaglin.wasabi@gmail.com>","Mike Kusold <hello@mikekusold.com>","Alex Kit <alex.kit@atmajs.com>","Santiago Gimeno <santiago.gimeno@gmail.com>","Daniel <darc.tec@gmail.com>","Christian Steininger <christian.steininger.cs@gmail.com>","Mykola Piskovyi <m.piskovyi@gmail.com>","Brian Vaughn <brian.david.vaughn@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Yasuhiroki <yasuhiroki.duck@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Brendan Warkentin <faazshift@gmail.com>","Charlie Fish <fishcharlie.code@gmail.com>","Ian Graves <ian+diskimage@iangrav.es>","Andy Thompson <me@andytson.com>","Regev Brody <regevbr@gmail.com>"],"license":"MIT","dependencies":{"luxon":"^1.28.0"},"devDependencies":{"eslint":"^8.2.0","sinon":"^10.0.0","tap":"^16.0.1","tsd":"^0.19.0"},"engines":{"node":">=0.8"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"_lastModified":"2025-12-06T17:52:40.309Z"}
|
package/dist/server/Plugin.js
CHANGED
|
@@ -45,6 +45,7 @@ var import_util = require("util");
|
|
|
45
45
|
var import_server = require("@nocobase/server");
|
|
46
46
|
var import_utils = require("@nocobase/utils");
|
|
47
47
|
var import_sequence_field = require("./fields/sequence-field");
|
|
48
|
+
var import_lodash = __toESM(require("lodash"));
|
|
48
49
|
const asyncRandomInt = (0, import_util.promisify)(import_crypto.randomInt);
|
|
49
50
|
class PluginFieldSequenceServer extends import_server.Plugin {
|
|
50
51
|
patternTypes = new import_utils.Registry();
|
|
@@ -127,6 +128,49 @@ class PluginFieldSequenceServer extends import_server.Plugin {
|
|
|
127
128
|
transaction
|
|
128
129
|
});
|
|
129
130
|
});
|
|
131
|
+
app.on("repair", async () => {
|
|
132
|
+
app.log.info(`app ${app.name} plugin ${this.name} start repair data...`);
|
|
133
|
+
const sequencesModel = app.db.getModel("sequences");
|
|
134
|
+
const allSequences = await sequencesModel.findAll();
|
|
135
|
+
const groupedSequences = import_lodash.default.groupBy(allSequences, "collection");
|
|
136
|
+
const tasks = [];
|
|
137
|
+
for (const [collectionName, sequencesList] of Object.entries(groupedSequences)) {
|
|
138
|
+
tasks.push(async () => {
|
|
139
|
+
const collection = app.db.getCollection(collectionName);
|
|
140
|
+
const fields = collection.getFields();
|
|
141
|
+
const fieldMap = Object.fromEntries(fields.map((field) => [field.name, field]));
|
|
142
|
+
const [autoIncrementField] = fields.filter((field) => field.options.primaryKey && field.type === "bigInt");
|
|
143
|
+
const [createAtField] = fields.filter((field) => field.options.interface === "createdAt");
|
|
144
|
+
if (!autoIncrementField && !createAtField) {
|
|
145
|
+
app.log.warn(
|
|
146
|
+
`Collection [${collection}] does not have autoIncrement or createdAt fields. Skipping sequences refresh`
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const [record] = await collection.model.findAll({
|
|
151
|
+
order: [[(autoIncrementField == null ? void 0 : autoIncrementField.name) ?? (createAtField == null ? void 0 : createAtField.name), "DESC"]],
|
|
152
|
+
limit: 1
|
|
153
|
+
});
|
|
154
|
+
if (!record) {
|
|
155
|
+
app.log.warn(`Collection [${collection}] has no records. Skipping sequences repair`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const sequencesFieldSet = import_lodash.default.uniq(sequencesList.map(({ field }) => field));
|
|
159
|
+
for (const sequencesField of sequencesFieldSet) {
|
|
160
|
+
const field = fieldMap[sequencesField];
|
|
161
|
+
if (!field) {
|
|
162
|
+
app.log.warn(
|
|
163
|
+
`Collection [${collection}] field [${sequencesField}] definition not found. Skipping sequences repair`
|
|
164
|
+
);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
await field.update(record, { overwrite: true });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
await Promise.all(tasks.map((t) => t()));
|
|
172
|
+
app.log.info(`app ${app.name} plugin ${this.name} finish repair data`);
|
|
173
|
+
});
|
|
130
174
|
}
|
|
131
175
|
async install() {
|
|
132
176
|
}
|
|
@@ -18,7 +18,9 @@ export interface Pattern {
|
|
|
18
18
|
}, options: Transactionable): Promise<void> | void;
|
|
19
19
|
getLength(options: any): number;
|
|
20
20
|
getMatcher(options: any): string;
|
|
21
|
-
update?(this: SequenceField, instance: Model, value: string, options: any, transactionable: Transactionable
|
|
21
|
+
update?(this: SequenceField, instance: Model, value: string, options: any, transactionable: Transactionable & {
|
|
22
|
+
overwrite?: boolean;
|
|
23
|
+
}): Promise<void>;
|
|
22
24
|
}
|
|
23
25
|
export declare const sequencePatterns: Registry<Pattern>;
|
|
24
26
|
interface PatternConfig {
|
|
@@ -203,7 +203,7 @@ sequencePatterns.register("integer", {
|
|
|
203
203
|
});
|
|
204
204
|
await lastSeq.save({ transaction });
|
|
205
205
|
},
|
|
206
|
-
async update(instance, value, options, { transaction }) {
|
|
206
|
+
async update(instance, value, options, { transaction, overwrite }) {
|
|
207
207
|
const recordTime = instance.get("createdAt") ?? /* @__PURE__ */ new Date();
|
|
208
208
|
const { digits = 1, start = 0, base = 10, cycle, key } = options;
|
|
209
209
|
const SeqRepo = this.database.getRepository("sequences");
|
|
@@ -237,6 +237,15 @@ sequencePatterns.register("integer", {
|
|
|
237
237
|
{ transaction }
|
|
238
238
|
);
|
|
239
239
|
}
|
|
240
|
+
if (overwrite === true) {
|
|
241
|
+
return lastSeq.update(
|
|
242
|
+
{
|
|
243
|
+
current,
|
|
244
|
+
lastGeneratedAt: recordTime
|
|
245
|
+
},
|
|
246
|
+
{ transaction }
|
|
247
|
+
);
|
|
248
|
+
}
|
|
240
249
|
if (cycle) {
|
|
241
250
|
const interval = import_cron_parser.default.parseExpression(cycle, { currentDate: lastSeq.get("lastGeneratedAt") });
|
|
242
251
|
const nextTime = interval.next();
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description": "Automatically generate codes based on configured rules, supporting combinations of dates, numbers, and text.",
|
|
7
7
|
"description.ru-RU": "Автоматически генерирует коды по заданным правилам с поддержкой комбинаций дат, чисел и текста.",
|
|
8
8
|
"description.zh-CN": "根据配置的规则自动生成编码,支持日期、数字、文本的组合。",
|
|
9
|
-
"version": "2.0.0-alpha.
|
|
9
|
+
"version": "2.0.0-alpha.51",
|
|
10
10
|
"license": "AGPL-3.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/handbook/field-sequence",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@nocobase/test": "2.x",
|
|
33
33
|
"@nocobase/utils": "2.x"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a1e34dd97f370d54f3d80a6b83ab7ddb9c72dc18",
|
|
36
36
|
"keywords": [
|
|
37
37
|
"Collection fields"
|
|
38
38
|
]
|