node-cqrs 1.2.0-beta.0 → 1.3.0-alpha.0

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 (82) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +29 -9
  3. package/dist/cjs/postgresql/AbstractPostgresqlAccessor.js +83 -0
  4. package/dist/cjs/postgresql/AbstractPostgresqlAccessor.js.map +1 -0
  5. package/dist/cjs/postgresql/AbstractPostgresqlObjectProjection.js +36 -0
  6. package/dist/cjs/postgresql/AbstractPostgresqlObjectProjection.js.map +1 -0
  7. package/dist/cjs/postgresql/AbstractPostgresqlView.js +53 -0
  8. package/dist/cjs/postgresql/AbstractPostgresqlView.js.map +1 -0
  9. package/dist/cjs/postgresql/IContainer.js +3 -0
  10. package/dist/cjs/postgresql/IContainer.js.map +1 -0
  11. package/dist/cjs/postgresql/PostgresqlConnection.js +3 -0
  12. package/dist/cjs/postgresql/PostgresqlConnection.js.map +1 -0
  13. package/dist/cjs/postgresql/PostgresqlEventLocker.js +127 -0
  14. package/dist/cjs/postgresql/PostgresqlEventLocker.js.map +1 -0
  15. package/dist/cjs/postgresql/PostgresqlEventStorage.js +315 -0
  16. package/dist/cjs/postgresql/PostgresqlEventStorage.js.map +1 -0
  17. package/dist/cjs/postgresql/PostgresqlObjectStorage.js +137 -0
  18. package/dist/cjs/postgresql/PostgresqlObjectStorage.js.map +1 -0
  19. package/dist/cjs/postgresql/PostgresqlObjectView.js +46 -0
  20. package/dist/cjs/postgresql/PostgresqlObjectView.js.map +1 -0
  21. package/dist/cjs/postgresql/PostgresqlProjectionDataParams.js +3 -0
  22. package/dist/cjs/postgresql/PostgresqlProjectionDataParams.js.map +1 -0
  23. package/dist/cjs/postgresql/PostgresqlViewLocker.js +151 -0
  24. package/dist/cjs/postgresql/PostgresqlViewLocker.js.map +1 -0
  25. package/dist/cjs/postgresql/index.js +29 -0
  26. package/dist/cjs/postgresql/index.js.map +1 -0
  27. package/dist/cjs/postgresql/utils/getEventId.js +14 -0
  28. package/dist/cjs/postgresql/utils/getEventId.js.map +1 -0
  29. package/dist/cjs/postgresql/utils/index.js +19 -0
  30. package/dist/cjs/postgresql/utils/index.js.map +1 -0
  31. package/dist/cjs/postgresql/utils/quoteIdentifier.js +14 -0
  32. package/dist/cjs/postgresql/utils/quoteIdentifier.js.map +1 -0
  33. package/dist/cjs/sqlite/SqliteEventStorage.js +66 -36
  34. package/dist/cjs/sqlite/SqliteEventStorage.js.map +1 -1
  35. package/dist/esm/postgresql/AbstractPostgresqlAccessor.js +79 -0
  36. package/dist/esm/postgresql/AbstractPostgresqlAccessor.js.map +1 -0
  37. package/dist/esm/postgresql/AbstractPostgresqlObjectProjection.js +32 -0
  38. package/dist/esm/postgresql/AbstractPostgresqlObjectProjection.js.map +1 -0
  39. package/dist/esm/postgresql/AbstractPostgresqlView.js +49 -0
  40. package/dist/esm/postgresql/AbstractPostgresqlView.js.map +1 -0
  41. package/dist/esm/postgresql/IContainer.js +2 -0
  42. package/dist/esm/postgresql/IContainer.js.map +1 -0
  43. package/dist/esm/postgresql/PostgresqlConnection.js +2 -0
  44. package/dist/esm/postgresql/PostgresqlConnection.js.map +1 -0
  45. package/dist/esm/postgresql/PostgresqlEventLocker.js +123 -0
  46. package/dist/esm/postgresql/PostgresqlEventLocker.js.map +1 -0
  47. package/dist/esm/postgresql/PostgresqlEventStorage.js +311 -0
  48. package/dist/esm/postgresql/PostgresqlEventStorage.js.map +1 -0
  49. package/dist/esm/postgresql/PostgresqlObjectStorage.js +133 -0
  50. package/dist/esm/postgresql/PostgresqlObjectStorage.js.map +1 -0
  51. package/dist/esm/postgresql/PostgresqlObjectView.js +42 -0
  52. package/dist/esm/postgresql/PostgresqlObjectView.js.map +1 -0
  53. package/dist/esm/postgresql/PostgresqlProjectionDataParams.js +2 -0
  54. package/dist/esm/postgresql/PostgresqlProjectionDataParams.js.map +1 -0
  55. package/dist/esm/postgresql/PostgresqlViewLocker.js +147 -0
  56. package/dist/esm/postgresql/PostgresqlViewLocker.js.map +1 -0
  57. package/dist/esm/postgresql/index.js +13 -0
  58. package/dist/esm/postgresql/index.js.map +1 -0
  59. package/dist/esm/postgresql/utils/getEventId.js +10 -0
  60. package/dist/esm/postgresql/utils/getEventId.js.map +1 -0
  61. package/dist/esm/postgresql/utils/index.js +3 -0
  62. package/dist/esm/postgresql/utils/index.js.map +1 -0
  63. package/dist/esm/postgresql/utils/quoteIdentifier.js +11 -0
  64. package/dist/esm/postgresql/utils/quoteIdentifier.js.map +1 -0
  65. package/dist/esm/sqlite/SqliteEventStorage.js +66 -36
  66. package/dist/esm/sqlite/SqliteEventStorage.js.map +1 -1
  67. package/dist/types/postgresql/AbstractPostgresqlAccessor.d.ts +29 -0
  68. package/dist/types/postgresql/AbstractPostgresqlObjectProjection.d.ts +12 -0
  69. package/dist/types/postgresql/AbstractPostgresqlView.d.ts +23 -0
  70. package/dist/types/postgresql/IContainer.d.ts +12 -0
  71. package/dist/types/postgresql/PostgresqlConnection.d.ts +7 -0
  72. package/dist/types/postgresql/PostgresqlEventLocker.d.ts +39 -0
  73. package/dist/types/postgresql/PostgresqlEventStorage.d.ts +23 -0
  74. package/dist/types/postgresql/PostgresqlObjectStorage.d.ts +29 -0
  75. package/dist/types/postgresql/PostgresqlObjectView.d.ts +19 -0
  76. package/dist/types/postgresql/PostgresqlProjectionDataParams.d.ts +14 -0
  77. package/dist/types/postgresql/PostgresqlViewLocker.d.ts +41 -0
  78. package/dist/types/postgresql/index.d.ts +12 -0
  79. package/dist/types/postgresql/utils/getEventId.d.ts +5 -0
  80. package/dist/types/postgresql/utils/index.d.ts +2 -0
  81. package/dist/types/postgresql/utils/quoteIdentifier.d.ts +1 -0
  82. package/package.json +20 -5
@@ -0,0 +1,41 @@
1
+ import type { IContainer } from 'node-cqrs';
2
+ import type { IViewLocker } from '../interfaces/index.ts';
3
+ import type { PostgresqlConnection } from './PostgresqlConnection.ts';
4
+ import type { PostgresqlProjectionDataParams } from './PostgresqlProjectionDataParams.ts';
5
+ import { AbstractPostgresqlAccessor } from './AbstractPostgresqlAccessor.ts';
6
+ export type PostgresqlViewLockerParams = PostgresqlProjectionDataParams & {
7
+ /**
8
+ * (Optional) PostgreSQL table name where view locks and the latest event are stored.
9
+ *
10
+ * @default PostgresqlViewLocker.DEFAULT_TABLE
11
+ */
12
+ viewLockTableName?: string;
13
+ /**
14
+ * (Optional) Time-to-live (TTL) duration (in milliseconds) for which a view remains locked.
15
+ * The lock is automatically prolonged while still held by this instance.
16
+ *
17
+ * @default PostgresqlViewLocker.DEFAULT_VIEW_LOCK_TTL
18
+ */
19
+ viewLockTtl?: number;
20
+ };
21
+ /**
22
+ * PostgreSQL-backed implementation of IViewLocker.
23
+ *
24
+ * Uses a row with token + locked_till semantics to acquire a distributed view lock.
25
+ * The lock is automatically prolonged at half the TTL interval to prevent expiration
26
+ * while processing is in progress.
27
+ */
28
+ export declare class PostgresqlViewLocker extends AbstractPostgresqlAccessor implements IViewLocker {
29
+ #private;
30
+ static DEFAULT_VIEW_LOCK_TTL: number;
31
+ static DEFAULT_TABLE: string;
32
+ constructor(o: Partial<Pick<IContainer, 'viewModelPostgresqlDb' | 'viewModelPostgresqlDbFactory' | 'logger'>> & PostgresqlViewLockerParams);
33
+ protected initialize(db: PostgresqlConnection): Promise<void>;
34
+ get ready(): boolean;
35
+ lock(): Promise<boolean>;
36
+ private scheduleLockProlongation;
37
+ private cancelLockProlongation;
38
+ private prolongLock;
39
+ unlock(): Promise<void>;
40
+ once(event: 'ready'): Promise<void>;
41
+ }
@@ -0,0 +1,12 @@
1
+ import './IContainer.ts';
2
+ export * from './AbstractPostgresqlAccessor.ts';
3
+ export * from './AbstractPostgresqlObjectProjection.ts';
4
+ export * from './AbstractPostgresqlView.ts';
5
+ export * from './PostgresqlConnection.ts';
6
+ export * from './PostgresqlEventStorage.ts';
7
+ export * from './PostgresqlEventLocker.ts';
8
+ export * from './PostgresqlObjectStorage.ts';
9
+ export * from './PostgresqlObjectView.ts';
10
+ export * from './PostgresqlProjectionDataParams.ts';
11
+ export * from './PostgresqlViewLocker.ts';
12
+ export * from './utils/index.ts';
@@ -0,0 +1,5 @@
1
+ import type { IEvent } from '../../interfaces/index.ts';
2
+ /**
3
+ * Get assigned or generate a deterministic event ID as a hex string.
4
+ */
5
+ export declare const getEventId: (event: IEvent) => string;
@@ -0,0 +1,2 @@
1
+ export * from './getEventId.ts';
2
+ export * from './quoteIdentifier.ts';
@@ -0,0 +1 @@
1
+ export declare function quoteIdentifier(identifier: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-cqrs",
3
- "version": "1.2.0-beta.0",
4
- "description": "TypeScript CQRS/Event Sourcing toolkit for Node.js with DI, sagas, projections, and optional Worker, RabbitMQ, and SQLite adapters",
3
+ "version": "1.3.0-alpha.0",
4
+ "description": "TypeScript CQRS/Event Sourcing toolkit for Node.js with DI, sagas, projections, and optional Worker, RabbitMQ, SQLite, MongoDB, and PostgreSQL adapters",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "cqrs",
@@ -19,7 +19,9 @@
19
19
  "worker-threads",
20
20
  "rabbitmq",
21
21
  "sqlite",
22
- "redis"
22
+ "mongodb",
23
+ "redis",
24
+ "postgresql"
23
25
  ],
24
26
  "repository": {
25
27
  "type": "git",
@@ -62,6 +64,11 @@
62
64
  "types": "./dist/types/mongodb/index.d.ts",
63
65
  "require": "./dist/cjs/mongodb/index.js",
64
66
  "import": "./dist/esm/mongodb/index.js"
67
+ },
68
+ "./postgresql": {
69
+ "types": "./dist/types/postgresql/index.d.ts",
70
+ "require": "./dist/cjs/postgresql/index.js",
71
+ "import": "./dist/esm/postgresql/index.js"
65
72
  }
66
73
  },
67
74
  "directories": {
@@ -87,6 +94,7 @@
87
94
  "example:redis": "node examples/redis/index.ts",
88
95
  "example:mongodb-eventstore": "node examples/mongodb-eventstore/index.ts",
89
96
  "example:mongodb-views": "node examples/mongodb-views/index.ts",
97
+ "example:postgresql": "node examples/postgresql/index.ts",
90
98
  "example:browser": "npm run build:browser && echo \"\nOpen ./examples/browser/index.html in your browser (check DevTools console)\n\"",
91
99
  "pretest:examples": "npm run build:cjs",
92
100
  "test:examples": "jest --roots='<rootDir>/examples'",
@@ -95,6 +103,7 @@
95
103
  "test:sqlite": "jest --verbose --roots='<rootDir>/tests/integration/sqlite'",
96
104
  "test:redis": "jest --verbose --roots='<rootDir>/tests/integration/redis'",
97
105
  "test:mongodb": "jest --verbose --roots='<rootDir>/tests/integration/mongodb'",
106
+ "test:postgresql": "jest --verbose --roots='<rootDir>/tests/integration/postgresql'",
98
107
  "pretest:workers": "npm run build:cjs",
99
108
  "test:workers": "jest --verbose --roots='<rootDir>/tests/integration/workers'",
100
109
  "changelog": "conventional-changelog -n ./scripts/changelog/index.cjs -r 0 > CHANGELOG.md",
@@ -135,10 +144,10 @@
135
144
  "@rollup/plugin-node-resolve": "^16.0.3",
136
145
  "@rollup/plugin-terser": "^1.0.0",
137
146
  "@types/amqplib": "^0.10.8",
138
- "ioredis": "^5.0.0",
139
147
  "@types/better-sqlite3": "^7.6.13",
140
148
  "@types/jest": "^29.5.14",
141
149
  "@types/node": "^25.5.0",
150
+ "@types/pg": "^8.20.0",
142
151
  "@typescript-eslint/eslint-plugin": "^8.29.0",
143
152
  "@typescript-eslint/parser": "^8.29.0",
144
153
  "amqplib": "^0.10.9",
@@ -148,8 +157,10 @@
148
157
  "eslint": "^9.39.4",
149
158
  "eslint-plugin-jest": "^28.14.0",
150
159
  "globals": "^17.4.0",
160
+ "ioredis": "^5.0.0",
151
161
  "jest": "^29.7.0",
152
162
  "mongodb": "^6.21.0",
163
+ "pg": "^8.21.0",
153
164
  "rollup": "^4.59.0",
154
165
  "ts-jest": "^29.4.6",
155
166
  "ts-node": "^10.9.2",
@@ -162,7 +173,8 @@
162
173
  "better-sqlite3": "^12.6.2",
163
174
  "comlink": "^4.4.2",
164
175
  "ioredis": "^5.0.0",
165
- "mongodb": "^6.0.0"
176
+ "mongodb": "^6.0.0",
177
+ "pg": "^8.0.0"
166
178
  },
167
179
  "peerDependenciesMeta": {
168
180
  "better-sqlite3": {
@@ -180,6 +192,9 @@
180
192
  "mongodb": {
181
193
  "optional": true
182
194
  },
195
+ "pg": {
196
+ "optional": true
197
+ },
183
198
  "@opentelemetry/api": {
184
199
  "optional": true
185
200
  }