@lyxa.ai/core 1.1.40 → 1.1.41

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.
@@ -57,7 +57,7 @@ exports.Category = Category = __decorate([
57
57
  (0, typegoose_1.index)({ nameNormalized: 1, itemType: 1 }, {
58
58
  unique: true,
59
59
  partialFilterExpression: {
60
- itemType: { $in: [enum_1.ItemType.GROCERY, enum_1.ItemType.PHARMACY] },
60
+ itemType: { $in: [enum_1.ItemType.GROCERY, enum_1.ItemType.PET] },
61
61
  parentCategory: null,
62
62
  deletedAt: null,
63
63
  },
@@ -1 +1 @@
1
- {"version":3,"file":"category.model.js","sourceRoot":"/","sources":["libraries/mongo/models/category.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA8E;AAC9E,4EAAqE;AACrE,kDAA2D;AAC3D,8EAAyE;AAgBlE,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,2BAAU;IAEhC,IAAI,CAAU;IAGd,cAAc,CAAU;IAGxB,KAAK,CAAU;IAGf,QAAQ,CAAY;IAGpB,cAAc,CAAiB;IAG/B,MAAM,CAAU;IAGhB,IAAI,CAAU;CACrB,CAAA;AArBY,4BAAQ;AAEb;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;;sCAC7C;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;gDACpC;AAGxB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;uCACD;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAQ,EAAE,CAAC;;0CAC5B;AAGpB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;;gDACQ;AAG/B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAM,EAAE,OAAO,EAAE,aAAM,CAAC,MAAM,EAAE,CAAC;;wCACtC;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;;sCAClB;mBApBT,QAAQ;IAdpB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,CAAC;IAC7D,IAAA,iBAAK,EACL,EAAE,cAAc,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAClC;QACC,MAAM,EAAE,IAAI;QACZ,uBAAuB,EAAE;YACxB,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,eAAQ,CAAC,OAAO,EAAE,eAAQ,CAAC,QAAQ,CAAC,EAAE;YACxD,cAAc,EAAE,IAAI;YACpB,SAAS,EAAE,IAAI;SACf;KACD,CACD;IACA,IAAA,iBAAK,EAAC,EAAE,cAAc,EAAE,CAAC,EAAE,EAAE,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;IAC9E,IAAA,kBAAM,EAAC,6CAAoB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;GACnC,QAAQ,CAqBpB","sourcesContent":["import { index, modelOptions, plugin, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { ItemType, Status } from '../../../utilities/enum';\nimport { normalizeFieldPlugin } from '../plugins/normalize-field.plugin';\n\n@modelOptions({ schemaOptions: { collection: 'categories' } })\n@index(\n\t{ nameNormalized: 1, itemType: 1 },\n\t{\n\t\tunique: true,\n\t\tpartialFilterExpression: {\n\t\t\titemType: { $in: [ItemType.GROCERY, ItemType.PHARMACY] },\n\t\t\tparentCategory: null,\n\t\t\tdeletedAt: null,\n\t\t},\n\t}\n)\n@index({ nameNormalized: 1 }, { partialFilterExpression: { deletedAt: null } })\n@plugin(normalizeFieldPlugin, { field: 'name' })\nexport class Category extends TimeStamps {\n\t@prop({ required: true, type: String, trim: true, maxlength: 30 })\n\tpublic name!: string;\n\n\t@prop({ type: String, trim: true, lowercase: true, select: false })\n\tpublic nameNormalized?: string;\n\n\t@prop({ type: String })\n\tpublic image?: string;\n\n\t@prop({ required: true, type: String, enum: ItemType })\n\tpublic itemType!: ItemType;\n\n\t@prop({ ref: () => Category })\n\tpublic parentCategory?: Ref<Category>;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: String, maxlength: 250 })\n\tpublic note?: string;\n}\n"]}
1
+ {"version":3,"file":"category.model.js","sourceRoot":"/","sources":["libraries/mongo/models/category.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA8E;AAC9E,4EAAqE;AACrE,kDAA2D;AAC3D,8EAAyE;AAgBlE,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,2BAAU;IAEhC,IAAI,CAAU;IAGd,cAAc,CAAU;IAGxB,KAAK,CAAU;IAGf,QAAQ,CAAY;IAGpB,cAAc,CAAiB;IAG/B,MAAM,CAAU;IAGhB,IAAI,CAAU;CACrB,CAAA;AArBY,4BAAQ;AAEb;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;;sCAC7C;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;gDACpC;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aultClasses';\nimport { ItemType, Status } from '../../../utilities/enum';\nimport { normalizeFieldPlugin } from '../plugins/normalize-field.plugin';\n\n@modelOptions({ schemaOptions: { collection: 'categories' } })\n@index(\n\t{ nameNormalized: 1, itemType: 1 },\n\t{\n\t\tunique: true,\n\t\tpartialFilterExpression: {\n\t\t\titemType: { $in: [ItemType.GROCERY, ItemType.PET] },\n\t\t\tparentCategory: null,\n\t\t\tdeletedAt: null,\n\t\t},\n\t}\n)\n@index({ nameNormalized: 1 }, { partialFilterExpression: { deletedAt: null } })\n@plugin(normalizeFieldPlugin, { field: 'name' })\nexport class Category extends TimeStamps {\n\t@prop({ required: true, type: String, trim: true, maxlength: 30 })\n\tpublic name!: string;\n\n\t@prop({ type: String, trim: true, lowercase: true, select: false })\n\tpublic nameNormalized?: string;\n\n\t@prop({ type: String })\n\tpublic image?: string;\n\n\t@prop({ required: true, type: String, enum: ItemType })\n\tpublic itemType!: ItemType;\n\n\t@prop({ ref: () => Category })\n\tpublic parentCategory?: Ref<Category>;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: String, maxlength: 250 })\n\tpublic note?: string;\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.1.40
25
+ Version: 1.1.41
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -7,15 +7,17 @@ function getNextCore(currentCore) {
7
7
  if (!match)
8
8
  throw new Error(`Invalid core format: ${currentCore}`);
9
9
  let [, letterPart, numberPart] = match;
10
- const numberLength = numberPart.length;
10
+ let numberLength = numberPart.length;
11
11
  let number = parseInt(numberPart, 10);
12
12
  number++;
13
- if (number > Number('9'.repeat(numberLength))) {
13
+ if (number > parseInt('9'.repeat(numberLength))) {
14
14
  number = 1;
15
+ const oldLetters = letterPart;
15
16
  letterPart = incrementLetters(letterPart);
16
- if (letterPart.length > match[1].length && numberLength > 1) {
17
- return `${letterPart}${number.toString().padStart(numberLength - 1, '0')}`;
17
+ if (letterPart === 'A' && oldLetters.split('').every(c => c === 'Z')) {
18
+ numberLength += 1;
18
19
  }
20
+ return `${letterPart}${number.toString().padStart(numberLength, '0')}`;
19
21
  }
20
22
  return `${letterPart}${number.toString().padStart(numberLength, '0')}`;
21
23
  }
@@ -23,18 +25,17 @@ function incrementLetters(letters) {
23
25
  const chars = letters.split('');
24
26
  let carry = true;
25
27
  for (let i = chars.length - 1; i >= 0 && carry; i--) {
26
- const c = chars[i];
27
- if (c === 'Z') {
28
+ if (chars[i] === 'Z') {
28
29
  chars[i] = 'A';
29
30
  carry = true;
30
31
  }
31
32
  else {
32
- chars[i] = String.fromCharCode(c.charCodeAt(0) + 1);
33
+ chars[i] = String.fromCharCode(chars[i].charCodeAt(0) + 1);
33
34
  carry = false;
34
35
  }
35
36
  }
36
37
  if (carry)
37
- chars.unshift('A');
38
+ return 'A';
38
39
  return chars.join('');
39
40
  }
40
41
  function getPrefixForType(counterType) {
@@ -1 +1 @@
1
- {"version":3,"file":"id-generator.js","sourceRoot":"/","sources":["utilities/id-generator.ts"],"names":[],"mappings":";;AAwDA,gCAuBC;AA/ED,iCAAqC;AAErC,SAAS,WAAW,CAAC,WAAmB;IACvC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC;IAEnE,IAAI,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IACvC,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC;IACv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EAClC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAC5B,EAAE,GAAG,EAAE,KAAK,EAAE,CACd,CAAC,IAAI,EAAE,CAAC;IAET,IAAI,CAAC,UAAU;QAAE,OAAO,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAE9D,OAAO,GAAG,MAAM,GAAG,WAAW,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { CounterType } from './enum';\n\nfunction getNextCore(currentCore: string): string {\n\tconst match = currentCore.match(/^([A-Z]+)(\\d+)$/);\n\tif (!match) throw new Error(`Invalid core format: ${currentCore}`);\n\n\tlet [, letterPart, numberPart] = match;\n\tconst numberLength = numberPart.length;\n\tlet number = parseInt(numberPart, 10);\n\n\tnumber++;\n\n\tif (number > Number('9'.repeat(numberLength))) {\n\t\tnumber = 1;\n\t\tletterPart = incrementLetters(letterPart);\n\n\t\t// When letter length expands (Z AA), reduce digit length\n\t\tif (letterPart.length > match[1].length && numberLength > 1) {\n\t\t\treturn `${letterPart}${number.toString().padStart(numberLength - 1, '0')}`;\n\t\t}\n\t}\n\n\treturn `${letterPart}${number.toString().padStart(numberLength, '0')}`;\n}\n\nfunction incrementLetters(letters: string): string {\n\tconst chars = letters.split('');\n\tlet carry = true;\n\n\tfor (let i = chars.length - 1; i >= 0 && carry; i--) {\n\t\tconst c = chars[i];\n\t\tif (c === 'Z') {\n\t\t\tchars[i] = 'A';\n\t\t\tcarry = true;\n\t\t} else {\n\t\t\tchars[i] = String.fromCharCode(c.charCodeAt(0) + 1);\n\t\t\tcarry = false;\n\t\t}\n\t}\n\n\tif (carry) chars.unshift('A');\n\treturn chars.join('');\n}\n\nfunction getPrefixForType(counterType: CounterType): string {\n\tconst prefixMap: any = {\n\t\t[CounterType.USER]: 'U',\n\t\t[CounterType.RIDER]: 'R',\n\t\t[CounterType.PARENT]: 'P',\n\t\t[CounterType.SHOP]: 'S',\n\t\t[CounterType.ITEM]: 'I',\n\t\t[CounterType.TRANSACTION]: 'T',\n\t};\n\treturn prefixMap[counterType];\n}\n\nexport async function generateId(CounterModel: any, counterType: CounterType): Promise<string> {\n\tconst prefix = getPrefixForType(counterType);\n\tconst initialCore = 'A0001';\n\n\tlet counterDoc = await CounterModel.findOne({ counterType }).lean();\n\n\tif (!counterDoc) {\n\t\tawait CounterModel.create({ counterType, core: initialCore });\n\t\tcounterDoc = { core: initialCore };\n\t}\n\n\tconst currentCore = counterDoc.core;\n\tconst nextCore = getNextCore(currentCore);\n\n\tconst updatedDoc = await CounterModel.findOneAndUpdate(\n\t\t{ counterType, core: currentCore },\n\t\t{ $set: { core: nextCore } },\n\t\t{ new: false }\n\t).lean();\n\n\tif (!updatedDoc) return generateId(CounterModel, counterType); // Retry if conflict\n\n\treturn `${prefix}${currentCore}`;\n}\n"]}
1
+ {"version":3,"file":"id-generator.js","sourceRoot":"/","sources":["utilities/id-generator.ts"],"names":[],"mappings":";;AA6DA,gCAuBC;AApFD,iCAAqC;AAErC,SAAS,WAAW,CAAC,WAAmB;IACvC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC;IAEnE,IAAI,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IACvC,IAAI,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC;IACrC,IAAI,MAAM,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAEtC,MAAM,EAAE,CAAC;IAET,IAAI,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;QACjD,MAAM,GAAG,CAAC,CAAC;QACX,MAAM,UAAU,GAAG,UAAU,CAAC;QAC9B,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAG1C,IAAI,UAAU,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C,CAAC","sourcesContent":["import { CounterType } from './enum';\n\nfunction getNextCore(currentCore: string): string {\n\tconst match = currentCore.match(/^([A-Z]+)(\\d+)$/);\n\tif (!match) throw new Error(`Invalid core format: ${currentCore}`);\n\n\tlet [, letterPart, numberPart] = match;\n\tlet numberLength = numberPart.length;\n\tlet number = parseInt(numberPart, 10);\n\n\tnumber++;\n\n\tif (number > parseInt('9'.repeat(numberLength))) {\n\t\tnumber = 1;\n\t\tconst oldLetters = letterPart;\n\t\tletterPart = incrementLetters(letterPart);\n\n\t\t// All letters were Z, need to increase digit length\n\t\tif (letterPart === 'A' && oldLetters.split('').every(c => c === 'Z')) {\n\t\t\tnumberLength += 1;\n\t\t}\n\n\t\treturn `${letterPart}${number.toString().padStart(numberLength, '0')}`;\n\t}\n\n\treturn `${letterPart}${number.toString().padStart(numberLength, '0')}`;\n}\n\nfunction incrementLetters(letters: string): string {\n\tconst chars = letters.split('');\n\tlet carry = true;\n\n\tfor (let i = chars.length - 1; i >= 0 && carry; i--) {\n\t\tif (chars[i] === 'Z') {\n\t\t\tchars[i] = 'A';\n\t\t\tcarry = true;\n\t\t} else {\n\t\t\tchars[i] = String.fromCharCode(chars[i].charCodeAt(0) + 1);\n\t\t\tcarry = false;\n\t\t}\n\t}\n\n\t// overflow all Z's -> back to A\n\tif (carry) return 'A';\n\n\treturn chars.join('');\n}\n\n\nfunction getPrefixForType(counterType: CounterType): string {\n\tconst prefixMap: any = {\n\t\t[CounterType.USER]: 'U',\n\t\t[CounterType.RIDER]: 'R',\n\t\t[CounterType.PARENT]: 'P',\n\t\t[CounterType.SHOP]: 'S',\n\t\t[CounterType.ITEM]: 'I',\n\t\t[CounterType.TRANSACTION]: 'T',\n\t};\n\treturn prefixMap[counterType];\n}\n\nexport async function generateId(CounterModel: any, counterType: CounterType): Promise<string> {\n\tconst prefix = getPrefixForType(counterType);\n\tconst initialCore = 'A0001';\n\n\tlet counterDoc = await CounterModel.findOne({ counterType }).lean();\n\n\tif (!counterDoc) {\n\t\tawait CounterModel.create({ counterType, core: initialCore });\n\t\tcounterDoc = { core: initialCore };\n\t}\n\n\tconst currentCore = counterDoc.core;\n\tconst nextCore = getNextCore(currentCore);\n\n\tconst updatedDoc = await CounterModel.findOneAndUpdate(\n\t\t{ counterType, core: currentCore },\n\t\t{ $set: { core: nextCore } },\n\t\t{ new: false }\n\t).lean();\n\n\tif (!updatedDoc) return generateId(CounterModel, counterType); // Retry if conflict\n\n\treturn `${prefix}${currentCore}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",