@devopsplaybook.io/common-utils 1.10.1-beta.23.b1906d7 → 1.11.0-beta.24.d8f9aef

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.
Files changed (69) hide show
  1. package/README.md +73 -27
  2. package/dist/src/ConfigBase.d.ts +31 -0
  3. package/dist/src/ConfigBase.js +58 -16
  4. package/dist/src/DbUtils.d.ts +20 -3
  5. package/dist/src/DbUtils.js +93 -2
  6. package/dist/src/DbUtilsNoTelemetry.d.ts +4 -1
  7. package/dist/src/DbUtilsNoTelemetry.js +62 -6
  8. package/dist/src/PostgresDbUtils.d.ts +41 -10
  9. package/dist/src/PostgresDbUtils.js +357 -304
  10. package/dist/src/SqlDbUtils.d.ts +12 -4
  11. package/dist/src/SqlDbUtils.js +76 -30
  12. package/dist/src/users/Auth.d.ts +11 -1
  13. package/dist/src/users/Auth.js +160 -44
  14. package/dist/src/users/User.d.ts +10 -0
  15. package/dist/src/users/User.js +30 -10
  16. package/dist/src/users/UserApiToken.d.ts +4 -0
  17. package/dist/src/users/UserApiToken.js +11 -0
  18. package/dist/src/users/UsersApiTokensData.d.ts +12 -0
  19. package/dist/src/users/UsersApiTokensData.js +130 -33
  20. package/dist/src/users/UsersData.d.ts +20 -1
  21. package/dist/src/users/UsersData.js +150 -52
  22. package/dist/src/users/UsersRoutes.js +178 -61
  23. package/dist/src/users/index.d.ts +8 -0
  24. package/dist/src/users/index.js +24 -0
  25. package/package.json +58 -1
  26. package/.github/workflows/main-build.yml +0 -18
  27. package/.github/workflows/pr-check.yml +0 -27
  28. package/.github/workflows/reusable-merge-build.yml +0 -197
  29. package/.github/workflows/reusable-npm-merge.yml +0 -135
  30. package/.github/workflows/reusable-npm-pr.yml +0 -183
  31. package/.github/workflows/reusable-npm-upgrade.yml +0 -92
  32. package/.github/workflows/reusable-pr-verify.yml +0 -181
  33. package/AGENTS.md +0 -105
  34. package/index.ts +0 -18
  35. package/jest.config.js +0 -17
  36. package/prettierrc.json +0 -5
  37. package/src/ConfigBase.spec.ts +0 -108
  38. package/src/ConfigBase.ts +0 -297
  39. package/src/DbUtils.spec.ts +0 -23
  40. package/src/DbUtils.ts +0 -116
  41. package/src/DbUtilsNoTelemetry.spec.ts +0 -168
  42. package/src/DbUtilsNoTelemetry.ts +0 -117
  43. package/src/LLM.spec.ts +0 -303
  44. package/src/LLM.ts +0 -204
  45. package/src/Notifications.spec.ts +0 -265
  46. package/src/Notifications.ts +0 -201
  47. package/src/OTelContext.spec.ts +0 -58
  48. package/src/OTelContext.ts +0 -63
  49. package/src/PostgresDbUtils.spec.ts +0 -153
  50. package/src/PostgresDbUtils.ts +0 -666
  51. package/src/SqlDbUtils.spec.ts +0 -108
  52. package/src/SqlDbUtils.ts +0 -152
  53. package/src/SystemCommand.spec.ts +0 -18
  54. package/src/SystemCommand.ts +0 -23
  55. package/src/Timeout.spec.ts +0 -18
  56. package/src/Timeout.ts +0 -12
  57. package/src/users/Auth.spec.ts +0 -268
  58. package/src/users/Auth.ts +0 -202
  59. package/src/users/User.ts +0 -75
  60. package/src/users/UserApiToken.ts +0 -55
  61. package/src/users/UserPassword.spec.ts +0 -28
  62. package/src/users/UserPassword.ts +0 -20
  63. package/src/users/UserSession.ts +0 -9
  64. package/src/users/UsersApiTokensData.spec.ts +0 -158
  65. package/src/users/UsersApiTokensData.ts +0 -125
  66. package/src/users/UsersData.ts +0 -141
  67. package/src/users/UsersRoutes.ts +0 -374
  68. package/tsconfig.json +0 -15
  69. package/tsconfig.spec.json +0 -8
@@ -1,153 +0,0 @@
1
-
2
- // Mock pg before imports
3
- const mockQuery = jest.fn();
4
- jest.mock("pg", () => {
5
- return {
6
- Pool: jest.fn().mockImplementation(() => ({
7
- query: mockQuery,
8
- on: jest.fn(),
9
- })),
10
- };
11
- });
12
-
13
- jest.mock("fs-extra", () => ({
14
- readdir: jest.fn().mockResolvedValue(["init-0000.sql"]),
15
- readFile: jest
16
- .fn()
17
- .mockResolvedValue(Buffer.from("CREATE TABLE metadata ();")),
18
- }));
19
-
20
- jest.mock("@devopsplaybook.io/otel-utils", () => ({
21
- StandardTracer: jest.fn(),
22
- StandardLogger: jest.fn(),
23
- ModuleLogger: jest.fn(),
24
- }));
25
-
26
- jest.mock("@opentelemetry/sdk-trace-base", () => ({
27
- Span: jest.fn(),
28
- }));
29
-
30
- jest.mock("@opentelemetry/api", () => ({
31
- SpanStatusCode: { ERROR: 2, OK: 1 },
32
- }));
33
-
34
- describe("PostgresDbUtils", () => {
35
- let PostgresDbUtils: typeof import("./PostgresDbUtils");
36
-
37
- const mockSpan = {
38
- end: jest.fn(),
39
- addEvent: jest.fn(),
40
- setStatus: jest.fn(),
41
- };
42
-
43
- const mockModuleLogger = {
44
- info: jest.fn(),
45
- error: jest.fn(),
46
- warn: jest.fn(),
47
- };
48
-
49
- const mockTracer = {
50
- startSpan: jest.fn().mockReturnValue(mockSpan),
51
- };
52
-
53
- const mockLogger = {
54
- createModuleLogger: jest.fn().mockReturnValue(mockModuleLogger),
55
- };
56
-
57
- beforeEach(() => {
58
- jest.clearAllMocks();
59
- jest.isolateModules(() => {
60
- PostgresDbUtils = require("./PostgresDbUtils");
61
- });
62
- PostgresDbUtils.PostgresDbUtilsSetOTel(
63
- mockTracer as any,
64
- mockLogger as any,
65
- );
66
- });
67
-
68
- it("PostgresDbUtilsSetOTel should accept tracer and logger", () => {
69
- expect(() =>
70
- PostgresDbUtils.PostgresDbUtilsSetOTel(
71
- mockTracer as any,
72
- mockLogger as any,
73
- ),
74
- ).not.toThrow();
75
- });
76
-
77
- it("PostgresDbUtilsGetPool should return undefined before init", () => {
78
- expect(PostgresDbUtils.PostgresDbUtilsGetPool()).toBeUndefined();
79
- });
80
-
81
- it("PostgresDbUtilsExecSQL should create a span and call pool.query", async () => {
82
- const config = {
83
- DATABASE_POSTGRES_HOST: "localhost",
84
- DATABASE_POSTGRES_PORT: 5432,
85
- DATABASE_POSTGRES_USER: "user",
86
- DATABASE_POSTGRES_PASSWORD: "pass",
87
- DATABASE_POSTGRES_DATABASE: "testdb",
88
- };
89
-
90
- // Mock the version query to return version 0
91
- // pool.query can be called with 2 args (sql, cb) or 3 args (sql, params, cb)
92
- mockQuery.mockImplementation((...args: any[]) => {
93
- const cb =
94
- typeof args[args.length - 1] === "function"
95
- ? args[args.length - 1]
96
- : null;
97
- if (!cb) return;
98
- // Determine which call this is based on arg count
99
- if (args.length === 2) {
100
- // execSQLFile call
101
- cb(null);
102
- } else if (args.length === 3) {
103
- const sql = args[0] as string;
104
- if (sql.includes("MAX")) {
105
- // version query
106
- cb(null, { rows: [{ version: 0 }] });
107
- } else {
108
- // insert version
109
- cb(null, { rowCount: 1 });
110
- }
111
- }
112
- });
113
-
114
- await PostgresDbUtils.PostgresDbUtilsInit(
115
- mockSpan as any,
116
- config,
117
- "/fake/sql",
118
- );
119
-
120
- expect(mockTracer.startSpan).toHaveBeenCalledWith(
121
- "PostgresDbUtilsInit",
122
- mockSpan,
123
- );
124
- });
125
-
126
- it("PostgresDbUtilsTransactionStart should call BEGIN", async () => {
127
- const config = {
128
- DATABASE_POSTGRES_HOST: "localhost",
129
- DATABASE_POSTGRES_PORT: 5432,
130
- DATABASE_POSTGRES_USER: "user",
131
- DATABASE_POSTGRES_PASSWORD: "pass",
132
- DATABASE_POSTGRES_DATABASE: "testdb",
133
- };
134
-
135
- // Need to init first to create pool
136
- mockQuery.mockImplementation((_sql: any, ...args: any[]) => {
137
- const cb = args[args.length - 1];
138
- if (typeof cb === "function") cb(null, { rows: [], rowCount: 0 });
139
- });
140
-
141
- await PostgresDbUtils.PostgresDbUtilsInit(
142
- mockSpan as any,
143
- config,
144
- "/fake/sql",
145
- );
146
- await PostgresDbUtils.PostgresDbUtilsTransactionStart(mockSpan as any);
147
-
148
- expect(mockTracer.startSpan).toHaveBeenCalledWith(
149
- "PostgresDbUtilsTransactionStart",
150
- mockSpan,
151
- );
152
- });
153
- });