@things-factory/id-rule-base 3.6.33 → 3.6.38

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.
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IdRuleResolver = void 0;
4
- const id_rule_1 = require("./id-rule");
5
4
  const create_id_rule_1 = require("./create-id-rule");
5
+ const id_rule_1 = require("./id-rule");
6
6
  const update_id_rule_1 = require("./update-id-rule");
7
+ const update_insert_sequence_1 = require("./update-insert-sequence");
7
8
  exports.IdRuleResolver = {
8
9
  Query: Object.assign({}, id_rule_1.idRuleResolver),
9
- Mutation: Object.assign(Object.assign({}, create_id_rule_1.createIdRule), update_id_rule_1.updateIdRule)
10
+ Mutation: Object.assign(Object.assign(Object.assign({}, create_id_rule_1.createIdRule), update_id_rule_1.updateIdRule), update_insert_sequence_1.upsertSequence)
10
11
  };
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/graphql/resolvers/index.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAC1C,qDAA+C;AAC/C,qDAA+C;AAElC,QAAA,cAAc,GAAG;IAC5B,KAAK,oBACA,wBAAc,CAClB;IACD,QAAQ,kCACH,6BAAY,GACZ,6BAAY,CAChB;CACF,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/graphql/resolvers/index.ts"],"names":[],"mappings":";;;AAAA,qDAA+C;AAC/C,uCAA0C;AAC1C,qDAA+C;AAC/C,qEAAyD;AAE5C,QAAA,cAAc,GAAG;IAC5B,KAAK,oBACA,wBAAc,CAClB;IACD,QAAQ,gDACH,6BAAY,GACZ,6BAAY,GACZ,uCAAc,CAClB;CACF,CAAA"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upsertSequence = void 0;
4
+ const typeorm_1 = require("typeorm");
5
+ const entities_1 = require("../../entities");
6
+ exports.upsertSequence = {
7
+ async upsertSequence(_, { pattern, counter }, context) {
8
+ const domain = context.state.domain;
9
+ const seqRepo = (0, typeorm_1.getRepository)(entities_1.Sequence);
10
+ const now = new Date();
11
+ const expiresAt = new Date(now.setMonth(now.getMonth() + 12));
12
+ pattern = `${pattern} [${getDateStr()}]`;
13
+ const foundSeq = await seqRepo.findOne({
14
+ where: { pattern, domain }
15
+ });
16
+ if (foundSeq) {
17
+ return await seqRepo.save(Object.assign(Object.assign({}, foundSeq), { seq: counter ? foundSeq.seq + counter : foundSeq.seq + 1, expiresAt }));
18
+ }
19
+ else {
20
+ return await seqRepo.save({
21
+ domain,
22
+ pattern,
23
+ seq: 1,
24
+ expiresAt
25
+ });
26
+ }
27
+ }
28
+ };
29
+ function getDateStr() {
30
+ const today = new Date();
31
+ const year = today.getFullYear();
32
+ const month = today.getMonth();
33
+ const day = today.getDate();
34
+ const yy = String(year).substr(String(year).length - 2);
35
+ const mm = String(month + 1).padStart(2, '0');
36
+ const dd = String(day).padStart(2, '0');
37
+ return yy + mm + dd;
38
+ }
39
+ //# sourceMappingURL=update-insert-sequence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-insert-sequence.js","sourceRoot":"","sources":["../../../server/graphql/resolvers/update-insert-sequence.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAIvC,6CAAyC;AAE5B,QAAA,cAAc,GAAG;IAC5B,KAAK,CAAC,cAAc,CAAC,CAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,OAAY;QAC7D,MAAM,MAAM,GAAW,OAAO,CAAC,KAAK,CAAC,MAAM,CAAA;QAC3C,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,mBAAQ,CAAC,CAAA;QACvC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;QACtB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAA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;AACrB,CAAC"}
@@ -18,11 +18,13 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
18
18
  __exportStar(require("./id-rule"), exports);
19
19
  __exportStar(require("./id-rule-patch"), exports);
20
20
  __exportStar(require("./new-id-rule"), exports);
21
+ __exportStar(require("./sequence"), exports);
21
22
  exports.IdRuleResolver = (0, graphql_tag_1.default) `
22
23
  extend type Mutation {
23
24
  createIdRule(idRule: NewIdRule!): IdRule
24
25
 
25
26
  updateIdRule(type: String!, patch: IdRulePatch): IdRule
27
+ upsertSequence(pattern: String!, counter: Int): Sequence
26
28
  }
27
29
 
28
30
  extend type Query {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/graphql/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,4CAAyB;AACzB,kDAA+B;AAC/B,gDAA6B;AAEhB,QAAA,cAAc,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;CAUhC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/graphql/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,4CAAyB;AACzB,kDAA+B;AAC/B,gDAA6B;AAC7B,6CAA0B;AAEb,QAAA,cAAc,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;CAWhC,CAAA"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Sequence = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ exports.Sequence = (0, graphql_tag_1.default) `
9
+ type Sequence {
10
+ id: String
11
+ pattern: String
12
+ seq: String
13
+ expiresAt: String
14
+ createdAt: String
15
+ updatedAt: String
16
+ }
17
+ `;
18
+ //# sourceMappingURL=sequence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequence.js","sourceRoot":"","sources":["../../../server/graphql/types/sequence.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,QAAQ,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;CAS1B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/id-rule-base",
3
- "version": "3.6.33",
3
+ "version": "3.6.38",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,14 +24,14 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/grist-ui": "^3.6.33",
28
- "@things-factory/i18n-base": "^3.6.33",
29
- "@things-factory/setting-base": "^3.6.33",
30
- "@things-factory/shell": "^3.6.33",
27
+ "@things-factory/grist-ui": "^3.6.37",
28
+ "@things-factory/i18n-base": "^3.6.38",
29
+ "@things-factory/setting-base": "^3.6.38",
30
+ "@things-factory/shell": "^3.6.38",
31
31
  "codemirror": "^5.59.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/codemirror": "^0.0.105"
35
35
  },
36
- "gitHead": "965ef2f6fdc604b4f800e4d01337a3814b3b0d21"
36
+ "gitHead": "95b6401d665c7625d1e5f9e78925571b2fca1cdc"
37
37
  }
@@ -1,6 +1,7 @@
1
- import { idRuleResolver } from './id-rule'
2
1
  import { createIdRule } from './create-id-rule'
2
+ import { idRuleResolver } from './id-rule'
3
3
  import { updateIdRule } from './update-id-rule'
4
+ import { upsertSequence } from './update-insert-sequence'
4
5
 
5
6
  export const IdRuleResolver = {
6
7
  Query: {
@@ -8,6 +9,7 @@ export const IdRuleResolver = {
8
9
  },
9
10
  Mutation: {
10
11
  ...createIdRule,
11
- ...updateIdRule
12
+ ...updateIdRule,
13
+ ...upsertSequence
12
14
  }
13
15
  }
@@ -0,0 +1,48 @@
1
+ import { getRepository } from 'typeorm'
2
+
3
+ import { Domain } from '@things-factory/shell'
4
+
5
+ import { Sequence } from '../../entities'
6
+
7
+ export const upsertSequence = {
8
+ async upsertSequence(_: any, { pattern, counter }, context: any) {
9
+ const domain: Domain = context.state.domain
10
+ const seqRepo = getRepository(Sequence)
11
+ const now = new Date()
12
+ const expiresAt = new Date(now.setMonth(now.getMonth() + 12))
13
+
14
+ pattern = `${pattern} [${getDateStr()}]`
15
+
16
+ const foundSeq = await seqRepo.findOne({
17
+ where: { pattern, domain }
18
+ })
19
+
20
+ if (foundSeq) {
21
+ return await seqRepo.save({
22
+ ...foundSeq,
23
+ seq: counter ? foundSeq.seq + counter : foundSeq.seq + 1,
24
+ expiresAt
25
+ })
26
+ } else {
27
+ return await seqRepo.save({
28
+ domain,
29
+ pattern,
30
+ seq: 1,
31
+ expiresAt
32
+ })
33
+ }
34
+ }
35
+ }
36
+
37
+ function getDateStr() {
38
+ const today = new Date()
39
+ const year = today.getFullYear()
40
+ const month = today.getMonth()
41
+ const day = today.getDate()
42
+
43
+ const yy = String(year).substr(String(year).length - 2)
44
+ const mm = String(month + 1).padStart(2, '0')
45
+ const dd = String(day).padStart(2, '0')
46
+
47
+ return yy + mm + dd
48
+ }
@@ -3,12 +3,14 @@ import gql from 'graphql-tag'
3
3
  export * from './id-rule'
4
4
  export * from './id-rule-patch'
5
5
  export * from './new-id-rule'
6
+ export * from './sequence'
6
7
 
7
8
  export const IdRuleResolver = gql`
8
9
  extend type Mutation {
9
10
  createIdRule(idRule: NewIdRule!): IdRule
10
11
 
11
12
  updateIdRule(type: String!, patch: IdRulePatch): IdRule
13
+ upsertSequence(pattern: String!, counter: Int): Sequence
12
14
  }
13
15
 
14
16
  extend type Query {
@@ -0,0 +1,12 @@
1
+ import gql from 'graphql-tag'
2
+
3
+ export const Sequence = gql`
4
+ type Sequence {
5
+ id: String
6
+ pattern: String
7
+ seq: String
8
+ expiresAt: String
9
+ createdAt: String
10
+ updatedAt: String
11
+ }
12
+ `