@talkpilot/core-db 1.0.18 → 1.0.19

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,4 +1,4 @@
1
1
  export * from './instructions.getters';
2
2
  export * from './instructions.setters';
3
- export type { SystemInstruction } from './instructions.types';
3
+ export type { MIS_SystemInstruction, MIS_Tool, QueryType } from './instructions.types';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,YAAY,EAAE,qBAAqB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,30 +1,30 @@
1
1
  import { CityName } from '../index';
2
2
  import { Collection, Filter } from 'mongodb';
3
- import { SystemInstruction } from './instructions.types';
4
- export declare const getSystemInstructionsCollection: () => Collection<SystemInstruction>;
3
+ import { MIS_SystemInstruction, MIS_Tool } from './instructions.types';
4
+ export declare const getSystemInstructionsCollection: () => Collection<MIS_SystemInstruction>;
5
5
  /**
6
6
  * Find system instructions by filter
7
7
  * @param filter filter to apply
8
8
  * @returns array of system instructions
9
9
  */
10
- export declare const findSystemInstructions: (filter?: Filter<SystemInstruction>) => Promise<SystemInstruction[]>;
10
+ export declare const findSystemInstructions: (filter?: Filter<MIS_SystemInstruction>) => Promise<MIS_SystemInstruction[]>;
11
11
  /**
12
12
  * Get system instruction by id
13
13
  * @param id system instruction id
14
14
  * @returns system instruction or null if not found
15
15
  */
16
- export declare const getSystemInstructionById: (id: string) => Promise<SystemInstruction | null>;
16
+ export declare const getSystemInstructionById: (id: string) => Promise<MIS_SystemInstruction | null>;
17
17
  /**
18
18
  * Get all active system instructions for a city
19
19
  * @param cityName city name
20
20
  * @returns array of active system instructions
21
21
  */
22
- export declare const getActiveSystemInstructionsByCity: (cityName: CityName) => Promise<SystemInstruction[]>;
22
+ export declare const getActiveSystemInstructionsByCity: (cityName: CityName) => Promise<MIS_SystemInstruction[]>;
23
23
  /**
24
24
  * Get system instructions by tool and city
25
25
  * @param cityName city name
26
26
  * @param toolName tool name
27
27
  * @returns array of system instructions
28
28
  */
29
- export declare const getSystemInstructionsByToolAndCity: (cityName: CityName, toolName: string) => Promise<SystemInstruction[]>;
29
+ export declare const getSystemInstructionsByToolAndCity: (cityName: CityName, toolName: MIS_Tool) => Promise<MIS_SystemInstruction[]>;
30
30
  //# sourceMappingURL=instructions.getters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAkB,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,eAAO,MAAM,+BAA+B,QAAO,UAAU,CAAC,iBAAiB,CAE9E,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAQ,MAAM,CAAC,iBAAiB,CAAM,KACrC,OAAO,CAAC,iBAAiB,EAAE,CAE7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAE3F,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,iBAAiB,EAAE,CAEvG,CAAA;AACD;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,GAAU,UAAU,QAAQ,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,iBAAiB,EAAE,CAE1H,CAAA"}
1
+ {"version":3,"file":"instructions.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAkB,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEvE,eAAO,MAAM,+BAA+B,QAAO,UAAU,CAAC,qBAAqB,CAElF,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAQ,MAAM,CAAC,qBAAqB,CAAM,KACzC,OAAO,CAAC,qBAAqB,EAAE,CAEjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAE/F,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,qBAAqB,EAAE,CAE3G,CAAA;AACD;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,GAAU,UAAU,QAAQ,EAAE,UAAU,QAAQ,KAAG,OAAO,CAAC,qBAAqB,EAAE,CAEhI,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.getters.js","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.getters.ts"],"names":[],"mappings":";;;AAAA,oCAAmD;AAI5C,MAAM,+BAA+B,GAAG,GAAkC,EAAE;IACjF,OAAO,IAAA,aAAK,GAAE,CAAC,UAAU,CAAoB,qBAAqB,CAAC,CAAC;AACtE,CAAC,CAAC;AAFW,QAAA,+BAA+B,mCAE1C;AACF;;;;GAIG;AACI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,mCAE1C;AACF;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,SAAwC,EAAE,EACR,EAAE;IACpC,OAAO,MAAM,IAAA,uCAA+B,GAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;AACxE,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC;AAEF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAAU,EAAyC,EAAE;IAClG,OAAO,MAAM,IAAA,uCAA+B,GAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACpF,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC;AACD;;;;GAIG;AACI,MAAM,iCAAiC,GAAG,KAAK,EAAE,QAAkB,EAAoC,EAAE;IAC9G,OAAO,MAAM,IAAA,uCAA+B,GAAE,CAAC,IAAI,CAAC,EAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAC5F,CAAC,CAAA;AAFY,QAAA,iCAAiC,qCAE7C;AACD;;;;;GAKG;AACI,MAAM,kCAAkC,GAAG,KAAK,EAAE,QAAkB,EAAE,QAAkB,EAAoC,EAAE;IACnI,OAAO,MAAM,IAAA,uCAA+B,GAAE,CAAC,IAAI,CAAC,EAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACtG,CAAC,CAAA;AAFY,QAAA,kCAAkC,sCAE9C"}
@@ -1,18 +1,18 @@
1
1
  import { ObjectId as MongoObjectId } from 'mongodb';
2
- import { SystemInstruction } from './instructions.types';
2
+ import { MIS_SystemInstruction } from './instructions.types';
3
3
  /**
4
4
  * Create a new system instruction
5
5
  * @param instructionData system instruction data
6
6
  * @returns inserted system instruction id
7
7
  */
8
- export declare const createSystemInstruction: (instructionData: Omit<SystemInstruction, "_id" | "createdAt" | "updatedAt">) => Promise<MongoObjectId>;
8
+ export declare const createSystemInstruction: (instructionData: Omit<MIS_SystemInstruction, "_id" | "createdAt" | "updatedAt">) => Promise<MongoObjectId>;
9
9
  /**
10
10
  * Update a system instruction by id
11
11
  * @param id system instruction id
12
12
  * @param data partial system instruction data
13
13
  * @returns updated system instruction or null if not found
14
14
  */
15
- export declare const updateSystemInstruction: (id: string, data: Partial<Omit<SystemInstruction, "_id" | "createdAt" | "updatedAt">>) => Promise<SystemInstruction | null>;
15
+ export declare const updateSystemInstruction: (id: string, data: Partial<Omit<MIS_SystemInstruction, "_id" | "createdAt" | "updatedAt">>) => Promise<MIS_SystemInstruction | null>;
16
16
  /**
17
17
  * Delete a system instruction by id
18
18
  * @param id system instruction id
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.setters.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.setters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,iBAAiB,IAAI,CAAC,iBAAiB,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,KAC1E,OAAO,CAAC,aAAa,CAUvB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,MAAM,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,KACxE,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAOlC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAGzE,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAO3E,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAO7E,CAAA"}
1
+ {"version":3,"file":"instructions.setters.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.setters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAA0B,MAAM,sBAAsB,CAAC;AAiBrF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,iBAAiB,IAAI,CAAC,qBAAqB,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,KAC9E,OAAO,CAAC,aAAa,CAWvB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,MAAM,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,KAC5E,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAQtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAGzE,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAO3E,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAU,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAO7E,CAAA"}
@@ -2,13 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deactivateSystemInstruction = exports.activateSystemInstruction = exports.deleteSystemInstruction = exports.updateSystemInstruction = exports.createSystemInstruction = void 0;
4
4
  const index_1 = require("../index");
5
+ const instructions_types_1 = require("./instructions.types");
5
6
  const instructions_getters_1 = require("./instructions.getters");
7
+ /**
8
+ * Validate system instruction data
9
+ * @param data partial system instruction data
10
+ * @throws Error if tool or queryType is invalid
11
+ */
12
+ const validateInstructionData = (data) => {
13
+ if (data.tool && !Object.values(instructions_types_1.MIS_TOOLS).includes(data.tool)) {
14
+ throw new Error(`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(instructions_types_1.MIS_TOOLS).join(', ')}`);
15
+ }
16
+ if (data.queryType && !Object.values(instructions_types_1.QUERY_TYPES).includes(data.queryType)) {
17
+ throw new Error(`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(instructions_types_1.QUERY_TYPES).join(', ')}`);
18
+ }
19
+ };
6
20
  /**
7
21
  * Create a new system instruction
8
22
  * @param instructionData system instruction data
9
23
  * @returns inserted system instruction id
10
24
  */
11
25
  const createSystemInstruction = async (instructionData) => {
26
+ validateInstructionData(instructionData);
12
27
  const instruction = {
13
28
  ...instructionData,
14
29
  createdAt: new Date(),
@@ -25,6 +40,7 @@ exports.createSystemInstruction = createSystemInstruction;
25
40
  * @returns updated system instruction or null if not found
26
41
  */
27
42
  const updateSystemInstruction = async (id, data) => {
43
+ validateInstructionData(data);
28
44
  const result = await (0, instructions_getters_1.getSystemInstructionsCollection)().findOneAndUpdate({ _id: new index_1.ObjectId(id) }, { $set: { ...data, updatedAt: new Date() } }, { returnDocument: 'after' });
29
45
  return result || null;
30
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.setters.js","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.setters.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AAGpC,iEAAyE;AAEzE;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,eAA2E,EACnD,EAAE;IAC1B,MAAM,WAAW,GAAmC;QAClD,GAAG,eAAe;QAClB,SAAS,EAAE,IAAI,IAAI,EAAE;QACrB,SAAS,EAAE,IAAI,IAAI,EAAE;KACtB,CAAC;IACF,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,sDAA+B,GAAE,C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yBAAyB,6BAOpC;AACF;;;;;GAKG;AACI,MAAM,2BAA2B,GAAG,KAAK,EAAE,EAAU,EAAoB,EAAE;IAChF,MAAM,MAAM,GAAG,MAAM,IAAA,sDAA+B,GAAE,CAAC,gBAAgB,CACrE,EAAE,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC,EAAE,EACzB,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAC3B,EAAC,cAAc,EAAE,OAAO,EAAC,CAC5B,CAAC;IACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAA;AAPY,QAAA,2BAA2B,+BAOvC"}
1
+ {"version":3,"file":"instructions.setters.js","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.setters.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AAEpC,6DAAqF;AACrF,iEAAyE;AAEzE;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,CAAC,IAAoC,EAAE,EAAE;IACvE,IAAI,IAAI,CAAC,IAAI,IAAI,CAAE,MAAM,CAAC,MAAM,CAAC,8BAAS,CAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,yBAAyB,MAAM,CAAC,MAAM,CAAC,8BAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;IACD,IAAI,IAAI,CAAC,SAAS,IAAI,CAAE,MAAM,CAAC,MAAM,CAAC,gCAAW,CAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,SAAS,yBAAyB,MAAM,CAAC,MAAM,CAAC,gCAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9H,CAAC;AACH,CAAC,CAA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AG,KAAK,EAAE,EAAU,EAAoB,EAAE;IAC9E,MAAM,MAAM,GAAG,MAAM,IAAA,sDAA+B,GAAE,CAAC,gBAAgB,CACrE,EAAE,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC,EAAE,EACzB,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAC5B,EAAE,cAAc,EAAE,OAAO,EAAE,CAC5B,CAAC;IACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC;AAPW,QAAA,yBAAyB,6BAOpC;AACF;;;;;GAKG;AACI,MAAM,2BAA2B,GAAG,KAAK,EAAE,EAAU,EAAoB,EAAE;IAChF,MAAM,MAAM,GAAG,MAAM,IAAA,sDAA+B,GAAE,CAAC,gBAAgB,CACrE,EAAE,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC,EAAE,EACzB,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAC3B,EAAC,cAAc,EAAE,OAAO,EAAC,CAC5B,CAAC;IACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAA;AAPY,QAAA,2BAA2B,+BAOvC"}
@@ -1,14 +1,26 @@
1
1
  import { ObjectId } from 'mongodb';
2
2
  import { CityName } from "../utils/types";
3
- export type SystemInstruction = {
3
+ export declare const MIS_TOOLS: {
4
+ readonly findStreet: "findStreet";
5
+ readonly findSubject: "findSubject";
6
+ };
7
+ export declare const QUERY_TYPES: {
8
+ readonly exactlyOne: "exactlyOne";
9
+ readonly any: "any";
10
+ readonly all: "all";
11
+ readonly none: "none";
12
+ };
13
+ export type MIS_Tool = typeof MIS_TOOLS[keyof typeof MIS_TOOLS];
14
+ export type QueryType = typeof QUERY_TYPES[keyof typeof QUERY_TYPES];
15
+ export type MIS_SystemInstruction = {
4
16
  _id: ObjectId;
5
17
  createdAt: Date;
6
18
  updatedAt: Date;
7
19
  cityName: CityName;
8
20
  instruction: string;
9
21
  isActive: boolean;
10
- tool: string;
11
- queryType: string;
22
+ tool: MIS_Tool;
23
+ queryType: QueryType;
12
24
  tags?: string[];
13
25
  };
14
26
  //# sourceMappingURL=instructions.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.types.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC"}
1
+ {"version":3,"file":"instructions.types.d.ts","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC,eAAO,MAAM,SAAS;;;CAGZ,CAAC;AAEX,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAChE,MAAM,MAAM,SAAS,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAErE,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC"}
@@ -1,3 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUERY_TYPES = exports.MIS_TOOLS = void 0;
4
+ exports.MIS_TOOLS = {
5
+ findStreet: 'findStreet',
6
+ findSubject: 'findSubject'
7
+ };
8
+ exports.QUERY_TYPES = {
9
+ exactlyOne: 'exactlyOne',
10
+ any: 'any',
11
+ all: 'all',
12
+ none: 'none'
13
+ };
3
14
  //# sourceMappingURL=instructions.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.types.js","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"instructions.types.js","sourceRoot":"","sources":["../../../src/municipal/systemInstructions/instructions.types.ts"],"names":[],"mappings":";;;AAIa,QAAA,SAAS,GAAG;IACvB,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;CAClB,CAAC;AAEE,QAAA,WAAW,GAAG;IACzB,UAAU,EAAE,YAAY;IACxB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talkpilot/core-db",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Core database package for centralized connections and ORM integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -6,6 +6,7 @@ import {
6
6
  findSystemInstructions
7
7
  } from '../instructions.getters';
8
8
  import { ObjectId } from 'mongodb';
9
+ import { MIS_TOOLS, QUERY_TYPES } from '../instructions.types';
9
10
 
10
11
  describe('System Instructions Getter Tests', () => {
11
12
  const testCity = 'Ashdod';
@@ -19,8 +20,8 @@ describe('System Instructions Getter Tests', () => {
19
20
  cityName: testCity,
20
21
  instruction: 'Find Me',
21
22
  isActive: true,
22
- tool: "search tool",
23
- queryType: "search tool",
23
+ tool: MIS_TOOLS.findSubject,
24
+ queryType: QUERY_TYPES.any,
24
25
  tags: ['important', 'urgent']
25
26
  });
26
27
  instructionId = id.toString();
@@ -30,16 +31,16 @@ describe('System Instructions Getter Tests', () => {
30
31
  cityName: testCity,
31
32
  instruction: 'Inactive One',
32
33
  isActive: false,
33
- tool: "search tool",
34
- queryType: "search tool",
34
+ tool: MIS_TOOLS.findSubject,
35
+ queryType: QUERY_TYPES.any,
35
36
  });
36
37
 
37
38
  await createSystemInstruction({
38
39
  cityName: otherCity,
39
40
  instruction: 'Other City Instruction',
40
41
  isActive: true,
41
- tool: "other tool",
42
- queryType: "other type",
42
+ tool: MIS_TOOLS.findStreet,
43
+ queryType: QUERY_TYPES.exactlyOne,
43
44
  });
44
45
  });
45
46
 
@@ -70,13 +71,13 @@ describe('System Instructions Getter Tests', () => {
70
71
 
71
72
  describe('getSystemInstructionsByToolAndCity', () => {
72
73
  it('given valid city and tool when fetched then return matching instructions', async () => {
73
- const result = await getSystemInstructionsByToolAndCity(testCity, 'search tool');
74
+ const result = await getSystemInstructionsByToolAndCity(testCity, MIS_TOOLS.findSubject);
74
75
  expect(result.length).toBe(2); // One active, one inactive
75
- expect(result.every(r => r.cityName === testCity && r.tool === 'search tool')).toBe(true);
76
+ expect(result.every(r => r.cityName === testCity && r.tool === MIS_TOOLS.findSubject)).toBe(true);
76
77
  });
77
78
 
78
79
  it('given valid city but wrong tool when fetched then return empty array', async () => {
79
- const result = await getSystemInstructionsByToolAndCity(testCity, 'wrong tool');
80
+ const result = await getSystemInstructionsByToolAndCity(testCity, MIS_TOOLS.findStreet);
80
81
  expect(result).toEqual([]);
81
82
  });
82
83
  });
@@ -5,9 +5,9 @@ import {
5
5
  deactivateSystemInstruction,
6
6
  activateSystemInstruction
7
7
  } from '../instructions.setters';
8
- import { getSystemInstructionById } from '../instructions.getters';
9
- import {SystemInstruction} from "../instructions.types";
10
- import { ObjectId } from 'mongodb';
8
+ import {getSystemInstructionById} from '../instructions.getters';
9
+ import {MIS_SystemInstruction, MIS_TOOLS, QUERY_TYPES} from "../instructions.types";
10
+ import {ObjectId} from 'mongodb';
11
11
 
12
12
 
13
13
  describe('System Instructions Setter Tests', () => {
@@ -16,12 +16,12 @@ describe('System Instructions Setter Tests', () => {
16
16
  describe('createSystemInstruction', () => {
17
17
  it('given valid data when created then save document with timestamps', async () => {
18
18
  // Given
19
- const instructionData: Omit<SystemInstruction, '_id' | 'createdAt' | 'updatedAt'> = {
19
+ const instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'> = {
20
20
  cityName: testCity,
21
21
  instruction: 'Test Instruction',
22
22
  isActive: true,
23
- tool: "search tool",
24
- queryType: "search tool",
23
+ tool: MIS_TOOLS.findSubject,
24
+ queryType: QUERY_TYPES.any,
25
25
  tags: ['test', 'unit']
26
26
  };
27
27
 
@@ -39,12 +39,12 @@ describe('System Instructions Setter Tests', () => {
39
39
 
40
40
  it('given data without tags when created then save document with default isActive true and no tags', async () => {
41
41
  // Given
42
- const instructionData: Omit<SystemInstruction, '_id' | 'createdAt' | 'updatedAt'> = {
42
+ const instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'> = {
43
43
  cityName: testCity,
44
44
  instruction: 'No Tags Instruction',
45
45
  isActive: true,
46
- tool: "minimal tool",
47
- queryType: "minimal type",
46
+ tool: MIS_TOOLS.findStreet,
47
+ queryType: QUERY_TYPES.exactlyOne,
48
48
  };
49
49
 
50
50
  // When
@@ -56,6 +56,32 @@ describe('System Instructions Setter Tests', () => {
56
56
  expect(saved?.tags).toBeUndefined();
57
57
  expect(saved?.isActive).toBe(true);
58
58
  });
59
+
60
+ it('should throw error when creating with invalid tool', async () => {
61
+ const invalidData = {
62
+ cityName: testCity,
63
+ instruction: 'Invalid Tool Test',
64
+ isActive: true,
65
+ tool: 'invalidTool' as any,
66
+ queryType: QUERY_TYPES.any,
67
+ };
68
+
69
+ await expect(createSystemInstruction(invalidData))
70
+ .rejects.toThrow(`Invalid tool value: invalidTool. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
71
+ });
72
+
73
+ it('should throw error when creating with invalid queryType', async () => {
74
+ const invalidData = {
75
+ cityName: testCity,
76
+ instruction: 'Invalid QueryType Test',
77
+ isActive: true,
78
+ tool: MIS_TOOLS.findSubject,
79
+ queryType: 'invalidType' as any,
80
+ };
81
+
82
+ await expect(createSystemInstruction(invalidData))
83
+ .rejects.toThrow(`Invalid queryType value: invalidType. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
84
+ });
59
85
  });
60
86
 
61
87
  describe('updateSystemInstruction', () => {
@@ -66,8 +92,8 @@ describe('System Instructions Setter Tests', () => {
66
92
  cityName: testCity,
67
93
  instruction: 'Find Me',
68
94
  isActive: true,
69
- tool: "search tool",
70
- queryType: "search tool",
95
+ tool: MIS_TOOLS.findSubject,
96
+ queryType: QUERY_TYPES.any,
71
97
  });
72
98
  instructionId = id.toString();
73
99
 
@@ -75,8 +101,8 @@ describe('System Instructions Setter Tests', () => {
75
101
  cityName: testCity,
76
102
  instruction: 'Inactive One',
77
103
  isActive: false,
78
- tool: "search tool",
79
- queryType: "search tool",
104
+ tool: MIS_TOOLS.findSubject,
105
+ queryType: QUERY_TYPES.any,
80
106
  });
81
107
  });
82
108
  it('given existing doc when updated then change values and refresh updatedAt', async () => {
@@ -99,17 +125,31 @@ describe('System Instructions Setter Tests', () => {
99
125
  // When
100
126
  await updateSystemInstruction(instructionId, {
101
127
  isActive: false,
102
- tool: 'updated tool',
128
+ tool: MIS_TOOLS.findStreet,
103
129
  tags: ['new-tag']
104
130
  });
105
131
 
106
132
  // Then
107
133
  const updatedDoc = await getSystemInstructionById(instructionId);
108
134
  expect(updatedDoc?.isActive).toBe(false);
109
- expect(updatedDoc?.tool).toBe('updated tool');
135
+ expect(updatedDoc?.tool).toBe(MIS_TOOLS.findStreet);
110
136
  expect(updatedDoc?.tags).toEqual(['new-tag']);
111
137
  });
112
138
 
139
+ it('should throw error when updating with invalid tool', async () => {
140
+ const invalidUpdate = { tool: 'invalidTool' as any };
141
+
142
+ await expect(updateSystemInstruction(instructionId, invalidUpdate))
143
+ .rejects.toThrow(`Invalid tool value: invalidTool. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
144
+ });
145
+
146
+ it('should throw error when updating with invalid queryType', async () => {
147
+ const invalidUpdate = { queryType: 'invalidType' as any };
148
+
149
+ await expect(updateSystemInstruction(instructionId, invalidUpdate))
150
+ .rejects.toThrow(`Invalid queryType value: invalidType. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
151
+ });
152
+
113
153
  it('given system instructions, when deactivating it then its status updated to active', async () => {
114
154
  //When
115
155
  const success= await deactivateSystemInstruction(instructionId.toString());
@@ -148,8 +188,8 @@ describe('System Instructions Setter Tests', () => {
148
188
  cityName: testCity,
149
189
  instruction: 'Inactive Instruction',
150
190
  isActive: false,
151
- tool: "test",
152
- queryType: "test",
191
+ tool: MIS_TOOLS.findSubject,
192
+ queryType: QUERY_TYPES.any,
153
193
  });
154
194
  instructionId = id.toString();
155
195
  });
@@ -179,8 +219,8 @@ describe('System Instructions Setter Tests', () => {
179
219
  cityName: testCity,
180
220
  instruction: 'To be deleted',
181
221
  isActive: true,
182
- tool: "search tool",
183
- queryType: "search tool",
222
+ tool: MIS_TOOLS.findSubject,
223
+ queryType: QUERY_TYPES.any,
184
224
  });
185
225
 
186
226
  const deleteResult = await deleteSystemInstruction(id.toString());
@@ -1,3 +1,3 @@
1
1
  export * from './instructions.getters';
2
2
  export * from './instructions.setters';
3
- export type { SystemInstruction } from './instructions.types';
3
+ export type { MIS_SystemInstruction, MIS_Tool, QueryType } from './instructions.types';
@@ -1,9 +1,9 @@
1
1
  import {CityName, getDb, ObjectId} from '../index';
2
2
  import { Collection, Filter } from 'mongodb';
3
- import { SystemInstruction } from './instructions.types';
3
+ import { MIS_SystemInstruction, MIS_Tool } from './instructions.types';
4
4
 
5
- export const getSystemInstructionsCollection = (): Collection<SystemInstruction> => {
6
- return getDb().collection<SystemInstruction>('system_instructions');
5
+ export const getSystemInstructionsCollection = (): Collection<MIS_SystemInstruction> => {
6
+ return getDb().collection<MIS_SystemInstruction>('system_instructions');
7
7
  };
8
8
  /**
9
9
  * Find system instructions by filter
@@ -11,8 +11,8 @@ export const getSystemInstructionsCollection = (): Collection<SystemInstruction>
11
11
  * @returns array of system instructions
12
12
  */
13
13
  export const findSystemInstructions = async (
14
- filter: Filter<SystemInstruction> = {}
15
- ): Promise<SystemInstruction[]> => {
14
+ filter: Filter<MIS_SystemInstruction> = {}
15
+ ): Promise<MIS_SystemInstruction[]> => {
16
16
  return await getSystemInstructionsCollection().find(filter).toArray();
17
17
  };
18
18
 
@@ -21,7 +21,7 @@ export const findSystemInstructions = async (
21
21
  * @param id system instruction id
22
22
  * @returns system instruction or null if not found
23
23
  */
24
- export const getSystemInstructionById = async (id: string): Promise<SystemInstruction | null> => {
24
+ export const getSystemInstructionById = async (id: string): Promise<MIS_SystemInstruction | null> => {
25
25
  return await getSystemInstructionsCollection().findOne({ _id: new ObjectId(id) });
26
26
  }
27
27
  /**
@@ -29,7 +29,7 @@ export const getSystemInstructionById = async (id: string): Promise<SystemInstru
29
29
  * @param cityName city name
30
30
  * @returns array of active system instructions
31
31
  */
32
- export const getActiveSystemInstructionsByCity = async (cityName: CityName): Promise<SystemInstruction[]> => {
32
+ export const getActiveSystemInstructionsByCity = async (cityName: CityName): Promise<MIS_SystemInstruction[]> => {
33
33
  return await getSystemInstructionsCollection().find({cityName, isActive: true}).toArray();
34
34
  }
35
35
  /**
@@ -38,7 +38,7 @@ export const getActiveSystemInstructionsByCity = async (cityName: CityName): Pro
38
38
  * @param toolName tool name
39
39
  * @returns array of system instructions
40
40
  */
41
- export const getSystemInstructionsByToolAndCity = async (cityName: CityName, toolName: string): Promise<SystemInstruction[]> => {
41
+ export const getSystemInstructionsByToolAndCity = async (cityName: CityName, toolName: MIS_Tool): Promise<MIS_SystemInstruction[]> => {
42
42
  return await getSystemInstructionsCollection().find({cityName: cityName, tool: toolName}).toArray();
43
43
  }
44
44
 
@@ -1,23 +1,38 @@
1
1
  import { ObjectId } from '../index';
2
2
  import { ObjectId as MongoObjectId } from 'mongodb';
3
- import { SystemInstruction } from './instructions.types';
3
+ import { MIS_SystemInstruction, MIS_TOOLS, QUERY_TYPES } from './instructions.types';
4
4
  import { getSystemInstructionsCollection } from './instructions.getters';
5
5
 
6
+ /**
7
+ * Validate system instruction data
8
+ * @param data partial system instruction data
9
+ * @throws Error if tool or queryType is invalid
10
+ */
11
+ const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
12
+ if (data.tool && !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)) {
13
+ throw new Error(`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
14
+ }
15
+ if (data.queryType && !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)) {
16
+ throw new Error(`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
17
+ }
18
+ };
19
+
6
20
  /**
7
21
  * Create a new system instruction
8
22
  * @param instructionData system instruction data
9
23
  * @returns inserted system instruction id
10
24
  */
11
25
  export const createSystemInstruction = async (
12
- instructionData: Omit<SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>
26
+ instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>
13
27
  ): Promise<MongoObjectId> => {
14
- const instruction: Omit<SystemInstruction, '_id'> = { //append doc metadata to user provided data
28
+ validateInstructionData(instructionData as Partial<MIS_SystemInstruction>);
29
+ const instruction: Omit<MIS_SystemInstruction, '_id'> = { //append doc metadata to user provided data
15
30
  ...instructionData,
16
31
  createdAt: new Date(),
17
32
  updatedAt: new Date(),
18
33
  };
19
34
  const { insertedId } = await getSystemInstructionsCollection().insertOne(
20
- instruction as SystemInstruction
35
+ instruction as MIS_SystemInstruction
21
36
  );
22
37
  return insertedId;
23
38
  };
@@ -30,8 +45,9 @@ export const createSystemInstruction = async (
30
45
  */
31
46
  export const updateSystemInstruction = async (
32
47
  id: string,
33
- data: Partial<Omit<SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>>
34
- ): Promise<SystemInstruction | null> => {
48
+ data: Partial<Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>>
49
+ ): Promise<MIS_SystemInstruction | null> => {
50
+ validateInstructionData(data as Partial<MIS_SystemInstruction>);
35
51
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
36
52
  { _id: new ObjectId(id) },
37
53
  { $set: { ...data, updatedAt: new Date() } },
@@ -2,14 +2,29 @@ import { ObjectId } from 'mongodb';
2
2
 
3
3
  import {CityName} from "../utils/types";
4
4
 
5
- export type SystemInstruction = {
5
+ export const MIS_TOOLS = {
6
+ findStreet: 'findStreet',
7
+ findSubject: 'findSubject'
8
+ } as const;
9
+
10
+ export const QUERY_TYPES = {
11
+ exactlyOne: 'exactlyOne',
12
+ any: 'any',
13
+ all: 'all',
14
+ none: 'none'
15
+ } as const;
16
+
17
+ export type MIS_Tool = typeof MIS_TOOLS[keyof typeof MIS_TOOLS];
18
+ export type QueryType = typeof QUERY_TYPES[keyof typeof QUERY_TYPES];
19
+
20
+ export type MIS_SystemInstruction = {
6
21
  _id: ObjectId;
7
22
  createdAt: Date;
8
23
  updatedAt: Date;
9
24
  cityName: CityName;
10
25
  instruction: string;
11
26
  isActive: boolean;
12
- tool: string;
13
- queryType: string;
27
+ tool: MIS_Tool;
28
+ queryType: QueryType;
14
29
  tags?: string[]; //no tags implies all wildcard (?)
15
30
  };