@event-driven-io/emmett 0.38.7 → 0.39.1
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.
- package/dist/{chunk-O2VMBOV4.js → chunk-AZDDB5SF.js} +19 -9
- package/dist/chunk-AZDDB5SF.js.map +1 -0
- package/dist/{chunk-FMH3M5GB.cjs → chunk-WND32L6P.cjs} +22 -12
- package/dist/chunk-WND32L6P.cjs.map +1 -0
- package/dist/cli.cjs +7 -7
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +2 -2
- package/dist/{index-7wNEMFlg.d.cts → index-Amos00J7.d.cts} +8 -0
- package/dist/{index-7wNEMFlg.d.ts → index-Amos00J7.d.ts} +8 -0
- package/dist/index.cjs +54 -547
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -140
- package/dist/index.d.ts +12 -140
- package/dist/index.js +14 -507
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/dist/chunk-FMH3M5GB.cjs.map +0 -1
- package/dist/chunk-O2VMBOV4.js.map +0 -1
|
@@ -37,28 +37,38 @@ var isErrorConstructor = (expect) => {
|
|
|
37
37
|
expect.prototype.constructor === expect;
|
|
38
38
|
};
|
|
39
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
|
+
};
|
|
40
47
|
errorCode;
|
|
41
48
|
constructor(options) {
|
|
42
|
-
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options :
|
|
49
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
|
|
43
50
|
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
44
51
|
super(message);
|
|
45
52
|
this.errorCode = errorCode;
|
|
46
53
|
Object.setPrototypeOf(this, _EmmettError.prototype);
|
|
47
54
|
}
|
|
48
55
|
static mapFrom(error) {
|
|
49
|
-
if (error
|
|
56
|
+
if (_EmmettError.isInstanceOf(error)) {
|
|
50
57
|
return error;
|
|
51
58
|
}
|
|
52
59
|
return new _EmmettError({
|
|
53
|
-
errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode :
|
|
60
|
+
errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
|
|
54
61
|
message: error.message ?? "An unknown error occurred"
|
|
55
62
|
});
|
|
56
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
|
+
}
|
|
57
67
|
};
|
|
58
68
|
var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
59
69
|
constructor(current, expected, message) {
|
|
60
70
|
super({
|
|
61
|
-
errorCode:
|
|
71
|
+
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
62
72
|
message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
|
|
63
73
|
});
|
|
64
74
|
this.current = current;
|
|
@@ -69,7 +79,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
69
79
|
var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError extends EmmettError {
|
|
70
80
|
constructor(message) {
|
|
71
81
|
super({
|
|
72
|
-
errorCode:
|
|
82
|
+
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
73
83
|
message: message ?? `Expected document state does not match current one!`
|
|
74
84
|
});
|
|
75
85
|
Object.setPrototypeOf(this, _ConcurrencyInMemoryDatabaseError.prototype);
|
|
@@ -78,7 +88,7 @@ var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError e
|
|
|
78
88
|
var ValidationError = class _ValidationError extends EmmettError {
|
|
79
89
|
constructor(message) {
|
|
80
90
|
super({
|
|
81
|
-
errorCode:
|
|
91
|
+
errorCode: EmmettError.Codes.ValidationError,
|
|
82
92
|
message: message ?? `Validation Error ocurred during Emmett processing`
|
|
83
93
|
});
|
|
84
94
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
@@ -87,7 +97,7 @@ var ValidationError = class _ValidationError extends EmmettError {
|
|
|
87
97
|
var IllegalStateError = class _IllegalStateError extends EmmettError {
|
|
88
98
|
constructor(message) {
|
|
89
99
|
super({
|
|
90
|
-
errorCode:
|
|
100
|
+
errorCode: EmmettError.Codes.IllegalStateError,
|
|
91
101
|
message: message ?? `Illegal State ocurred during Emmett processing`
|
|
92
102
|
});
|
|
93
103
|
Object.setPrototypeOf(this, _IllegalStateError.prototype);
|
|
@@ -96,7 +106,7 @@ var IllegalStateError = class _IllegalStateError extends EmmettError {
|
|
|
96
106
|
var NotFoundError = class _NotFoundError extends EmmettError {
|
|
97
107
|
constructor(options) {
|
|
98
108
|
super({
|
|
99
|
-
errorCode:
|
|
109
|
+
errorCode: EmmettError.Codes.NotFoundError,
|
|
100
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")
|
|
101
111
|
});
|
|
102
112
|
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
@@ -148,4 +158,4 @@ export {
|
|
|
148
158
|
IllegalStateError,
|
|
149
159
|
NotFoundError
|
|
150
160
|
};
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
161
|
+
//# sourceMappingURL=chunk-AZDDB5SF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config/plugins/index.ts","../src/validation/index.ts","../src/errors/index.ts","../src/validation/dates.ts"],"sourcesContent":["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","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","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"],"mappings":";AAyBO,IAAM,iBAAiB,CAC5B,WAEA,WAAW,WACV,OAAO,WAAW,YAChB,UAAU,UACT,OAAO,SAAS,UAChB,OAAO,OAAO,SAAS;;;AC9BtB,IAAW,mBAAX,kBAAWA,sBAAX;AACL,EAAAA,kBAAA,2BAAwB;AACxB,EAAAA,kBAAA,2BAAwB;AACxB,EAAAA,kBAAA,4BAAyB;AAHT,SAAAA;AAAA,GAAA;AAMX,IAAM,WAAW,CAAC,QACvB,OAAO,QAAQ,YAAY,QAAQ;AAG9B,IAAM,WAAW,CAAC,QACvB,OAAO,QAAQ,YAAY,QAAQ;AAE9B,IAAM,WAAW,CAAC,QACvB,OAAO,QAAQ;AAEV,IAAM,uBAAuB,CAAC,UAA2B;AAC9D,MAAI,CAAC,SAAS,KAAK,KAAK,MAAM,WAAW,GAAG;AAC1C,UAAM,IAAI,gBAAgB,mDAAsC;AAAA,EAClE;AACA,SAAO;AACT;AAEO,IAAM,uBAAuB,CAAC,UAA2B;AAC9D,MAAI,CAAC,SAAS,KAAK,KAAK,SAAS,GAAG;AAClC,UAAM,IAAI,gBAAgB,mDAAsC;AAAA,EAClE;AACA,SAAO;AACT;AAEO,IAAM,u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AAS;AAAA,IACjD,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,EACP,CAAC;AAGD,SAAO,UAAU,OAAO,IAAI;AAC9B;AAGO,IAAM,kBAAkB,CAAC,eAAuB;AACrD,QAAM,QAAQ;AACd,SAAO,MAAM,KAAK,UAAU;AAC9B;AAEO,IAAM,2BAA2B,CAAC,eAAuB;AAC9D,QAAM,OAAO,oBAAI,KAAK,aAAa,YAAY;AAE/C,MAAI,CAAC,gBAAgB,UAAU,GAAG;AAChC,UAAM,IAAI,gBAAgB,yCAAyC;AAAA,EACrE;AAEA,MAAI,MAAM,KAAK,QAAQ,CAAC,GAAG;AACzB,UAAM,IAAI,gBAAgB,qBAAqB;AAAA,EACjD;AAEA,SAAO;AACT;","names":["ValidationErrors"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/config/plugins/index.ts
|
|
2
2
|
var isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
|
|
3
3
|
|
|
4
4
|
// src/validation/index.ts
|
|
@@ -36,29 +36,39 @@ var isErrorConstructor = (expect) => {
|
|
|
36
36
|
return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
37
37
|
expect.prototype.constructor === expect;
|
|
38
38
|
};
|
|
39
|
-
var EmmettError = class _EmmettError extends Error {
|
|
39
|
+
var EmmettError = (_class = class _EmmettError extends Error {
|
|
40
|
+
static __initStatic() {this.Codes = {
|
|
41
|
+
ValidationError: 400,
|
|
42
|
+
IllegalStateError: 403,
|
|
43
|
+
NotFoundError: 404,
|
|
44
|
+
ConcurrencyError: 412,
|
|
45
|
+
InternalServerError: 500
|
|
46
|
+
}}
|
|
40
47
|
|
|
41
48
|
constructor(options) {
|
|
42
|
-
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options :
|
|
49
|
+
const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
|
|
43
50
|
const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
|
|
44
51
|
super(message);
|
|
45
52
|
this.errorCode = errorCode;
|
|
46
53
|
Object.setPrototypeOf(this, _EmmettError.prototype);
|
|
47
54
|
}
|
|
48
55
|
static mapFrom(error) {
|
|
49
|
-
if (error
|
|
56
|
+
if (_EmmettError.isInstanceOf(error)) {
|
|
50
57
|
return error;
|
|
51
58
|
}
|
|
52
59
|
return new _EmmettError({
|
|
53
|
-
errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode :
|
|
60
|
+
errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
|
|
54
61
|
message: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
|
-
|
|
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
|
+
}, _class.__initStatic(), _class);
|
|
58
68
|
var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
59
69
|
constructor(current, expected, message) {
|
|
60
70
|
super({
|
|
61
|
-
errorCode:
|
|
71
|
+
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
62
72
|
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])}`))
|
|
63
73
|
});
|
|
64
74
|
this.current = current;
|
|
@@ -69,7 +79,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
69
79
|
var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError extends EmmettError {
|
|
70
80
|
constructor(message) {
|
|
71
81
|
super({
|
|
72
|
-
errorCode:
|
|
82
|
+
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
73
83
|
message: _nullishCoalesce(message, () => ( `Expected document state does not match current one!`))
|
|
74
84
|
});
|
|
75
85
|
Object.setPrototypeOf(this, _ConcurrencyInMemoryDatabaseError.prototype);
|
|
@@ -78,7 +88,7 @@ var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError e
|
|
|
78
88
|
var ValidationError = class _ValidationError extends EmmettError {
|
|
79
89
|
constructor(message) {
|
|
80
90
|
super({
|
|
81
|
-
errorCode:
|
|
91
|
+
errorCode: EmmettError.Codes.ValidationError,
|
|
82
92
|
message: _nullishCoalesce(message, () => ( `Validation Error ocurred during Emmett processing`))
|
|
83
93
|
});
|
|
84
94
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
@@ -87,7 +97,7 @@ var ValidationError = class _ValidationError extends EmmettError {
|
|
|
87
97
|
var IllegalStateError = class _IllegalStateError extends EmmettError {
|
|
88
98
|
constructor(message) {
|
|
89
99
|
super({
|
|
90
|
-
errorCode:
|
|
100
|
+
errorCode: EmmettError.Codes.IllegalStateError,
|
|
91
101
|
message: _nullishCoalesce(message, () => ( `Illegal State ocurred during Emmett processing`))
|
|
92
102
|
});
|
|
93
103
|
Object.setPrototypeOf(this, _IllegalStateError.prototype);
|
|
@@ -96,7 +106,7 @@ var IllegalStateError = class _IllegalStateError extends EmmettError {
|
|
|
96
106
|
var NotFoundError = class _NotFoundError extends EmmettError {
|
|
97
107
|
constructor(options) {
|
|
98
108
|
super({
|
|
99
|
-
errorCode:
|
|
109
|
+
errorCode: EmmettError.Codes.NotFoundError,
|
|
100
110
|
message: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.message]), () => ( (_optionalChain([options, 'optionalAccess', _4 => _4.id]) ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : _optionalChain([options, 'optionalAccess', _5 => _5.type]) ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")))
|
|
101
111
|
});
|
|
102
112
|
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
@@ -148,4 +158,4 @@ var parseDateFromUtcYYYYMMDD = (dateString) => {
|
|
|
148
158
|
|
|
149
159
|
|
|
150
160
|
exports.isPluginConfig = isPluginConfig; exports.formatDateToUtcYYYYMMDD = formatDateToUtcYYYYMMDD; exports.isValidYYYYMMDD = isValidYYYYMMDD; exports.parseDateFromUtcYYYYMMDD = parseDateFromUtcYYYYMMDD; exports.ValidationErrors = ValidationErrors; exports.isNumber = isNumber; exports.isBigint = isBigint; exports.isString = isString; exports.assertNotEmptyString = assertNotEmptyString; exports.assertPositiveNumber = assertPositiveNumber; exports.assertUnsignedBigInt = assertUnsignedBigInt; exports.isErrorConstructor = isErrorConstructor; exports.EmmettError = EmmettError; exports.ConcurrencyError = ConcurrencyError; exports.ConcurrencyInMemoryDatabaseError = ConcurrencyInMemoryDatabaseError; exports.ValidationError = ValidationError; exports.IllegalStateError = IllegalStateError; exports.NotFoundError = NotFoundError;
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
161
|
+
//# sourceMappingURL=chunk-WND32L6P.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-WND32L6P.cjs","../src/config/plugins/index.ts","../src/validation/index.ts","../src/errors/index.ts","../src/validation/dates.ts"],"names":["ValidationErrors"],"mappings":"AAAA;ACyBO,IAAM,eAAA,EAAiB,CAC5B,MAAA,EAAA,GAEA,OAAA,IAAW,KAAA,EAAA,GAAA,CACV,OAAO,OAAA,IAAW,SAAA,GAChB,OAAA,GAAU,OAAA,GACT,MAAA,CAAO,KAAA,IAAS,KAAA,EAAA,GAChB,OAAO,MAAA,CAAO,KAAA,IAAS,QAAA,CAAA;AD9B7B;AACA;AEDO,IAAW,iBAAA,kBAAX,CAAA,CAAWA,iBAAAA,EAAAA,GAAX;AACL,EAAAA,iBAAAA,CAAA,uBAAA,EAAA,EAAwB,uBAAA;AACxB,EAAAA,iBAAAA,CAAA,uBAAA,EAAA,EAAwB,uBAAA;AACxB,EAAAA,iBAAAA,CAAA,wBAAA,EAAA,EAAyB,wBAAA;AAHT,EAAA,OAAAA,iBAAAA;AAAA,CAAA,CAAA,CAAA,iBAAA,GAAA,CAAA,CAAA,CAAA;AAMX,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACvB,OAAO,IAAA,IAAQ,SAAA,GAAY,IAAA,IAAQ,GAAA;AAG9B,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACvB,OAAO,IAAA,IAAQ,SAAA,GAAY,IAAA,IAAQ,GAAA;AAE9B,I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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-WND32L6P.cjs","sourcesContent":[null,"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","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","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"]}
|
package/dist/cli.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkWND32L6Pcjs = require('./chunk-WND32L6P.cjs');
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
var _commander = require('commander');
|
|
@@ -86,15 +86,15 @@ var importPluginsConfig = async (options) => {
|
|
|
86
86
|
try {
|
|
87
87
|
const imported = await Promise.resolve().then(() => _interopRequireWildcard(require(configPath)));
|
|
88
88
|
if (!imported.default) {
|
|
89
|
-
return new (0,
|
|
89
|
+
return new (0, _chunkWND32L6Pcjs.EmmettError)(PluginsConfigImportError.missingDefaultExport);
|
|
90
90
|
}
|
|
91
91
|
if (!imported.default.plugins || !Array.isArray(imported.default.plugins)) {
|
|
92
|
-
return new (0,
|
|
92
|
+
return new (0, _chunkWND32L6Pcjs.EmmettError)(
|
|
93
93
|
PluginsConfigImportError.missingPluginsPropertyExport
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
if (!imported.default.plugins.every(
|
|
97
|
-
return new (0,
|
|
96
|
+
if (!imported.default.plugins.every(_chunkWND32L6Pcjs.isPluginConfig)) {
|
|
97
|
+
return new (0, _chunkWND32L6Pcjs.EmmettError)(PluginsConfigImportError.wrongPluginStructure);
|
|
98
98
|
}
|
|
99
99
|
return { plugins: imported.default.plugins };
|
|
100
100
|
} catch (error) {
|
|
@@ -102,7 +102,7 @@ var importPluginsConfig = async (options) => {
|
|
|
102
102
|
console.warn("Didn`t find config file: " + configPath, error);
|
|
103
103
|
return { plugins: [] };
|
|
104
104
|
}
|
|
105
|
-
return new (0,
|
|
105
|
+
return new (0, _chunkWND32L6Pcjs.EmmettError)(
|
|
106
106
|
`Error: Couldn't load file:` + error.toString()
|
|
107
107
|
);
|
|
108
108
|
}
|
|
@@ -112,7 +112,7 @@ var loadPlugins = async (options) => {
|
|
|
112
112
|
const pluginsConfig = await importPluginsConfig({
|
|
113
113
|
configPath: _optionalChain([options, 'optionalAccess', _3 => _3.configPath])
|
|
114
114
|
});
|
|
115
|
-
if (pluginsConfig instanceof
|
|
115
|
+
if (pluginsConfig instanceof _chunkWND32L6Pcjs.EmmettError) throw pluginsConfig;
|
|
116
116
|
if (pluginsConfig.plugins.length === 0) {
|
|
117
117
|
console.log(`No extensions specified in config ${_optionalChain([options, 'optionalAccess', _4 => _4.configPath])}.`);
|
|
118
118
|
return [];
|
package/dist/cli.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-
|
|
3
|
+
import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-Amos00J7.cjs';
|
|
4
4
|
|
|
5
5
|
declare const sampleConfig: (plugins?: string[]) => string;
|
|
6
6
|
declare const generateConfigFile: (configPath: string, collectionNames: string[]) => void;
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-
|
|
3
|
+
import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-Amos00J7.js';
|
|
4
4
|
|
|
5
5
|
declare const sampleConfig: (plugins?: string[]) => string;
|
|
6
6
|
declare const generateConfigFile: (configPath: string, collectionNames: string[]) => void;
|
package/dist/cli.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
EmmettError,
|
|
4
4
|
isPluginConfig
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-AZDDB5SF.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { Command } from "commander";
|
|
9
9
|
|
|
10
10
|
// src/commandLine/config.ts
|
|
11
11
|
import { Command as CliCommand } from "commander";
|
|
12
|
-
import { writeFileSync } from "
|
|
12
|
+
import { writeFileSync } from "fs";
|
|
13
13
|
import { exit } from "process";
|
|
14
14
|
var sampleConfig = (plugins = ["emmett-expressjs"]) => {
|
|
15
15
|
const pluginsNames = plugins.length > 0 ? `[
|
|
@@ -26,6 +26,13 @@ type EmmettPluginsConfig = {
|
|
|
26
26
|
type ErrorConstructor<ErrorType extends Error> = new (...args: any[]) => ErrorType;
|
|
27
27
|
declare const isErrorConstructor: <ErrorType extends Error>(expect: Function) => expect is ErrorConstructor<ErrorType>;
|
|
28
28
|
declare class EmmettError extends Error {
|
|
29
|
+
static readonly Codes: {
|
|
30
|
+
ValidationError: number;
|
|
31
|
+
IllegalStateError: number;
|
|
32
|
+
NotFoundError: number;
|
|
33
|
+
ConcurrencyError: number;
|
|
34
|
+
InternalServerError: number;
|
|
35
|
+
};
|
|
29
36
|
errorCode: number;
|
|
30
37
|
constructor(options?: {
|
|
31
38
|
errorCode: number;
|
|
@@ -35,6 +42,7 @@ declare class EmmettError extends Error {
|
|
|
35
42
|
message?: string;
|
|
36
43
|
errorCode?: number;
|
|
37
44
|
}): EmmettError;
|
|
45
|
+
static isInstanceOf<ErrorType extends EmmettError = EmmettError>(error: unknown, errorCode?: (typeof EmmettError.Codes)[keyof typeof EmmettError.Codes]): error is ErrorType;
|
|
38
46
|
}
|
|
39
47
|
declare class ConcurrencyError extends EmmettError {
|
|
40
48
|
current: string | undefined;
|
|
@@ -26,6 +26,13 @@ type EmmettPluginsConfig = {
|
|
|
26
26
|
type ErrorConstructor<ErrorType extends Error> = new (...args: any[]) => ErrorType;
|
|
27
27
|
declare const isErrorConstructor: <ErrorType extends Error>(expect: Function) => expect is ErrorConstructor<ErrorType>;
|
|
28
28
|
declare class EmmettError extends Error {
|
|
29
|
+
static readonly Codes: {
|
|
30
|
+
ValidationError: number;
|
|
31
|
+
IllegalStateError: number;
|
|
32
|
+
NotFoundError: number;
|
|
33
|
+
ConcurrencyError: number;
|
|
34
|
+
InternalServerError: number;
|
|
35
|
+
};
|
|
29
36
|
errorCode: number;
|
|
30
37
|
constructor(options?: {
|
|
31
38
|
errorCode: number;
|
|
@@ -35,6 +42,7 @@ declare class EmmettError extends Error {
|
|
|
35
42
|
message?: string;
|
|
36
43
|
errorCode?: number;
|
|
37
44
|
}): EmmettError;
|
|
45
|
+
static isInstanceOf<ErrorType extends EmmettError = EmmettError>(error: unknown, errorCode?: (typeof EmmettError.Codes)[keyof typeof EmmettError.Codes]): error is ErrorType;
|
|
38
46
|
}
|
|
39
47
|
declare class ConcurrencyError extends EmmettError {
|
|
40
48
|
current: string | undefined;
|