@tachybase/plugin-field-sequence 0.23.41 → 0.23.47
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/client/index.js +6 -6
- package/dist/externalVersion.js +6 -6
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/server/Plugin.js +4 -1
- package/dist/server/fields/field-sequence.js +67 -68
- package/dist/server/migrations/20221207022250-sequence-field-key.js +4 -1
- package/package.json +10 -10
package/dist/client/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("react/jsx-runtime"),require("react"),require("@tachybase/components"),require("@tachybase/schema"),require("@tachybase/utils/client"),require("antd"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","react/jsx-runtime","react","@tachybase/components","@tachybase/schema","@tachybase/utils/client","antd","react-i18next"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-field-sequence"]={},n["@tachybase/client"],n.jsxRuntime,n.react,n["@tachybase/components"],n["@tachybase/schema"],n["@tachybase/utils"],n.antd,n["react-i18next"]))})(this,function(n,e,t,S,u,
|
|
1
|
+
(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("react/jsx-runtime"),require("react"),require("@tachybase/components"),require("@tachybase/schema"),require("@tachybase/utils/client"),require("antd"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","react/jsx-runtime","react","@tachybase/components","@tachybase/schema","@tachybase/utils/client","antd","react-i18next"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-field-sequence"]={},n["@tachybase/client"],n.jsxRuntime,n.react,n["@tachybase/components"],n["@tachybase/schema"],n["@tachybase/utils"],n.antd,n["react-i18next"]))})(this,function(n,e,t,I,p,m,S,u,d){"use strict";var Y=Object.defineProperty,V=Object.defineProperties;var w=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var T=(n,e,t)=>e in n?Y(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e)=>{for(var t in e||(e={}))z.call(e,t)&&T(n,t,e[t]);if($)for(var t of $(e))B.call(e,t)&&T(n,t,e[t]);return n},g=(n,e)=>V(n,w(e));var A=(n,e,t)=>new Promise((I,p)=>{var m=d=>{try{u(t.next(d))}catch(r){p(r)}},S=d=>{try{u(t.throw(d))}catch(r){p(r)}},u=d=>d.done?I(d.value):Promise.resolve(d.value).then(m,S);u((t=t.apply(n,e)).next())});const r="field-sequence";function j(o,a={}){return e.i18n.t(o,g(h({},a),{ns:[r,"core"]}))}function F(o){return e.tval(o,{ns:[r,"core"]})}function M(o){const a=e.useCompile(),{setValuesIn:i}=m.useForm(),l=p.ArrayTable.useIndex();return m.useFormEffects(()=>{m.onFieldValueChange(`patterns.${l}.type`,s=>{i(`patterns.${l}.options`,{})})}),t.jsx(u.Select,g(h({popupMatchSelectWidth:!1},o),{children:Object.keys(b).map(s=>t.jsx(u.Select.Option,{value:s,children:a(b[s].title)},s))}))}function O(){const o=e.useCompile(),{values:a}=m.useForm(),i=p.ArrayTable.useIndex(),{type:l,options:s}=a.patterns[i],y=b[l];return t.jsx("div",{className:e.css`
|
|
2
2
|
display: flex;
|
|
3
3
|
gap: 1em;
|
|
4
4
|
flex-wrap: wrap;
|
|
5
|
-
`,children:Object.keys(s).filter(
|
|
5
|
+
`,children:Object.keys(s).filter(c=>typeof s[c]!="undefined"&&y.optionRenders[c]).map(c=>{const v=y.optionRenders[c],{title:f}=y.fieldset[c];return v?t.jsxs("dl",{className:e.css`
|
|
6
6
|
margin: 0;
|
|
7
7
|
padding: 0;
|
|
8
|
-
`,children:[t.jsx("dt",{children:o(
|
|
8
|
+
`,children:[t.jsx("dt",{children:o(f)}),t.jsx("dd",{className:e.css`
|
|
9
9
|
margin-bottom: 0;
|
|
10
|
-
`,children:t.jsx(
|
|
10
|
+
`,children:t.jsx(v,{value:s[c]},c)})]},c):null})})}const b={string:{title:`{{t("Fixed text", { ns: "${r}" })}}`,optionRenders:{value(o={value:""}){return t.jsx("code",{children:o.value})}},fieldset:{value:{type:"string",title:`{{t("Text content", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"Input"}}},integer:{title:`{{t("Autoincrement", { ns: "${r}" })}}`,optionRenders:{digits:function({value:a}){return t.jsx("code",{children:a})},start:function({value:a}){return t.jsx("code",{children:a})},cycle:e.Cron.ReadPretty},fieldset:{digits:{type:"number",title:`{{t("Digits", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:1,max:10},required:!0,default:1,"x-reactions":{target:"start",fulfill:{schema:{"x-component-props.max":"{{ 10 ** $self.value - 1 }}"}}}},start:{type:"number",title:`{{t("Start from", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:0},required:!0,default:0},cycle:{type:"string",title:`{{t("Reset cycle", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component"({value:o,onChange:a}){const i=[{label:"No reset",value:0},{label:"Daily",value:1,cron:"0 0 * * *"},{label:"Every Monday",value:2,cron:"0 0 * * 1"},{label:"Monthly",value:3,cron:"0 0 1 * *"},{label:"Yearly",value:4,cron:"0 0 1 1 *"},{label:"Customize",value:5,cron:"* * * * *"}],l=typeof o=="undefined"?i[0]:i.find(s=>s.cron===o)||i[5];return t.jsxs("fieldset",{children:[t.jsx(u.Select,{value:l.value,onChange:s=>a(i[s].cron),children:i.map(s=>t.jsx(u.Select.Option,{value:s.value,children:j(s.label)},s.value))}),l.value===5?t.jsx(e.Cron,{value:o,onChange:a,clearButton:!1}):null]})},default:null}}},date:{title:F("Date"),optionRenders:{format(o={value:"YYYYMMDD"}){return t.jsx("code",{children:o.value})}},fieldset:{format:{type:"string",title:F("Date format"),"x-decorator":"FormItem","x-component":"Input",default:"YYYYMMDD"}}}};function q(){const{t:o}=d.useTranslation(),a=e.useCompile(),i=I.useContext(m.SchemaOptionsContext),{values:l,setValuesIn:s}=m.useForm(),y=p.ArrayTable.useIndex(),{type:c,options:v}=l.patterns[y],f=b[c],{token:N}=e.useToken();return f!=null&&f.fieldset?t.jsx(u.Button,{type:"link",onClick:()=>{p.FormDrawer({title:a(f.title),zIndex:N.zIndexPopupBase+1e3},()=>t.jsxs(p.FormLayout,{layout:"vertical",children:[t.jsx(e.SchemaComponentOptions,{scope:i.scope,components:i.components,children:t.jsx(e.SchemaComponent,{schema:{type:"object","x-component":"fieldset",properties:f.fieldset}})}),t.jsx(p.FormButtonGroup,{className:e.css`
|
|
11
11
|
justify-content: flex-end;
|
|
12
|
-
`,children:t.jsx(
|
|
12
|
+
`,children:t.jsx(p.Submit,{onSubmit:x=>x,children:o("Submit")})})]})).open({initialValues:v}).then(x=>{s(`patterns.${y}`,{type:c,options:h({},x)})}).catch(x=>{S.error(x)})},children:o("Configure")}):null}class P extends e.CollectionFieldInterface{constructor(){super(...arguments),this.name="sequence",this.type="object",this.group="advanced",this.order=3,this.title=`{{t("Sequence", { ns: "${r}" })}}`,this.description=`{{t("Automatically generate codes based on configured rules, supporting combinations of dates, numbers, and text.", { ns: "${r}" })}}`,this.sortable=!0,this.default={type:"sequence",uiSchema:{type:"string","x-component":"Input","x-component-props":{}}},this.availableTypes=["string"],this.hasDefaultValue=!1,this.filterable={operators:e.interfacesProperties.operators.string},this.titleUsable=!0,this.properties=g(h({},e.interfacesProperties.defaultProps),{unique:e.interfacesProperties.unique,patterns:{type:"array",title:`{{t("Sequence rules", { ns: "${r}" })}}`,required:!0,"x-decorator":"FormItem","x-component":"ArrayTable",items:{type:"object",properties:{sort:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:50,title:"",align:"center"},properties:{sort:{type:"void","x-component":"ArrayTable.SortHandle"}}},type:{type:"void","x-component":"ArrayTable.Column","x-component-props":{title:`{{t("Type", { ns: "${r}" })}}`},properties:{type:{type:"string",name:"type",required:!0,"x-decorator":"FormItem","x-component":M}}},options:{type:"void","x-component":"ArrayTable.Column","x-component-props":{title:`{{t("Rule content", { ns: "${r}" })}}`},properties:{options:{type:"object",name:"options","x-component":O}}},operations:{type:"void","x-component":"ArrayTable.Column","x-component-props":{title:`{{t("Operations", { ns: "${r}" })}}`,dataIndex:"operations",fixed:"right",className:e.css`
|
|
13
13
|
> *:not(:last-child) {
|
|
14
14
|
margin-right: 0.5em;
|
|
15
15
|
}
|
|
16
16
|
button {
|
|
17
17
|
padding: 0;
|
|
18
18
|
}
|
|
19
|
-
`},properties:{config:{type:"void",properties:{options:{type:"object","x-component"
|
|
19
|
+
`},properties:{config:{type:"void",properties:{options:{type:"object","x-component":q}}},remove:{type:"void","x-component":"ArrayTable.Remove"}}}}},properties:{add:{type:"void","x-component":"ArrayTable.Addition","x-component-props":{defaultValue:{type:"integer",options:{digits:1,start:0}}},title:`{{t("Add rule", { ns: "${r}" })}}`}}},inputable:{type:"boolean",title:`{{t("Inputable", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox"},match:{type:"boolean",title:`{{t("Match rules", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:["inputable"],fulfill:{state:{value:"{{$deps[0] && $self.value}}",visible:"{{$deps[0] === true}}"}}}}})}schemaInitialize(a,{block:i,field:l}){return i==="Form"&&Object.assign(a["x-component-props"],{disabled:!l.inputable}),a}}const D=o=>t.jsx(e.SchemaComponentOptions,{components:{RuleConfigForm:q},children:o.children});class C extends e.Plugin{load(){return A(this,null,function*(){this.app.use(D),this.app.dataSourceManager.addFieldInterfaces([P])})}}n.SequenceFieldPlugin=C,n.default=C,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.3.1",
|
|
3
|
-
"@tachybase/client": "0.23.
|
|
4
|
-
"@tachybase/components": "0.23.
|
|
5
|
-
"@tachybase/schema": "0.23.
|
|
6
|
-
"@tachybase/utils": "0.23.
|
|
3
|
+
"@tachybase/client": "0.23.47",
|
|
4
|
+
"@tachybase/components": "0.23.47",
|
|
5
|
+
"@tachybase/schema": "0.23.47",
|
|
6
|
+
"@tachybase/utils": "0.23.47",
|
|
7
7
|
"antd": "5.22.5",
|
|
8
8
|
"react-i18next": "15.2.0",
|
|
9
|
-
"@tachybase/server": "0.23.
|
|
10
|
-
"@tachybase/database": "0.23.
|
|
9
|
+
"@tachybase/server": "0.23.47",
|
|
10
|
+
"@tachybase/database": "0.23.47",
|
|
11
11
|
"dayjs": "1.11.13",
|
|
12
12
|
"lodash": "4.17.21"
|
|
13
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"cron-parser","version":"4.9.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"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":"^3.2.1"},"devDependencies":{"eslint":"^8.27.0","sinon":"^15.0.1","tap":"^16.3.3","tsd":"^0.26.0"},"engines":{"node":">=12.0.0"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"files":["lib","types","LICENSE","README.md"],"_lastModified":"2025-02-
|
|
1
|
+
{"name":"cron-parser","version":"4.9.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"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":"^3.2.1"},"devDependencies":{"eslint":"^8.27.0","sinon":"^15.0.1","tap":"^16.3.3","tsd":"^0.26.0"},"engines":{"node":">=12.0.0"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"files":["lib","types","LICENSE","README.md"],"_lastModified":"2025-02-21T02:30:05.523Z"}
|
package/dist/server/Plugin.js
CHANGED
|
@@ -38,7 +38,10 @@ var import_utils = require("@tachybase/utils");
|
|
|
38
38
|
var import_field_sequence = require("./fields/field-sequence");
|
|
39
39
|
const asyncRandomInt = (0, import_util.promisify)(import_crypto.randomInt);
|
|
40
40
|
class SequenceFieldPlugin extends import_server.Plugin {
|
|
41
|
-
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.patternTypes = new import_utils.Registry();
|
|
44
|
+
}
|
|
42
45
|
async load() {
|
|
43
46
|
const { app, db, options } = this;
|
|
44
47
|
db.registerFieldTypes({
|
|
@@ -258,12 +258,72 @@ sequencePatterns.register("date", {
|
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
260
|
class SequenceField extends import_database.Field {
|
|
261
|
-
matcher;
|
|
262
|
-
get dataType() {
|
|
263
|
-
return import_database.DataTypes.STRING;
|
|
264
|
-
}
|
|
265
261
|
constructor(options, context) {
|
|
266
262
|
super(options, context);
|
|
263
|
+
this.validate = (instance) => {
|
|
264
|
+
const { name, inputable, match } = this.options;
|
|
265
|
+
const value = instance.get(name);
|
|
266
|
+
if (value != null && inputable && match && !this.match(value)) {
|
|
267
|
+
throw new import_database.ValidationError("sequence pattern not match", [
|
|
268
|
+
new import_database.ValidationErrorItem(
|
|
269
|
+
`input value of ${name} field not match the sequence pattern (${this.matcher.toString()}) which is required`,
|
|
270
|
+
"validation error",
|
|
271
|
+
// NOTE: type should only be this which in sequelize enum set
|
|
272
|
+
name,
|
|
273
|
+
value,
|
|
274
|
+
instance,
|
|
275
|
+
"sequence_pattern_not_match",
|
|
276
|
+
name,
|
|
277
|
+
[]
|
|
278
|
+
)
|
|
279
|
+
]);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
this.setValue = async (instance, options) => {
|
|
283
|
+
var _a;
|
|
284
|
+
if ((_a = options.skipIndividualHooks) == null ? void 0 : _a.has(`${this.collection.name}.beforeCreate.${this.name}`)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const { name, patterns, inputable } = this.options;
|
|
288
|
+
const value = instance.get(name);
|
|
289
|
+
if (value != null && inputable) {
|
|
290
|
+
return this.update(instance, options);
|
|
291
|
+
}
|
|
292
|
+
const results = await patterns.reduce(
|
|
293
|
+
(promise, p) => promise.then(async (result) => {
|
|
294
|
+
const item = await sequencePatterns.get(p.type).generate.call(this, instance, p.options, options);
|
|
295
|
+
return result.concat(item);
|
|
296
|
+
}),
|
|
297
|
+
Promise.resolve([])
|
|
298
|
+
);
|
|
299
|
+
instance.set(name, results.join(""));
|
|
300
|
+
};
|
|
301
|
+
this.setGroupValue = async (instances, options) => {
|
|
302
|
+
if (!instances.length) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!options.skipIndividualHooks) {
|
|
306
|
+
options.skipIndividualHooks = /* @__PURE__ */ new Set();
|
|
307
|
+
}
|
|
308
|
+
options.skipIndividualHooks.add(`${this.collection.name}.beforeCreate.${this.name}`);
|
|
309
|
+
const { name, patterns, inputable } = this.options;
|
|
310
|
+
const array = Array(patterns.length).fill(null).map(() => Array(instances.length));
|
|
311
|
+
await patterns.reduce(
|
|
312
|
+
(promise, p, i) => promise.then(
|
|
313
|
+
() => sequencePatterns.get(p.type).batchGenerate.call(this, instances, array[i], p.options ?? {}, options)
|
|
314
|
+
),
|
|
315
|
+
Promise.resolve()
|
|
316
|
+
);
|
|
317
|
+
instances.forEach((instance, i) => {
|
|
318
|
+
const value = instance.get(name);
|
|
319
|
+
if (!inputable || value == null) {
|
|
320
|
+
instance.set(this.name, array.map((a) => a[i]).join(""));
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
this.cleanHook = (_, options) => {
|
|
325
|
+
options.skipIndividualHooks.delete(`${this.collection.name}.beforeCreate.${this.name}`);
|
|
326
|
+
};
|
|
267
327
|
if (!options.patterns || !options.patterns.length) {
|
|
268
328
|
throw new Error("at least one pattern should be defined for sequence type");
|
|
269
329
|
}
|
|
@@ -282,70 +342,9 @@ class SequenceField extends import_database.Field {
|
|
|
282
342
|
const patterns = options.patterns.map(({ type, options: options2 }) => sequencePatterns.get(type).getMatcher(options2));
|
|
283
343
|
this.matcher = new RegExp(`^${patterns.map((p) => `(${p})`).join("")}$`, "i");
|
|
284
344
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (value != null && inputable && match && !this.match(value)) {
|
|
289
|
-
throw new import_database.ValidationError("sequence pattern not match", [
|
|
290
|
-
new import_database.ValidationErrorItem(
|
|
291
|
-
`input value of ${name} field not match the sequence pattern (${this.matcher.toString()}) which is required`,
|
|
292
|
-
"validation error",
|
|
293
|
-
// NOTE: type should only be this which in sequelize enum set
|
|
294
|
-
name,
|
|
295
|
-
value,
|
|
296
|
-
instance,
|
|
297
|
-
"sequence_pattern_not_match",
|
|
298
|
-
name,
|
|
299
|
-
[]
|
|
300
|
-
)
|
|
301
|
-
]);
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
setValue = async (instance, options) => {
|
|
305
|
-
var _a;
|
|
306
|
-
if ((_a = options.skipIndividualHooks) == null ? void 0 : _a.has(`${this.collection.name}.beforeCreate.${this.name}`)) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
const { name, patterns, inputable } = this.options;
|
|
310
|
-
const value = instance.get(name);
|
|
311
|
-
if (value != null && inputable) {
|
|
312
|
-
return this.update(instance, options);
|
|
313
|
-
}
|
|
314
|
-
const results = await patterns.reduce(
|
|
315
|
-
(promise, p) => promise.then(async (result) => {
|
|
316
|
-
const item = await sequencePatterns.get(p.type).generate.call(this, instance, p.options, options);
|
|
317
|
-
return result.concat(item);
|
|
318
|
-
}),
|
|
319
|
-
Promise.resolve([])
|
|
320
|
-
);
|
|
321
|
-
instance.set(name, results.join(""));
|
|
322
|
-
};
|
|
323
|
-
setGroupValue = async (instances, options) => {
|
|
324
|
-
if (!instances.length) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (!options.skipIndividualHooks) {
|
|
328
|
-
options.skipIndividualHooks = /* @__PURE__ */ new Set();
|
|
329
|
-
}
|
|
330
|
-
options.skipIndividualHooks.add(`${this.collection.name}.beforeCreate.${this.name}`);
|
|
331
|
-
const { name, patterns, inputable } = this.options;
|
|
332
|
-
const array = Array(patterns.length).fill(null).map(() => Array(instances.length));
|
|
333
|
-
await patterns.reduce(
|
|
334
|
-
(promise, p, i) => promise.then(
|
|
335
|
-
() => sequencePatterns.get(p.type).batchGenerate.call(this, instances, array[i], p.options ?? {}, options)
|
|
336
|
-
),
|
|
337
|
-
Promise.resolve()
|
|
338
|
-
);
|
|
339
|
-
instances.forEach((instance, i) => {
|
|
340
|
-
const value = instance.get(name);
|
|
341
|
-
if (!inputable || value == null) {
|
|
342
|
-
instance.set(this.name, array.map((a) => a[i]).join(""));
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
};
|
|
346
|
-
cleanHook = (_, options) => {
|
|
347
|
-
options.skipIndividualHooks.delete(`${this.collection.name}.beforeCreate.${this.name}`);
|
|
348
|
-
};
|
|
345
|
+
get dataType() {
|
|
346
|
+
return import_database.DataTypes.STRING;
|
|
347
|
+
}
|
|
349
348
|
match(value) {
|
|
350
349
|
return typeof value === "string" ? value.match(this.matcher) : null;
|
|
351
350
|
}
|
|
@@ -22,7 +22,10 @@ __export(sequence_field_key_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(sequence_field_key_exports);
|
|
23
23
|
var import_server = require("@tachybase/server");
|
|
24
24
|
class sequence_field_key_default extends import_server.Migration {
|
|
25
|
-
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.appVersion = "<0.8.1-alpha.2";
|
|
28
|
+
}
|
|
26
29
|
async up() {
|
|
27
30
|
const match = await this.app.version.satisfies("<=0.8.0-alpha.13");
|
|
28
31
|
if (!match) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/plugin-field-sequence",
|
|
3
3
|
"displayName": "Collection field: Sequence",
|
|
4
|
-
"version": "0.23.
|
|
4
|
+
"version": "0.23.47",
|
|
5
5
|
"description": "Automatically generate codes based on configured rules, supporting combinations of dates, numbers, and text.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Collection fields"
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"react": "~18.3.1",
|
|
18
18
|
"react-i18next": "^15.2.0",
|
|
19
19
|
"react-js-cron": "^3.2.0",
|
|
20
|
-
"@tachybase/components": "0.23.
|
|
21
|
-
"@tachybase/schema": "0.23.
|
|
20
|
+
"@tachybase/components": "0.23.47",
|
|
21
|
+
"@tachybase/schema": "0.23.47"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@tachybase/actions": "0.23.
|
|
25
|
-
"@tachybase/client": "0.23.
|
|
26
|
-
"@tachybase/
|
|
27
|
-
"@tachybase/module-collection": "0.23.
|
|
28
|
-
"@tachybase/
|
|
29
|
-
"@tachybase/test": "0.23.
|
|
30
|
-
"@tachybase/utils": "0.23.
|
|
24
|
+
"@tachybase/actions": "0.23.47",
|
|
25
|
+
"@tachybase/client": "0.23.47",
|
|
26
|
+
"@tachybase/server": "0.23.47",
|
|
27
|
+
"@tachybase/module-collection": "0.23.47",
|
|
28
|
+
"@tachybase/database": "0.23.47",
|
|
29
|
+
"@tachybase/test": "0.23.47",
|
|
30
|
+
"@tachybase/utils": "0.23.47"
|
|
31
31
|
},
|
|
32
32
|
"description.zh-CN": "根据配置的规则自动生成编码,支持日期、数字、文本的组合。",
|
|
33
33
|
"displayName.zh-CN": "数据表字段:自动编码",
|