@event-driven-io/emmett 0.43.0-beta.13 → 0.43.0-beta.15

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.
@@ -0,0 +1,131 @@
1
+ //#region src/validation/dates.ts
2
+ const formatDateToUtcYYYYMMDD = (date) => {
3
+ return new Intl.DateTimeFormat("en-CA", {
4
+ timeZone: "UTC",
5
+ year: "numeric",
6
+ month: "2-digit",
7
+ day: "2-digit"
8
+ }).format(date);
9
+ };
10
+ const isValidYYYYMMDD = (dateString) => {
11
+ return /^\d{4}-\d{2}-\d{2}$/.test(dateString);
12
+ };
13
+ const parseDateFromUtcYYYYMMDD = (dateString) => {
14
+ const date = /* @__PURE__ */ new Date(dateString + "T00:00:00Z");
15
+ if (!isValidYYYYMMDD(dateString)) throw new ValidationError("Invalid date format, must be yyyy-mm-dd");
16
+ if (isNaN(date.getTime())) throw new ValidationError("Invalid date format");
17
+ return date;
18
+ };
19
+
20
+ //#endregion
21
+ //#region src/validation/index.ts
22
+ let ValidationErrors = /* @__PURE__ */ function(ValidationErrors) {
23
+ ValidationErrors["NOT_A_NONEMPTY_STRING"] = "NOT_A_NONEMPTY_STRING";
24
+ ValidationErrors["NOT_A_POSITIVE_NUMBER"] = "NOT_A_POSITIVE_NUMBER";
25
+ ValidationErrors["NOT_AN_UNSIGNED_BIGINT"] = "NOT_AN_UNSIGNED_BIGINT";
26
+ return ValidationErrors;
27
+ }({});
28
+ const isNumber = (val) => typeof val === "number" && val === val;
29
+ const isBigint = (val) => typeof val === "bigint" && val === val;
30
+ const isString = (val) => typeof val === "string";
31
+ const assertNotEmptyString = (value) => {
32
+ if (!isString(value) || value.length === 0) throw new ValidationError("NOT_A_NONEMPTY_STRING");
33
+ return value;
34
+ };
35
+ const assertPositiveNumber = (value) => {
36
+ if (!isNumber(value) || value <= 0) throw new ValidationError("NOT_A_POSITIVE_NUMBER");
37
+ return value;
38
+ };
39
+ const assertUnsignedBigInt = (value) => {
40
+ const number = BigInt(value);
41
+ if (number < 0) throw new ValidationError("NOT_AN_UNSIGNED_BIGINT");
42
+ return number;
43
+ };
44
+
45
+ //#endregion
46
+ //#region src/errors/index.ts
47
+ const isErrorConstructor = (expect) => {
48
+ return typeof expect === "function" && expect.prototype && expect.prototype.constructor === expect;
49
+ };
50
+ var EmmettError = class EmmettError extends Error {
51
+ static Codes = {
52
+ ValidationError: 400,
53
+ IllegalStateError: 403,
54
+ NotFoundError: 404,
55
+ ConcurrencyError: 412,
56
+ InternalServerError: 500
57
+ };
58
+ errorCode;
59
+ constructor(options) {
60
+ const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : EmmettError.Codes.InternalServerError;
61
+ const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
62
+ super(message);
63
+ this.errorCode = errorCode;
64
+ Object.setPrototypeOf(this, EmmettError.prototype);
65
+ }
66
+ static mapFrom(error) {
67
+ if (EmmettError.isInstanceOf(error)) return error;
68
+ return new EmmettError({
69
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : EmmettError.Codes.InternalServerError,
70
+ message: error.message ?? "An unknown error occurred"
71
+ });
72
+ }
73
+ static isInstanceOf(error, errorCode) {
74
+ return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
75
+ }
76
+ };
77
+ var ConcurrencyError = class ConcurrencyError extends EmmettError {
78
+ constructor(current, expected, message) {
79
+ super({
80
+ errorCode: EmmettError.Codes.ConcurrencyError,
81
+ message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
82
+ });
83
+ this.current = current;
84
+ this.expected = expected;
85
+ Object.setPrototypeOf(this, ConcurrencyError.prototype);
86
+ }
87
+ };
88
+ var ConcurrencyInMemoryDatabaseError = class ConcurrencyInMemoryDatabaseError extends EmmettError {
89
+ constructor(message) {
90
+ super({
91
+ errorCode: EmmettError.Codes.ConcurrencyError,
92
+ message: message ?? `Expected document state does not match current one!`
93
+ });
94
+ Object.setPrototypeOf(this, ConcurrencyInMemoryDatabaseError.prototype);
95
+ }
96
+ };
97
+ var ValidationError = class ValidationError extends EmmettError {
98
+ constructor(message) {
99
+ super({
100
+ errorCode: EmmettError.Codes.ValidationError,
101
+ message: message ?? `Validation Error ocurred during Emmett processing`
102
+ });
103
+ Object.setPrototypeOf(this, ValidationError.prototype);
104
+ }
105
+ };
106
+ var IllegalStateError = class IllegalStateError extends EmmettError {
107
+ constructor(message) {
108
+ super({
109
+ errorCode: EmmettError.Codes.IllegalStateError,
110
+ message: message ?? `Illegal State ocurred during Emmett processing`
111
+ });
112
+ Object.setPrototypeOf(this, IllegalStateError.prototype);
113
+ }
114
+ };
115
+ var NotFoundError = class NotFoundError extends EmmettError {
116
+ constructor(options) {
117
+ super({
118
+ errorCode: EmmettError.Codes.NotFoundError,
119
+ message: options?.message ?? (options?.id ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : options?.type ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")
120
+ });
121
+ Object.setPrototypeOf(this, NotFoundError.prototype);
122
+ }
123
+ };
124
+
125
+ //#endregion
126
+ //#region src/config/plugins/index.ts
127
+ const isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
128
+
129
+ //#endregion
130
+ export { isValidYYYYMMDD as _, IllegalStateError as a, isErrorConstructor as c, assertPositiveNumber as d, assertUnsignedBigInt as f, formatDateToUtcYYYYMMDD as g, isString as h, EmmettError as i, ValidationErrors as l, isNumber as m, ConcurrencyError as n, NotFoundError as o, isBigint as p, ConcurrencyInMemoryDatabaseError as r, ValidationError as s, isPluginConfig as t, assertNotEmptyString as u, parseDateFromUtcYYYYMMDD as v };
131
+ //# sourceMappingURL=plugins-CUbnGFPp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-CUbnGFPp.js","names":[],"sources":["../src/validation/dates.ts","../src/validation/index.ts","../src/errors/index.ts","../src/config/plugins/index.ts"],"sourcesContent":["import { ValidationError } from '../errors';\n\nexport const formatDateToUtcYYYYMMDD = (date: Date) => {\n // Use the 'en-CA' locale which formats as 'yyyy-mm-dd'\n const formatter = new Intl.DateTimeFormat('en-CA', {\n timeZone: 'UTC',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n });\n\n // Format the date\n return formatter.format(date);\n};\n\n// Function to validate 'yyyy-mm-dd' format\nexport const isValidYYYYMMDD = (dateString: string) => {\n const regex = /^\\d{4}-\\d{2}-\\d{2}$/;\n return regex.test(dateString);\n};\n\nexport const parseDateFromUtcYYYYMMDD = (dateString: string) => {\n const date = new Date(dateString + 'T00:00:00Z');\n\n if (!isValidYYYYMMDD(dateString)) {\n throw new ValidationError('Invalid date format, must be yyyy-mm-dd');\n }\n\n if (isNaN(date.getTime())) {\n throw new ValidationError('Invalid date format');\n }\n\n return date;\n};\n","import { ValidationError } from '../errors';\n\nexport const enum ValidationErrors {\n NOT_A_NONEMPTY_STRING = 'NOT_A_NONEMPTY_STRING',\n NOT_A_POSITIVE_NUMBER = 'NOT_A_POSITIVE_NUMBER',\n NOT_AN_UNSIGNED_BIGINT = 'NOT_AN_UNSIGNED_BIGINT',\n}\n\nexport const isNumber = (val: unknown): val is number =>\n typeof val === 'number' && val === val;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isBigint = (val: any): val is bigint =>\n typeof val === 'bigint' && val === val;\n\nexport const isString = (val: unknown): val is string =>\n typeof val === 'string';\n\nexport const assertNotEmptyString = (value: unknown): string => {\n if (!isString(value) || value.length === 0) {\n throw new ValidationError(ValidationErrors.NOT_A_NONEMPTY_STRING);\n }\n return value;\n};\n\nexport const assertPositiveNumber = (value: unknown): number => {\n if (!isNumber(value) || value <= 0) {\n throw new ValidationError(ValidationErrors.NOT_A_POSITIVE_NUMBER);\n }\n return value;\n};\n\nexport const assertUnsignedBigInt = (value: string): bigint => {\n const number = BigInt(value);\n if (number < 0) {\n throw new ValidationError(ValidationErrors.NOT_AN_UNSIGNED_BIGINT);\n }\n return number;\n};\n\nexport * from './dates';\n","import { isNumber, isString } from '../validation';\n\nexport type ErrorConstructor<ErrorType extends Error> = new (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => ErrorType;\n\nexport const isErrorConstructor = <ErrorType extends Error>(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n expect: Function,\n): expect is ErrorConstructor<ErrorType> => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n typeof expect === 'function' &&\n expect.prototype &&\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect.prototype.constructor === expect\n );\n};\n\nexport class EmmettError extends Error {\n public static readonly Codes = {\n ValidationError: 400,\n IllegalStateError: 403,\n NotFoundError: 404,\n ConcurrencyError: 412,\n InternalServerError: 500,\n };\n\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : EmmettError.Codes.InternalServerError;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n\n public static mapFrom(\n error: Error | { message?: string; errorCode?: number },\n ): EmmettError {\n if (EmmettError.isInstanceOf(error)) {\n return error;\n }\n\n return new EmmettError({\n errorCode:\n 'errorCode' in error &&\n error.errorCode !== undefined &&\n error.errorCode !== null\n ? error.errorCode\n : EmmettError.Codes.InternalServerError,\n message: error.message ?? 'An unknown error occurred',\n });\n }\n\n public static isInstanceOf<ErrorType extends EmmettError = EmmettError>(\n error: unknown,\n errorCode?: (typeof EmmettError.Codes)[keyof typeof EmmettError.Codes],\n ): error is ErrorType {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'errorCode' in error &&\n isNumber(error.errorCode) &&\n (errorCode === undefined || error.errorCode === errorCode)\n );\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: EmmettError.Codes.ConcurrencyError,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\n// TODO: Make it derive from ConcurrencyError to avoid code duplication\n// Or add additional type to distinguinsh both errors\nexport class ConcurrencyInMemoryDatabaseError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.ConcurrencyError,\n message: message ?? `Expected document state does not match current one!`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyInMemoryDatabaseError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.ValidationError,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.IllegalStateError,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: EmmettError.Codes.NotFoundError,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","export type EmmettPluginConfig =\n | {\n name: string;\n register: EmmettPluginRegistration[];\n }\n | string;\n\nexport type EmmettPluginType = 'cli';\n\nexport type EmmettCliPluginRegistration = { pluginType: 'cli'; path?: string };\n\nexport type EmmettPluginRegistration = EmmettCliPluginRegistration;\n\nexport type EmmettCliCommand = {\n addCommand<CliCommand>(command: CliCommand): CliCommand;\n};\n\nexport type EmmettCliPlugin = {\n pluginType: 'cli';\n name: string;\n registerCommands: (program: EmmettCliCommand) => Promise<void> | void;\n};\n\nexport type EmmettPlugin = EmmettCliPlugin;\n\nexport const isPluginConfig = (\n plugin: Partial<EmmettPluginConfig> | string | undefined,\n): plugin is EmmettPluginConfig =>\n plugin !== undefined &&\n (typeof plugin === 'string' ||\n ('name' in plugin &&\n plugin.name !== undefined &&\n typeof plugin.name === 'string'));\n"],"mappings":"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"}
@@ -0,0 +1,272 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ //#region src/validation/dates.ts
30
+ const formatDateToUtcYYYYMMDD = (date) => {
31
+ return new Intl.DateTimeFormat("en-CA", {
32
+ timeZone: "UTC",
33
+ year: "numeric",
34
+ month: "2-digit",
35
+ day: "2-digit"
36
+ }).format(date);
37
+ };
38
+ const isValidYYYYMMDD = (dateString) => {
39
+ return /^\d{4}-\d{2}-\d{2}$/.test(dateString);
40
+ };
41
+ const parseDateFromUtcYYYYMMDD = (dateString) => {
42
+ const date = /* @__PURE__ */ new Date(dateString + "T00:00:00Z");
43
+ if (!isValidYYYYMMDD(dateString)) throw new ValidationError("Invalid date format, must be yyyy-mm-dd");
44
+ if (isNaN(date.getTime())) throw new ValidationError("Invalid date format");
45
+ return date;
46
+ };
47
+
48
+ //#endregion
49
+ //#region src/validation/index.ts
50
+ let ValidationErrors = /* @__PURE__ */ function(ValidationErrors) {
51
+ ValidationErrors["NOT_A_NONEMPTY_STRING"] = "NOT_A_NONEMPTY_STRING";
52
+ ValidationErrors["NOT_A_POSITIVE_NUMBER"] = "NOT_A_POSITIVE_NUMBER";
53
+ ValidationErrors["NOT_AN_UNSIGNED_BIGINT"] = "NOT_AN_UNSIGNED_BIGINT";
54
+ return ValidationErrors;
55
+ }({});
56
+ const isNumber = (val) => typeof val === "number" && val === val;
57
+ const isBigint = (val) => typeof val === "bigint" && val === val;
58
+ const isString = (val) => typeof val === "string";
59
+ const assertNotEmptyString = (value) => {
60
+ if (!isString(value) || value.length === 0) throw new ValidationError("NOT_A_NONEMPTY_STRING");
61
+ return value;
62
+ };
63
+ const assertPositiveNumber = (value) => {
64
+ if (!isNumber(value) || value <= 0) throw new ValidationError("NOT_A_POSITIVE_NUMBER");
65
+ return value;
66
+ };
67
+ const assertUnsignedBigInt = (value) => {
68
+ const number = BigInt(value);
69
+ if (number < 0) throw new ValidationError("NOT_AN_UNSIGNED_BIGINT");
70
+ return number;
71
+ };
72
+
73
+ //#endregion
74
+ //#region src/errors/index.ts
75
+ const isErrorConstructor = (expect) => {
76
+ return typeof expect === "function" && expect.prototype && expect.prototype.constructor === expect;
77
+ };
78
+ var EmmettError = class EmmettError extends Error {
79
+ static Codes = {
80
+ ValidationError: 400,
81
+ IllegalStateError: 403,
82
+ NotFoundError: 404,
83
+ ConcurrencyError: 412,
84
+ InternalServerError: 500
85
+ };
86
+ errorCode;
87
+ constructor(options) {
88
+ const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : EmmettError.Codes.InternalServerError;
89
+ const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
90
+ super(message);
91
+ this.errorCode = errorCode;
92
+ Object.setPrototypeOf(this, EmmettError.prototype);
93
+ }
94
+ static mapFrom(error) {
95
+ if (EmmettError.isInstanceOf(error)) return error;
96
+ return new EmmettError({
97
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : EmmettError.Codes.InternalServerError,
98
+ message: error.message ?? "An unknown error occurred"
99
+ });
100
+ }
101
+ static isInstanceOf(error, errorCode) {
102
+ return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
103
+ }
104
+ };
105
+ var ConcurrencyError = class ConcurrencyError extends EmmettError {
106
+ constructor(current, expected, message) {
107
+ super({
108
+ errorCode: EmmettError.Codes.ConcurrencyError,
109
+ message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
110
+ });
111
+ this.current = current;
112
+ this.expected = expected;
113
+ Object.setPrototypeOf(this, ConcurrencyError.prototype);
114
+ }
115
+ };
116
+ var ConcurrencyInMemoryDatabaseError = class ConcurrencyInMemoryDatabaseError extends EmmettError {
117
+ constructor(message) {
118
+ super({
119
+ errorCode: EmmettError.Codes.ConcurrencyError,
120
+ message: message ?? `Expected document state does not match current one!`
121
+ });
122
+ Object.setPrototypeOf(this, ConcurrencyInMemoryDatabaseError.prototype);
123
+ }
124
+ };
125
+ var ValidationError = class ValidationError extends EmmettError {
126
+ constructor(message) {
127
+ super({
128
+ errorCode: EmmettError.Codes.ValidationError,
129
+ message: message ?? `Validation Error ocurred during Emmett processing`
130
+ });
131
+ Object.setPrototypeOf(this, ValidationError.prototype);
132
+ }
133
+ };
134
+ var IllegalStateError = class IllegalStateError extends EmmettError {
135
+ constructor(message) {
136
+ super({
137
+ errorCode: EmmettError.Codes.IllegalStateError,
138
+ message: message ?? `Illegal State ocurred during Emmett processing`
139
+ });
140
+ Object.setPrototypeOf(this, IllegalStateError.prototype);
141
+ }
142
+ };
143
+ var NotFoundError = class NotFoundError extends EmmettError {
144
+ constructor(options) {
145
+ super({
146
+ errorCode: EmmettError.Codes.NotFoundError,
147
+ message: options?.message ?? (options?.id ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : options?.type ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")
148
+ });
149
+ Object.setPrototypeOf(this, NotFoundError.prototype);
150
+ }
151
+ };
152
+
153
+ //#endregion
154
+ //#region src/config/plugins/index.ts
155
+ const isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
156
+
157
+ //#endregion
158
+ Object.defineProperty(exports, 'ConcurrencyError', {
159
+ enumerable: true,
160
+ get: function () {
161
+ return ConcurrencyError;
162
+ }
163
+ });
164
+ Object.defineProperty(exports, 'ConcurrencyInMemoryDatabaseError', {
165
+ enumerable: true,
166
+ get: function () {
167
+ return ConcurrencyInMemoryDatabaseError;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, 'EmmettError', {
171
+ enumerable: true,
172
+ get: function () {
173
+ return EmmettError;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, 'IllegalStateError', {
177
+ enumerable: true,
178
+ get: function () {
179
+ return IllegalStateError;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, 'NotFoundError', {
183
+ enumerable: true,
184
+ get: function () {
185
+ return NotFoundError;
186
+ }
187
+ });
188
+ Object.defineProperty(exports, 'ValidationError', {
189
+ enumerable: true,
190
+ get: function () {
191
+ return ValidationError;
192
+ }
193
+ });
194
+ Object.defineProperty(exports, 'ValidationErrors', {
195
+ enumerable: true,
196
+ get: function () {
197
+ return ValidationErrors;
198
+ }
199
+ });
200
+ Object.defineProperty(exports, '__toESM', {
201
+ enumerable: true,
202
+ get: function () {
203
+ return __toESM;
204
+ }
205
+ });
206
+ Object.defineProperty(exports, 'assertNotEmptyString', {
207
+ enumerable: true,
208
+ get: function () {
209
+ return assertNotEmptyString;
210
+ }
211
+ });
212
+ Object.defineProperty(exports, 'assertPositiveNumber', {
213
+ enumerable: true,
214
+ get: function () {
215
+ return assertPositiveNumber;
216
+ }
217
+ });
218
+ Object.defineProperty(exports, 'assertUnsignedBigInt', {
219
+ enumerable: true,
220
+ get: function () {
221
+ return assertUnsignedBigInt;
222
+ }
223
+ });
224
+ Object.defineProperty(exports, 'formatDateToUtcYYYYMMDD', {
225
+ enumerable: true,
226
+ get: function () {
227
+ return formatDateToUtcYYYYMMDD;
228
+ }
229
+ });
230
+ Object.defineProperty(exports, 'isBigint', {
231
+ enumerable: true,
232
+ get: function () {
233
+ return isBigint;
234
+ }
235
+ });
236
+ Object.defineProperty(exports, 'isErrorConstructor', {
237
+ enumerable: true,
238
+ get: function () {
239
+ return isErrorConstructor;
240
+ }
241
+ });
242
+ Object.defineProperty(exports, 'isNumber', {
243
+ enumerable: true,
244
+ get: function () {
245
+ return isNumber;
246
+ }
247
+ });
248
+ Object.defineProperty(exports, 'isPluginConfig', {
249
+ enumerable: true,
250
+ get: function () {
251
+ return isPluginConfig;
252
+ }
253
+ });
254
+ Object.defineProperty(exports, 'isString', {
255
+ enumerable: true,
256
+ get: function () {
257
+ return isString;
258
+ }
259
+ });
260
+ Object.defineProperty(exports, 'isValidYYYYMMDD', {
261
+ enumerable: true,
262
+ get: function () {
263
+ return isValidYYYYMMDD;
264
+ }
265
+ });
266
+ Object.defineProperty(exports, 'parseDateFromUtcYYYYMMDD', {
267
+ enumerable: true,
268
+ get: function () {
269
+ return parseDateFromUtcYYYYMMDD;
270
+ }
271
+ });
272
+ //# sourceMappingURL=plugins-DB9xe8AV.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-DB9xe8AV.cjs","names":[],"sources":["../src/validation/dates.ts","../src/validation/index.ts","../src/errors/index.ts","../src/config/plugins/index.ts"],"sourcesContent":["import { ValidationError } from '../errors';\n\nexport const formatDateToUtcYYYYMMDD = (date: Date) => {\n // Use the 'en-CA' locale which formats as 'yyyy-mm-dd'\n const formatter = new Intl.DateTimeFormat('en-CA', {\n timeZone: 'UTC',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n });\n\n // Format the date\n return formatter.format(date);\n};\n\n// Function to validate 'yyyy-mm-dd' format\nexport const isValidYYYYMMDD = (dateString: string) => {\n const regex = /^\\d{4}-\\d{2}-\\d{2}$/;\n return regex.test(dateString);\n};\n\nexport const parseDateFromUtcYYYYMMDD = (dateString: string) => {\n const date = new Date(dateString + 'T00:00:00Z');\n\n if (!isValidYYYYMMDD(dateString)) {\n throw new ValidationError('Invalid date format, must be yyyy-mm-dd');\n }\n\n if (isNaN(date.getTime())) {\n throw new ValidationError('Invalid date format');\n }\n\n return date;\n};\n","import { ValidationError } from '../errors';\n\nexport const enum ValidationErrors {\n NOT_A_NONEMPTY_STRING = 'NOT_A_NONEMPTY_STRING',\n NOT_A_POSITIVE_NUMBER = 'NOT_A_POSITIVE_NUMBER',\n NOT_AN_UNSIGNED_BIGINT = 'NOT_AN_UNSIGNED_BIGINT',\n}\n\nexport const isNumber = (val: unknown): val is number =>\n typeof val === 'number' && val === val;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isBigint = (val: any): val is bigint =>\n typeof val === 'bigint' && val === val;\n\nexport const isString = (val: unknown): val is string =>\n typeof val === 'string';\n\nexport const assertNotEmptyString = (value: unknown): string => {\n if (!isString(value) || value.length === 0) {\n throw new ValidationError(ValidationErrors.NOT_A_NONEMPTY_STRING);\n }\n return value;\n};\n\nexport const assertPositiveNumber = (value: unknown): number => {\n if (!isNumber(value) || value <= 0) {\n throw new ValidationError(ValidationErrors.NOT_A_POSITIVE_NUMBER);\n }\n return value;\n};\n\nexport const assertUnsignedBigInt = (value: string): bigint => {\n const number = BigInt(value);\n if (number < 0) {\n throw new ValidationError(ValidationErrors.NOT_AN_UNSIGNED_BIGINT);\n }\n return number;\n};\n\nexport * from './dates';\n","import { isNumber, isString } from '../validation';\n\nexport type ErrorConstructor<ErrorType extends Error> = new (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => ErrorType;\n\nexport const isErrorConstructor = <ErrorType extends Error>(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n expect: Function,\n): expect is ErrorConstructor<ErrorType> => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n typeof expect === 'function' &&\n expect.prototype &&\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect.prototype.constructor === expect\n );\n};\n\nexport class EmmettError extends Error {\n public static readonly Codes = {\n ValidationError: 400,\n IllegalStateError: 403,\n NotFoundError: 404,\n ConcurrencyError: 412,\n InternalServerError: 500,\n };\n\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : EmmettError.Codes.InternalServerError;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n\n public static mapFrom(\n error: Error | { message?: string; errorCode?: number },\n ): EmmettError {\n if (EmmettError.isInstanceOf(error)) {\n return error;\n }\n\n return new EmmettError({\n errorCode:\n 'errorCode' in error &&\n error.errorCode !== undefined &&\n error.errorCode !== null\n ? error.errorCode\n : EmmettError.Codes.InternalServerError,\n message: error.message ?? 'An unknown error occurred',\n });\n }\n\n public static isInstanceOf<ErrorType extends EmmettError = EmmettError>(\n error: unknown,\n errorCode?: (typeof EmmettError.Codes)[keyof typeof EmmettError.Codes],\n ): error is ErrorType {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'errorCode' in error &&\n isNumber(error.errorCode) &&\n (errorCode === undefined || error.errorCode === errorCode)\n );\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: EmmettError.Codes.ConcurrencyError,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\n// TODO: Make it derive from ConcurrencyError to avoid code duplication\n// Or add additional type to distinguinsh both errors\nexport class ConcurrencyInMemoryDatabaseError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.ConcurrencyError,\n message: message ?? `Expected document state does not match current one!`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyInMemoryDatabaseError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.ValidationError,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: EmmettError.Codes.IllegalStateError,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: EmmettError.Codes.NotFoundError,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","export type EmmettPluginConfig =\n | {\n name: string;\n register: EmmettPluginRegistration[];\n }\n | string;\n\nexport type EmmettPluginType = 'cli';\n\nexport type EmmettCliPluginRegistration = { pluginType: 'cli'; path?: string };\n\nexport type EmmettPluginRegistration = EmmettCliPluginRegistration;\n\nexport type EmmettCliCommand = {\n addCommand<CliCommand>(command: CliCommand): CliCommand;\n};\n\nexport type EmmettCliPlugin = {\n pluginType: 'cli';\n name: string;\n registerCommands: (program: EmmettCliCommand) => Promise<void> | void;\n};\n\nexport type EmmettPlugin = EmmettCliPlugin;\n\nexport const isPluginConfig = (\n plugin: Partial<EmmettPluginConfig> | string | undefined,\n): plugin is EmmettPluginConfig =>\n plugin !== undefined &&\n (typeof plugin === 'string' ||\n ('name' in plugin &&\n plugin.name !== undefined &&\n typeof plugin.name === 'string'));\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@event-driven-io/emmett",
3
3
  "type": "module",
4
- "version": "0.43.0-beta.13",
4
+ "version": "0.43.0-beta.15",
5
5
  "description": "Emmett - Event Sourcing development made simple",
6
6
  "scripts": {
7
- "build": "tsup",
7
+ "build": "tsdown",
8
8
  "build:ts": "tsc",
9
9
  "build:ts:watch": "tsc -b --watch",
10
10
  "test": "run-s test:unit test:int test:e2e",
@@ -66,10 +66,13 @@
66
66
  "bin": {
67
67
  "emmett": "dist/cli.js"
68
68
  },
69
- "peerDependencies": {
69
+ "dependencies": {
70
+ "@event-driven-io/almanac": "0.1.0-beta.14",
70
71
  "@types/async-retry": "^1.4.9",
71
- "async-retry": "^1.3.3",
72
- "commander": "^14.0.2",
73
- "uuid": "^13.0.0"
72
+ "async-retry": "^1.3.3"
73
+ },
74
+ "peerDependencies": {
75
+ "commander": "^14.0.3",
76
+ "uuid": "^14.0.0"
74
77
  }
75
78
  }
@@ -1,161 +0,0 @@
1
- // src/config/plugins/index.ts
2
- var isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
3
-
4
- // src/validation/index.ts
5
- var ValidationErrors = /* @__PURE__ */ ((ValidationErrors2) => {
6
- ValidationErrors2["NOT_A_NONEMPTY_STRING"] = "NOT_A_NONEMPTY_STRING";
7
- ValidationErrors2["NOT_A_POSITIVE_NUMBER"] = "NOT_A_POSITIVE_NUMBER";
8
- ValidationErrors2["NOT_AN_UNSIGNED_BIGINT"] = "NOT_AN_UNSIGNED_BIGINT";
9
- return ValidationErrors2;
10
- })(ValidationErrors || {});
11
- var isNumber = (val) => typeof val === "number" && val === val;
12
- var isBigint = (val) => typeof val === "bigint" && val === val;
13
- var isString = (val) => typeof val === "string";
14
- var assertNotEmptyString = (value) => {
15
- if (!isString(value) || value.length === 0) {
16
- throw new ValidationError("NOT_A_NONEMPTY_STRING" /* NOT_A_NONEMPTY_STRING */);
17
- }
18
- return value;
19
- };
20
- var assertPositiveNumber = (value) => {
21
- if (!isNumber(value) || value <= 0) {
22
- throw new ValidationError("NOT_A_POSITIVE_NUMBER" /* NOT_A_POSITIVE_NUMBER */);
23
- }
24
- return value;
25
- };
26
- var assertUnsignedBigInt = (value) => {
27
- const number = BigInt(value);
28
- if (number < 0) {
29
- throw new ValidationError("NOT_AN_UNSIGNED_BIGINT" /* NOT_AN_UNSIGNED_BIGINT */);
30
- }
31
- return number;
32
- };
33
-
34
- // src/errors/index.ts
35
- var isErrorConstructor = (expect) => {
36
- return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
37
- expect.prototype.constructor === expect;
38
- };
39
- var EmmettError = class _EmmettError extends Error {
40
- static Codes = {
41
- ValidationError: 400,
42
- IllegalStateError: 403,
43
- NotFoundError: 404,
44
- ConcurrencyError: 412,
45
- InternalServerError: 500
46
- };
47
- errorCode;
48
- constructor(options) {
49
- const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
50
- const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
51
- super(message);
52
- this.errorCode = errorCode;
53
- Object.setPrototypeOf(this, _EmmettError.prototype);
54
- }
55
- static mapFrom(error) {
56
- if (_EmmettError.isInstanceOf(error)) {
57
- return error;
58
- }
59
- return new _EmmettError({
60
- errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
61
- message: error.message ?? "An unknown error occurred"
62
- });
63
- }
64
- static isInstanceOf(error, errorCode) {
65
- return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
66
- }
67
- };
68
- var ConcurrencyError = class _ConcurrencyError extends EmmettError {
69
- constructor(current, expected, message) {
70
- super({
71
- errorCode: EmmettError.Codes.ConcurrencyError,
72
- message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
73
- });
74
- this.current = current;
75
- this.expected = expected;
76
- Object.setPrototypeOf(this, _ConcurrencyError.prototype);
77
- }
78
- };
79
- var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError extends EmmettError {
80
- constructor(message) {
81
- super({
82
- errorCode: EmmettError.Codes.ConcurrencyError,
83
- message: message ?? `Expected document state does not match current one!`
84
- });
85
- Object.setPrototypeOf(this, _ConcurrencyInMemoryDatabaseError.prototype);
86
- }
87
- };
88
- var ValidationError = class _ValidationError extends EmmettError {
89
- constructor(message) {
90
- super({
91
- errorCode: EmmettError.Codes.ValidationError,
92
- message: message ?? `Validation Error ocurred during Emmett processing`
93
- });
94
- Object.setPrototypeOf(this, _ValidationError.prototype);
95
- }
96
- };
97
- var IllegalStateError = class _IllegalStateError extends EmmettError {
98
- constructor(message) {
99
- super({
100
- errorCode: EmmettError.Codes.IllegalStateError,
101
- message: message ?? `Illegal State ocurred during Emmett processing`
102
- });
103
- Object.setPrototypeOf(this, _IllegalStateError.prototype);
104
- }
105
- };
106
- var NotFoundError = class _NotFoundError extends EmmettError {
107
- constructor(options) {
108
- super({
109
- errorCode: EmmettError.Codes.NotFoundError,
110
- message: options?.message ?? (options?.id ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : options?.type ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")
111
- });
112
- Object.setPrototypeOf(this, _NotFoundError.prototype);
113
- }
114
- };
115
-
116
- // src/validation/dates.ts
117
- var formatDateToUtcYYYYMMDD = (date) => {
118
- const formatter = new Intl.DateTimeFormat("en-CA", {
119
- timeZone: "UTC",
120
- year: "numeric",
121
- month: "2-digit",
122
- day: "2-digit"
123
- });
124
- return formatter.format(date);
125
- };
126
- var isValidYYYYMMDD = (dateString) => {
127
- const regex = /^\d{4}-\d{2}-\d{2}$/;
128
- return regex.test(dateString);
129
- };
130
- var parseDateFromUtcYYYYMMDD = (dateString) => {
131
- const date = /* @__PURE__ */ new Date(dateString + "T00:00:00Z");
132
- if (!isValidYYYYMMDD(dateString)) {
133
- throw new ValidationError("Invalid date format, must be yyyy-mm-dd");
134
- }
135
- if (isNaN(date.getTime())) {
136
- throw new ValidationError("Invalid date format");
137
- }
138
- return date;
139
- };
140
-
141
- export {
142
- isPluginConfig,
143
- formatDateToUtcYYYYMMDD,
144
- isValidYYYYMMDD,
145
- parseDateFromUtcYYYYMMDD,
146
- ValidationErrors,
147
- isNumber,
148
- isBigint,
149
- isString,
150
- assertNotEmptyString,
151
- assertPositiveNumber,
152
- assertUnsignedBigInt,
153
- isErrorConstructor,
154
- EmmettError,
155
- ConcurrencyError,
156
- ConcurrencyInMemoryDatabaseError,
157
- ValidationError,
158
- IllegalStateError,
159
- NotFoundError
160
- };
161
- //# sourceMappingURL=chunk-AZDDB5SF.js.map