@things-factory/id-rule-base 9.1.13 → 10.0.0-beta.1

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,5 +1,4 @@
1
1
  import { Domain } from '@things-factory/shell';
2
- import 'ses';
3
2
  type getNextArgs = {
4
3
  domain: Domain;
5
4
  pattern: string;
@@ -6,7 +6,6 @@ const typeorm_1 = require("typeorm");
6
6
  const shell_1 = require("@things-factory/shell");
7
7
  const id_rule_1 = require("../service/id-rule/id-rule");
8
8
  const sequence_1 = require("../service/sequence/sequence");
9
- require("ses");
10
9
  async function generateId({ domain, type, seed }) {
11
10
  const idRuleRepo = (0, shell_1.getRepository)(id_rule_1.IdRule);
12
11
  const rule = await idRuleRepo.findOne({
@@ -17,16 +16,11 @@ async function generateId({ domain, type, seed }) {
17
16
  });
18
17
  if (!rule)
19
18
  throw Error('Rule not found');
20
- const compartment = new Compartment({
21
- domain,
22
- seed,
23
- console
24
- });
25
19
  let evalFunc;
26
20
  try {
27
- evalFunc = compartment.evaluate(`(async (domain, seed, getNext) => {
21
+ evalFunc = new Function('domain', 'seed', 'console', `return (async (domain, seed, getNext) => {
28
22
  ${rule.rule}
29
- })`);
23
+ })`)(domain, seed, console);
30
24
  }
31
25
  catch (err) {
32
26
  throw new Error(`Failed to evaluate rule: ${err.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../server/controllers/id-generator.ts"],"names":[],"mappings":";;AAYA,gCAgCC;AAED,0BA4BC;AA1ED,qCAAkC;AAClC,iDAA6D;AAC7D,wDAAmD;AACnD,2DAAuD;AACvD,eAAY;AAQL,KAAK,UAAU,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;IACrD,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,gBAAM,CAAC,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;QACpC,KAAK,EA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AAC;QACT,IAAI,CAAC,GAAG,EAAE,CAAA;QACV,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,cAAc;YAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;QAErD,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,MAAM;YACN,OAAO;YACP,GAAG,EAAE,CAAC;YACN,SAAS;SACV,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAA;AACjB,CAAC","sourcesContent":["import { MoreThan } from 'typeorm'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { IdRule } from '../service/id-rule/id-rule'\nimport { Sequence } from '../service/sequence/sequence'\nimport 'ses'\n\ntype getNextArgs = {\n domain: Domain\n pattern: string\n expirationDate?: Date\n}\n\nexport async function generateId({ domain, type, seed }) {\n const idRuleRepo = getRepository(IdRule)\n const rule = await idRuleRepo.findOne({\n where: {\n domain: { id: domain.id },\n type\n }\n })\n\n if (!rule) throw Error('Rule not found')\n\n const compartment = new Compartment({\n domain,\n seed,\n console\n })\n\n let evalFunc\n try {\n evalFunc = compartment.evaluate(`(async (domain, seed, getNext) => {\n ${rule.rule}\n })`)\n } catch (err) {\n throw new Error(`Failed to evaluate rule: ${err.message}`)\n }\n\n const nextId = await evalFunc(domain, {\n ...seed,\n },\n getNext)\n\n return nextId\n}\n\nexport async function getNext({ domain, pattern, expirationDate }: getNextArgs) {\n const seqRepo = getRepository(Sequence)\n const now = new Date()\n let last = await seqRepo.findOneBy({\n domain: { id: domain.id },\n pattern,\n expiresAt: MoreThan(now)\n })\n\n var expiresAt = expirationDate\n if (!expirationDate) expiresAt = new Date(now.setMonth(now.getMonth() + 6))\n\n if (last) {\n last.seq++\n last.expiresAt = expiresAt\n await seqRepo.save(last)\n } else {\n if (!expirationDate) now.setMonth(now.getMonth() + 6)\n\n last = await seqRepo.save({\n domain,\n pattern,\n seq: 1,\n expiresAt\n })\n }\n\n return last.seq\n}\n"]}
1
+ {"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../server/controllers/id-generator.ts"],"names":[],"mappings":";;AAWA,gCA+BC;AAED,0BA4BC;AAxED,qCAAkC;AAClC,iDAA6D;AAC7D,wDAAmD;AACnD,2DAAuD;AAQhD,KAAK,UAAU,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;IACrD,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,gBAAM,CAAC,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;QACpC,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACzB,IAAI;SACL;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,IAAI;QAAE,MAAM,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAExC,IAAI,QAAQ,CAAA;IACZ,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,QAAQ,CACrB,QAAQ,EACR,MAAM,EACN,SAAS,EACT;QACE,IAAI,CAAC,IAAI;OACV,CACF,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE;QACpC,GAAG,IAAI;KACR,EACD,OAAO,CAAC,CAAA;IAER,OAAO,MAAM,CAAA;AACf,CAAC;AAEM,KAAK,UAAU,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAe;IAC5E,MAAM,OAAO,GAAG,IAAA,qBAAa,EAAC,mBAAQ,CAAC,CAAA;IACvC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,IAAI,IAAI,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;QACzB,OAAO;QACP,SAAS,EAAE,IAAA,kBAAQ,EAAC,GAAG,CAAC;KACzB,CAAC,CAAA;IAEF,IAAI,SAAS,GAAG,cAAc,CAAA;IAC9B,IAAI,CAAC,cAAc;QAAE,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IAE3E,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,CAAC,GAAG,EAAE,CAAA;QACV,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,cAAc;YAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;QAErD,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,MAAM;YACN,OAAO;YACP,GAAG,EAAE,CAAC;YACN,SAAS;SACV,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAA;AACjB,CAAC","sourcesContent":["import { MoreThan } from 'typeorm'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { IdRule } from '../service/id-rule/id-rule'\nimport { Sequence } from '../service/sequence/sequence'\n\ntype getNextArgs = {\n domain: Domain\n pattern: string\n expirationDate?: Date\n}\n\nexport async function generateId({ domain, type, seed }) {\n const idRuleRepo = getRepository(IdRule)\n const rule = await idRuleRepo.findOne({\n where: {\n domain: { id: domain.id },\n type\n }\n })\n\n if (!rule) throw Error('Rule not found')\n\n let evalFunc\n try {\n evalFunc = new Function(\n 'domain',\n 'seed',\n 'console',\n `return (async (domain, seed, getNext) => {\n ${rule.rule}\n })`\n )(domain, seed, console)\n } catch (err) {\n throw new Error(`Failed to evaluate rule: ${err.message}`)\n }\n\n const nextId = await evalFunc(domain, {\n ...seed,\n },\n getNext)\n\n return nextId\n}\n\nexport async function getNext({ domain, pattern, expirationDate }: getNextArgs) {\n const seqRepo = getRepository(Sequence)\n const now = new Date()\n let last = await seqRepo.findOneBy({\n domain: { id: domain.id },\n pattern,\n expiresAt: MoreThan(now)\n })\n\n var expiresAt = expirationDate\n if (!expirationDate) expiresAt = new Date(now.setMonth(now.getMonth() + 6))\n\n if (last) {\n last.seq++\n last.expiresAt = expiresAt\n await seqRepo.save(last)\n } else {\n if (!expirationDate) now.setMonth(now.getMonth() + 6)\n\n last = await seqRepo.save({\n domain,\n pattern,\n seq: 1,\n expiresAt\n })\n }\n\n return last.seq\n}\n"]}
@@ -2,7 +2,7 @@ export * from './id-rule/id-rule';
2
2
  export * from './id-rule/id-rule-types';
3
3
  export * from './sequence/sequence';
4
4
  export * from './doc-number/doc-number';
5
- export declare const entities: (typeof import("./id-rule/id-rule").IdRule | typeof import("./sequence/sequence").Sequence | typeof import("./doc-number/doc-number").DocNumber)[];
5
+ export declare const entities: (typeof import("./sequence/sequence").Sequence | typeof import("./id-rule/id-rule").IdRule | typeof import("./doc-number/doc-number").DocNumber)[];
6
6
  export declare const schema: {
7
7
  resolverClasses: (typeof import("./id-rule/id-rule-mutation").IdRuleMutation | typeof import("./id-rule/id-rule-query").IdRuleQuery | typeof import("./sequence/sequence-mutation").SequenceMutation | typeof import("./doc-number/doc-number-query").DocNumberQuery | typeof import("./doc-number/doc-number-mutation").DocNumberMutation)[];
8
8
  };