@event-driven-io/emmett 0.38.2 → 0.38.4

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.
@@ -45,6 +45,15 @@ var EmmettError = class _EmmettError extends Error {
45
45
  this.errorCode = errorCode;
46
46
  Object.setPrototypeOf(this, _EmmettError.prototype);
47
47
  }
48
+ static mapFrom(error) {
49
+ if (error instanceof _EmmettError) {
50
+ return error;
51
+ }
52
+ return new _EmmettError({
53
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : 500,
54
+ message: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
55
+ });
56
+ }
48
57
  };
49
58
  var ConcurrencyError = class _ConcurrencyError extends EmmettError {
50
59
  constructor(current, expected, message) {
@@ -139,4 +148,4 @@ var parseDateFromUtcYYYYMMDD = (dateString) => {
139
148
 
140
149
 
141
150
  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;
142
- //# sourceMappingURL=chunk-ZRFRNMXL.cjs.map
151
+ //# sourceMappingURL=chunk-FMH3M5GB.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-FMH3M5GB.cjs","../src/config/plugins/index.ts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;AACC,IAAA;AACF,EAAA;AAIP,EAAA;AACF;AAGO;AACL,EAAA;AACA,EAAA;AACF;AAEO;AACL,EAAA;AAEA,EAAA;AACE,IAAA;AAAmE,EAAA;AAGrE,EAAA;AACE,IAAA;AAA+C,EAAA;AAGjD,EAAA;AACF;AJgGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-FMH3M5GB.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 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 : 500;\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 (error instanceof EmmettError) {\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 : 500,\n message: error.message ?? 'An unknown error occurred',\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: 412,\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\nexport class ConcurrencyInMemoryDatabaseError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 412,\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: 400,\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: 403,\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: 404,\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"]}
@@ -45,6 +45,15 @@ var EmmettError = class _EmmettError extends Error {
45
45
  this.errorCode = errorCode;
46
46
  Object.setPrototypeOf(this, _EmmettError.prototype);
47
47
  }
48
+ static mapFrom(error) {
49
+ if (error instanceof _EmmettError) {
50
+ return error;
51
+ }
52
+ return new _EmmettError({
53
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : 500,
54
+ message: error.message ?? "An unknown error occurred"
55
+ });
56
+ }
48
57
  };
49
58
  var ConcurrencyError = class _ConcurrencyError extends EmmettError {
50
59
  constructor(current, expected, message) {
@@ -139,4 +148,4 @@ export {
139
148
  IllegalStateError,
140
149
  NotFoundError
141
150
  };
142
- //# sourceMappingURL=chunk-SJ7ERGWB.js.map
151
+ //# sourceMappingURL=chunk-O2VMBOV4.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 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 : 500;\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 (error instanceof EmmettError) {\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 : 500,\n message: error.message ?? 'An unknown error occurred',\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: 412,\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\nexport class ConcurrencyInMemoryDatabaseError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 412,\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: 400,\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: 403,\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: 404,\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,Q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AAA,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"]}
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 _chunkZRFRNMXLcjs = require('./chunk-ZRFRNMXL.cjs');
5
+ var _chunkFMH3M5GBcjs = require('./chunk-FMH3M5GB.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, _chunkZRFRNMXLcjs.EmmettError)(PluginsConfigImportError.missingDefaultExport);
89
+ return new (0, _chunkFMH3M5GBcjs.EmmettError)(PluginsConfigImportError.missingDefaultExport);
90
90
  }
91
91
  if (!imported.default.plugins || !Array.isArray(imported.default.plugins)) {
92
- return new (0, _chunkZRFRNMXLcjs.EmmettError)(
92
+ return new (0, _chunkFMH3M5GBcjs.EmmettError)(
93
93
  PluginsConfigImportError.missingPluginsPropertyExport
94
94
  );
95
95
  }
96
- if (!imported.default.plugins.every(_chunkZRFRNMXLcjs.isPluginConfig)) {
97
- return new (0, _chunkZRFRNMXLcjs.EmmettError)(PluginsConfigImportError.wrongPluginStructure);
96
+ if (!imported.default.plugins.every(_chunkFMH3M5GBcjs.isPluginConfig)) {
97
+ return new (0, _chunkFMH3M5GBcjs.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, _chunkZRFRNMXLcjs.EmmettError)(
105
+ return new (0, _chunkFMH3M5GBcjs.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 _chunkZRFRNMXLcjs.EmmettError) throw pluginsConfig;
115
+ if (pluginsConfig instanceof _chunkFMH3M5GBcjs.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-CKESCXxJ.cjs';
3
+ import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-7wNEMFlg.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-CKESCXxJ.js';
3
+ import { E as EmmettPluginsConfig, a as EmmettError, b as EmmettPluginType, c as EmmettPlugin, d as EmmettCliPlugin } from './index-7wNEMFlg.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,7 +2,7 @@
2
2
  import {
3
3
  EmmettError,
4
4
  isPluginConfig
5
- } from "./chunk-SJ7ERGWB.js";
5
+ } from "./chunk-O2VMBOV4.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { Command } from "commander";
@@ -31,6 +31,10 @@ declare class EmmettError extends Error {
31
31
  errorCode: number;
32
32
  message?: string;
33
33
  } | string | number);
34
+ static mapFrom(error: Error | {
35
+ message?: string;
36
+ errorCode?: number;
37
+ }): EmmettError;
34
38
  }
35
39
  declare class ConcurrencyError extends EmmettError {
36
40
  current: string | undefined;
@@ -31,6 +31,10 @@ declare class EmmettError extends Error {
31
31
  errorCode: number;
32
32
  message?: string;
33
33
  } | string | number);
34
+ static mapFrom(error: Error | {
35
+ message?: string;
36
+ errorCode?: number;
37
+ }): EmmettError;
34
38
  }
35
39
  declare class ConcurrencyError extends EmmettError {
36
40
  current: string | undefined;
package/dist/index.cjs CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
 
19
19
 
20
- var _chunkZRFRNMXLcjs = require('./chunk-ZRFRNMXL.cjs');
20
+ var _chunkFMH3M5GBcjs = require('./chunk-FMH3M5GB.cjs');
21
21
 
22
22
  // src/typing/command.ts
23
23
  var command = (...args) => {
@@ -140,7 +140,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
140
140
  if (!matchesExpectedVersion(current, expected, defaultVersion))
141
141
  throw new ExpectedVersionConflictError(current, expected);
142
142
  };
143
- var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends _chunkZRFRNMXLcjs.ConcurrencyError {
143
+ var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends _chunkFMH3M5GBcjs.ConcurrencyError {
144
144
  constructor(current, expected) {
145
145
  super(_optionalChain([current, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()]), _optionalChain([expected, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]));
146
146
  Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
@@ -250,7 +250,7 @@ var TaskProcessor = (_class = class {
250
250
  enqueue(task, options) {
251
251
  if (this.queue.length >= this.options.maxQueueSize) {
252
252
  return Promise.reject(
253
- new (0, _chunkZRFRNMXLcjs.EmmettError)(
253
+ new (0, _chunkFMH3M5GBcjs.EmmettError)(
254
254
  "Too many pending connections. Please try again later."
255
255
  )
256
256
  );
@@ -410,6 +410,21 @@ var InProcessLock = () => {
410
410
  };
411
411
  };
412
412
 
413
+ // src/utils/promises.ts
414
+ var delay = (ms) => {
415
+ return new Promise((resolve) => setTimeout(resolve, ms));
416
+ };
417
+ var asyncAwaiter = () => {
418
+ const result = {};
419
+ (result.reset = () => {
420
+ result.wait = new Promise((res, rej) => {
421
+ result.resolve = res;
422
+ result.reject = rej;
423
+ });
424
+ })();
425
+ return result;
426
+ };
427
+
413
428
  // src/utils/retry.ts
414
429
  var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
415
430
 
@@ -445,7 +460,7 @@ var asyncRetry = async (fn, opts) => {
445
460
  try {
446
461
  const result = await fn();
447
462
  if (_optionalChain([opts, 'optionalAccess', _27 => _27.shouldRetryResult]) && opts.shouldRetryResult(result)) {
448
- throw new (0, _chunkZRFRNMXLcjs.EmmettError)(
463
+ throw new (0, _chunkFMH3M5GBcjs.EmmettError)(
449
464
  `Retrying because of result: ${JSONParser.stringify(result)}`
450
465
  );
451
466
  }
@@ -453,6 +468,7 @@ var asyncRetry = async (fn, opts) => {
453
468
  } catch (error2) {
454
469
  if (_optionalChain([opts, 'optionalAccess', _28 => _28.shouldRetryError]) && !opts.shouldRetryError(error2)) {
455
470
  bail(error2);
471
+ return void 0;
456
472
  }
457
473
  throw error2;
458
474
  }
@@ -475,7 +491,7 @@ var operationResult = (result, options) => {
475
491
  const { successful } = result;
476
492
  const { operationName, collectionName } = options;
477
493
  if (!successful)
478
- throw new (0, _chunkZRFRNMXLcjs.ConcurrencyInMemoryDatabaseError)(
494
+ throw new (0, _chunkFMH3M5GBcjs.ConcurrencyInMemoryDatabaseError)(
479
495
  _nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${JSONParser.stringify(result)}!`))
480
496
  );
481
497
  }
@@ -589,8 +605,9 @@ var getInMemoryDatabase = () => {
589
605
  replaceOne: (predicate, document, options) => {
590
606
  ensureCollectionCreated();
591
607
  const documentsInCollection = storage.get(collectionName);
592
- const foundIndexes = documentsInCollection.filter((doc) => predicate(doc)).map((_, index) => index);
593
- const firstIndex = foundIndexes[0];
608
+ const firstIndex = documentsInCollection.findIndex(
609
+ (doc) => predicate(doc)
610
+ );
594
611
  if (firstIndex === void 0 || firstIndex === -1) {
595
612
  return Promise.resolve(
596
613
  operationResult(
@@ -630,7 +647,7 @@ var getInMemoryDatabase = () => {
630
647
  {
631
648
  successful: true,
632
649
  modifiedCount: 1,
633
- matchedCount: foundIndexes.length,
650
+ matchedCount: firstIndex,
634
651
  nextExpectedVersion: newVersion
635
652
  },
636
653
  { operationName: "replaceOne", collectionName, errors }
@@ -1122,7 +1139,7 @@ function thenNothingHappensHandler(events) {
1122
1139
  function thenThrowsErrorHandler(error2, args) {
1123
1140
  if (error2 instanceof AssertionError) throw error2;
1124
1141
  if (args.length === 0) return;
1125
- if (!_chunkZRFRNMXLcjs.isErrorConstructor.call(void 0, args[0])) {
1142
+ if (!_chunkFMH3M5GBcjs.isErrorConstructor.call(void 0, args[0])) {
1126
1143
  assertTrue(
1127
1144
  args[0](error2),
1128
1145
  `Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess', _61 => _61.toString, 'call', _62 => _62()])}`
@@ -1261,7 +1278,7 @@ var InMemoryProjectionSpec = {
1261
1278
  } catch (error2) {
1262
1279
  if (error2 instanceof AssertionError) throw error2;
1263
1280
  if (args.length === 0) return;
1264
- if (!_chunkZRFRNMXLcjs.isErrorConstructor.call(void 0, args[0])) {
1281
+ if (!_chunkFMH3M5GBcjs.isErrorConstructor.call(void 0, args[0])) {
1265
1282
  assertTrue(
1266
1283
  args[0](error2),
1267
1284
  `Error didn't match the error condition: ${_optionalChain([error2, 'optionalAccess', _70 => _70.toString, 'call', _71 => _71()])}`
@@ -1314,7 +1331,7 @@ function documentExists(expected, options) {
1314
1331
  }
1315
1332
  for (const [key, value] of Object.entries(expected)) {
1316
1333
  const propKey = key;
1317
- if (!(key in document) || JSON.stringify(document[propKey]) !== JSON.stringify(value)) {
1334
+ if (!(key in document) || JSONParser.stringify(document[propKey]) !== JSONParser.stringify(value)) {
1318
1335
  assertFails(`Property ${key} doesn't match the expected value`);
1319
1336
  return Promise.resolve(false);
1320
1337
  }
@@ -1665,7 +1682,7 @@ var getInMemoryMessageBus = () => {
1665
1682
  send: async (command2) => {
1666
1683
  const handlers = allHandlers.get(command2.type);
1667
1684
  if (handlers === void 0 || handlers.length === 0)
1668
- throw new (0, _chunkZRFRNMXLcjs.EmmettError)(
1685
+ throw new (0, _chunkFMH3M5GBcjs.EmmettError)(
1669
1686
  `No handler registered for command ${command2.type}!`
1670
1687
  );
1671
1688
  const commandHandler = handlers[0];
@@ -1686,7 +1703,7 @@ var getInMemoryMessageBus = () => {
1686
1703
  (registered) => commandTypes.includes(registered)
1687
1704
  );
1688
1705
  if (alreadyRegistered.length > 0)
1689
- throw new (0, _chunkZRFRNMXLcjs.EmmettError)(
1706
+ throw new (0, _chunkFMH3M5GBcjs.EmmettError)(
1690
1707
  `Cannot register handler for commands ${alreadyRegistered.join(", ")} as they're already registered!`
1691
1708
  );
1692
1709
  for (const commandType of commandTypes) {
@@ -1715,19 +1732,24 @@ var getInMemoryMessageBus = () => {
1715
1732
  // src/processors/processors.ts
1716
1733
  var getCheckpoint = (message2) => {
1717
1734
  return "checkpoint" in message2.metadata && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1718
- _chunkZRFRNMXLcjs.isBigint.call(void 0, message2.metadata.checkpoint) ? (
1735
+ _chunkFMH3M5GBcjs.isBigint.call(void 0, message2.metadata.checkpoint) ? (
1719
1736
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1720
1737
  message2.metadata.checkpoint
1721
1738
  ) : "globalPosition" in message2.metadata && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1722
- _chunkZRFRNMXLcjs.isBigint.call(void 0, message2.metadata.globalPosition) ? (
1739
+ _chunkFMH3M5GBcjs.isBigint.call(void 0, message2.metadata.globalPosition) ? (
1723
1740
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1724
1741
  message2.metadata.globalPosition
1725
1742
  ) : "streamPosition" in message2.metadata && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1726
- _chunkZRFRNMXLcjs.isBigint.call(void 0, message2.metadata.streamPosition) ? (
1743
+ _chunkFMH3M5GBcjs.isBigint.call(void 0, message2.metadata.streamPosition) ? (
1727
1744
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1728
1745
  message2.metadata.streamPosition
1729
1746
  ) : null;
1730
1747
  };
1748
+ var wasMessageHandled = (message2, checkpoint) => {
1749
+ const messageCheckpoint = getCheckpoint(message2);
1750
+ const checkpointBigint = checkpoint;
1751
+ return messageCheckpoint !== null && messageCheckpoint !== void 0 && checkpointBigint !== null && checkpointBigint !== void 0 && messageCheckpoint <= checkpointBigint;
1752
+ };
1731
1753
  var MessageProcessorType = {
1732
1754
  PROJECTOR: "projector",
1733
1755
  REACTOR: "reactor"
@@ -1791,6 +1813,7 @@ var reactor = (options) => {
1791
1813
  return await processingScope(async (context) => {
1792
1814
  let result = void 0;
1793
1815
  for (const message2 of messages) {
1816
+ if (wasMessageHandled(message2, lastCheckpoint)) continue;
1794
1817
  const messageProcessingResult = await eachMessage(message2, context);
1795
1818
  if (checkpoints) {
1796
1819
  const storeCheckpointResult = await checkpoints.store(
@@ -1803,7 +1826,7 @@ var reactor = (options) => {
1803
1826
  },
1804
1827
  context
1805
1828
  );
1806
- if (storeCheckpointResult && storeCheckpointResult.success) {
1829
+ if (storeCheckpointResult.success) {
1807
1830
  lastCheckpoint = storeCheckpointResult.newCheckpoint;
1808
1831
  }
1809
1832
  }
@@ -1865,17 +1888,18 @@ var inMemoryCheckpointer = () => {
1865
1888
  );
1866
1889
  const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _111 => _111.lastCheckpoint]), () => ( null));
1867
1890
  const newCheckpoint = getCheckpoint(message2);
1868
- if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint))
1869
- return Promise.resolve({
1891
+ if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint)) {
1892
+ return {
1870
1893
  success: false,
1871
1894
  reason: currentPosition === newCheckpoint ? "IGNORED" : "MISMATCH"
1872
- });
1895
+ };
1896
+ }
1873
1897
  await checkpoints.handle(processorId, (existing) => ({
1874
1898
  ..._nullishCoalesce(existing, () => ( {})),
1875
1899
  _id: processorId,
1876
1900
  lastCheckpoint: newCheckpoint
1877
1901
  }));
1878
- return Promise.resolve({ success: true, newCheckpoint });
1902
+ return { success: true, newCheckpoint };
1879
1903
  }
1880
1904
  };
1881
1905
  };
@@ -1884,7 +1908,7 @@ var inMemoryProcessingScope = (options) => {
1884
1908
  const processingScope = (handler, partialContext) => {
1885
1909
  const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _112 => _112.database])));
1886
1910
  if (!database)
1887
- throw new (0, _chunkZRFRNMXLcjs.EmmettError)(
1911
+ throw new (0, _chunkFMH3M5GBcjs.EmmettError)(
1888
1912
  `InMemory processor '${options.processorId}' is missing database. Ensure that you passed it through options`
1889
1913
  );
1890
1914
  return handler({ ...partialContext, database });
@@ -1942,7 +1966,7 @@ var filterProjections = (type, projections2) => {
1942
1966
  (proj) => proj.name
1943
1967
  );
1944
1968
  if (duplicateRegistrations.length > 0) {
1945
- throw new (0, _chunkZRFRNMXLcjs.EmmettError)(`You cannot register multiple projections with the same name (or without the name).
1969
+ throw new (0, _chunkFMH3M5GBcjs.EmmettError)(`You cannot register multiple projections with the same name (or without the name).
1946
1970
  Ensure that:
1947
1971
  ${JSONParser.stringify(duplicateRegistrations)}
1948
1972
  have different names`);
@@ -2444,5 +2468,8 @@ var decodeAndTransform = (decoder, transform, controller) => {
2444
2468
 
2445
2469
 
2446
2470
 
2447
- exports.AssertionError = AssertionError; exports.BinaryJsonDecoder = BinaryJsonDecoder; exports.CaughtUpTransformStream = CaughtUpTransformStream; exports.CommandHandler = CommandHandler; exports.CommandHandlerStreamVersionConflictRetryOptions = CommandHandlerStreamVersionConflictRetryOptions; exports.CompositeDecoder = CompositeDecoder; exports.ConcurrencyError = _chunkZRFRNMXLcjs.ConcurrencyError; exports.ConcurrencyInMemoryDatabaseError = _chunkZRFRNMXLcjs.ConcurrencyInMemoryDatabaseError; exports.DATABASE_REQUIRED_ERROR_MESSAGE = DATABASE_REQUIRED_ERROR_MESSAGE; exports.DeciderCommandHandler = DeciderCommandHandler; exports.DeciderSpecification = DeciderSpecification; exports.DefaultDecoder = DefaultDecoder; exports.EmmettError = _chunkZRFRNMXLcjs.EmmettError; exports.ExpectedVersionConflictError = ExpectedVersionConflictError; exports.GlobalStreamCaughtUpType = GlobalStreamCaughtUpType; exports.IllegalStateError = _chunkZRFRNMXLcjs.IllegalStateError; exports.InMemoryEventStoreDefaultStreamVersion = InMemoryEventStoreDefaultStreamVersion; exports.InMemoryProjectionSpec = InMemoryProjectionSpec; exports.InProcessLock = InProcessLock; exports.JSONParser = JSONParser; exports.JsonDecoder = JsonDecoder; exports.MessageProcessor = MessageProcessor; exports.MessageProcessorType = MessageProcessorType; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.NoRetries = NoRetries; exports.NotFoundError = _chunkZRFRNMXLcjs.NotFoundError; exports.ObjectDecoder = ObjectDecoder; exports.ParseError = ParseError; exports.STREAM_DOES_NOT_EXIST = STREAM_DOES_NOT_EXIST; exports.STREAM_EXISTS = STREAM_EXISTS; exports.StreamingCoordinator = StreamingCoordinator; exports.StringDecoder = StringDecoder; exports.TaskProcessor = TaskProcessor; exports.ValidationError = _chunkZRFRNMXLcjs.ValidationError; exports.ValidationErrors = _chunkZRFRNMXLcjs.ValidationErrors; exports.WrapEventStore = WrapEventStore; exports.accept = accept; exports.argMatches = argMatches; exports.argValue = argValue; exports.arrayUtils = arrayUtils; exports.assertDeepEqual = assertDeepEqual; exports.assertDoesNotThrow = assertDoesNotThrow; exports.assertEqual = assertEqual; exports.assertExpectedVersionMatchesCurrent = assertExpectedVersionMatchesCurrent; exports.assertFails = assertFails; exports.assertFalse = assertFalse; exports.assertIsNotNull = assertIsNotNull; exports.assertIsNull = assertIsNull; exports.assertMatches = assertMatches; exports.assertNotDeepEqual = assertNotDeepEqual; exports.assertNotEmptyString = _chunkZRFRNMXLcjs.assertNotEmptyString; exports.assertNotEqual = assertNotEqual; exports.assertOk = assertOk; exports.assertPositiveNumber = _chunkZRFRNMXLcjs.assertPositiveNumber; exports.assertRejects = assertRejects; exports.assertThat = assertThat; exports.assertThatArray = assertThatArray; exports.assertThrows = assertThrows; exports.assertThrowsAsync = assertThrowsAsync; exports.assertTrue = assertTrue; exports.assertUnsignedBigInt = _chunkZRFRNMXLcjs.assertUnsignedBigInt; exports.asyncProjections = asyncProjections; exports.asyncRetry = asyncRetry; exports.canCreateEventStoreSession = canCreateEventStoreSession; exports.caughtUpEventFrom = caughtUpEventFrom; exports.collect = collect; exports.command = command; exports.complete = complete; exports.concatUint8Arrays = concatUint8Arrays; exports.deepEquals = deepEquals; exports.defaultProcessingMessageProcessingScope = defaultProcessingMessageProcessingScope; exports.documentExists = documentExists; exports.error = error; exports.event = event; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectInMemoryDocuments = expectInMemoryDocuments; exports.filterProjections = filterProjections; exports.formatDateToUtcYYYYMMDD = _chunkZRFRNMXLcjs.formatDateToUtcYYYYMMDD; exports.forwardToMessageBus = forwardToMessageBus; exports.getCheckpoint = getCheckpoint; exports.getInMemoryDatabase = getInMemoryDatabase; exports.getInMemoryEventStore = getInMemoryEventStore; exports.getInMemoryMessageBus = getInMemoryMessageBus; exports.globalStreamCaughtUp = globalStreamCaughtUp; exports.handleInMemoryProjections = handleInMemoryProjections; exports.ignore = ignore; exports.inMemoryCheckpointer = inMemoryCheckpointer; exports.inMemoryMultiStreamProjection = inMemoryMultiStreamProjection; exports.inMemoryProjection = inMemoryProjection; exports.inMemoryProjector = inMemoryProjector; exports.inMemoryReactor = inMemoryReactor; exports.inMemorySingleStreamProjection = inMemorySingleStreamProjection; exports.inlineProjections = inlineProjections; exports.isBigint = _chunkZRFRNMXLcjs.isBigint; exports.isEquatable = isEquatable; exports.isErrorConstructor = _chunkZRFRNMXLcjs.isErrorConstructor; exports.isExpectedVersionConflictError = isExpectedVersionConflictError; exports.isGlobalStreamCaughtUp = isGlobalStreamCaughtUp; exports.isNotInternalEvent = isNotInternalEvent; exports.isNumber = _chunkZRFRNMXLcjs.isNumber; exports.isPluginConfig = _chunkZRFRNMXLcjs.isPluginConfig; exports.isString = _chunkZRFRNMXLcjs.isString; exports.isSubscriptionEvent = isSubscriptionEvent; exports.isSubset = isSubset; exports.isValidYYYYMMDD = _chunkZRFRNMXLcjs.isValidYYYYMMDD; exports.matchesExpectedVersion = matchesExpectedVersion; exports.merge = merge; exports.message = message; exports.newEventsInStream = newEventsInStream; exports.nulloSessionFactory = nulloSessionFactory; exports.parseDateFromUtcYYYYMMDD = _chunkZRFRNMXLcjs.parseDateFromUtcYYYYMMDD; exports.projection = projection; exports.projections = projections; exports.projector = projector; exports.publish = publish; exports.reactor = reactor; exports.reply = reply; exports.restream = restream; exports.schedule = schedule; exports.send = send; exports.streamGenerators = streamGenerators; exports.streamTrackingGlobalPosition = streamTrackingGlobalPosition; exports.streamTransformations = streamTransformations; exports.sum = sum; exports.tryPublishMessagesAfterCommit = tryPublishMessagesAfterCommit; exports.verifyThat = verifyThat;
2471
+
2472
+
2473
+
2474
+ exports.AssertionError = AssertionError; exports.BinaryJsonDecoder = BinaryJsonDecoder; exports.CaughtUpTransformStream = CaughtUpTransformStream; exports.CommandHandler = CommandHandler; exports.CommandHandlerStreamVersionConflictRetryOptions = CommandHandlerStreamVersionConflictRetryOptions; exports.CompositeDecoder = CompositeDecoder; exports.ConcurrencyError = _chunkFMH3M5GBcjs.ConcurrencyError; exports.ConcurrencyInMemoryDatabaseError = _chunkFMH3M5GBcjs.ConcurrencyInMemoryDatabaseError; exports.DATABASE_REQUIRED_ERROR_MESSAGE = DATABASE_REQUIRED_ERROR_MESSAGE; exports.DeciderCommandHandler = DeciderCommandHandler; exports.DeciderSpecification = DeciderSpecification; exports.DefaultDecoder = DefaultDecoder; exports.EmmettError = _chunkFMH3M5GBcjs.EmmettError; exports.ExpectedVersionConflictError = ExpectedVersionConflictError; exports.GlobalStreamCaughtUpType = GlobalStreamCaughtUpType; exports.IllegalStateError = _chunkFMH3M5GBcjs.IllegalStateError; exports.InMemoryEventStoreDefaultStreamVersion = InMemoryEventStoreDefaultStreamVersion; exports.InMemoryProjectionSpec = InMemoryProjectionSpec; exports.InProcessLock = InProcessLock; exports.JSONParser = JSONParser; exports.JsonDecoder = JsonDecoder; exports.MessageProcessor = MessageProcessor; exports.MessageProcessorType = MessageProcessorType; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.NoRetries = NoRetries; exports.NotFoundError = _chunkFMH3M5GBcjs.NotFoundError; exports.ObjectDecoder = ObjectDecoder; exports.ParseError = ParseError; exports.STREAM_DOES_NOT_EXIST = STREAM_DOES_NOT_EXIST; exports.STREAM_EXISTS = STREAM_EXISTS; exports.StreamingCoordinator = StreamingCoordinator; exports.StringDecoder = StringDecoder; exports.TaskProcessor = TaskProcessor; exports.ValidationError = _chunkFMH3M5GBcjs.ValidationError; exports.ValidationErrors = _chunkFMH3M5GBcjs.ValidationErrors; exports.WrapEventStore = WrapEventStore; exports.accept = accept; exports.argMatches = argMatches; exports.argValue = argValue; exports.arrayUtils = arrayUtils; exports.assertDeepEqual = assertDeepEqual; exports.assertDoesNotThrow = assertDoesNotThrow; exports.assertEqual = assertEqual; exports.assertExpectedVersionMatchesCurrent = assertExpectedVersionMatchesCurrent; exports.assertFails = assertFails; exports.assertFalse = assertFalse; exports.assertIsNotNull = assertIsNotNull; exports.assertIsNull = assertIsNull; exports.assertMatches = assertMatches; exports.assertNotDeepEqual = assertNotDeepEqual; exports.assertNotEmptyString = _chunkFMH3M5GBcjs.assertNotEmptyString; exports.assertNotEqual = assertNotEqual; exports.assertOk = assertOk; exports.assertPositiveNumber = _chunkFMH3M5GBcjs.assertPositiveNumber; exports.assertRejects = assertRejects; exports.assertThat = assertThat; exports.assertThatArray = assertThatArray; exports.assertThrows = assertThrows; exports.assertThrowsAsync = assertThrowsAsync; exports.assertTrue = assertTrue; exports.assertUnsignedBigInt = _chunkFMH3M5GBcjs.assertUnsignedBigInt; exports.asyncAwaiter = asyncAwaiter; exports.asyncProjections = asyncProjections; exports.asyncRetry = asyncRetry; exports.canCreateEventStoreSession = canCreateEventStoreSession; exports.caughtUpEventFrom = caughtUpEventFrom; exports.collect = collect; exports.command = command; exports.complete = complete; exports.concatUint8Arrays = concatUint8Arrays; exports.deepEquals = deepEquals; exports.defaultProcessingMessageProcessingScope = defaultProcessingMessageProcessingScope; exports.delay = delay; exports.documentExists = documentExists; exports.error = error; exports.event = event; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectInMemoryDocuments = expectInMemoryDocuments; exports.filterProjections = filterProjections; exports.formatDateToUtcYYYYMMDD = _chunkFMH3M5GBcjs.formatDateToUtcYYYYMMDD; exports.forwardToMessageBus = forwardToMessageBus; exports.getCheckpoint = getCheckpoint; exports.getInMemoryDatabase = getInMemoryDatabase; exports.getInMemoryEventStore = getInMemoryEventStore; exports.getInMemoryMessageBus = getInMemoryMessageBus; exports.globalStreamCaughtUp = globalStreamCaughtUp; exports.handleInMemoryProjections = handleInMemoryProjections; exports.ignore = ignore; exports.inMemoryCheckpointer = inMemoryCheckpointer; exports.inMemoryMultiStreamProjection = inMemoryMultiStreamProjection; exports.inMemoryProjection = inMemoryProjection; exports.inMemoryProjector = inMemoryProjector; exports.inMemoryReactor = inMemoryReactor; exports.inMemorySingleStreamProjection = inMemorySingleStreamProjection; exports.inlineProjections = inlineProjections; exports.isBigint = _chunkFMH3M5GBcjs.isBigint; exports.isEquatable = isEquatable; exports.isErrorConstructor = _chunkFMH3M5GBcjs.isErrorConstructor; exports.isExpectedVersionConflictError = isExpectedVersionConflictError; exports.isGlobalStreamCaughtUp = isGlobalStreamCaughtUp; exports.isNotInternalEvent = isNotInternalEvent; exports.isNumber = _chunkFMH3M5GBcjs.isNumber; exports.isPluginConfig = _chunkFMH3M5GBcjs.isPluginConfig; exports.isString = _chunkFMH3M5GBcjs.isString; exports.isSubscriptionEvent = isSubscriptionEvent; exports.isSubset = isSubset; exports.isValidYYYYMMDD = _chunkFMH3M5GBcjs.isValidYYYYMMDD; exports.matchesExpectedVersion = matchesExpectedVersion; exports.merge = merge; exports.message = message; exports.newEventsInStream = newEventsInStream; exports.nulloSessionFactory = nulloSessionFactory; exports.parseDateFromUtcYYYYMMDD = _chunkFMH3M5GBcjs.parseDateFromUtcYYYYMMDD; exports.projection = projection; exports.projections = projections; exports.projector = projector; exports.publish = publish; exports.reactor = reactor; exports.reply = reply; exports.restream = restream; exports.schedule = schedule; exports.send = send; exports.streamGenerators = streamGenerators; exports.streamTrackingGlobalPosition = streamTrackingGlobalPosition; exports.streamTransformations = streamTransformations; exports.sum = sum; exports.tryPublishMessagesAfterCommit = tryPublishMessagesAfterCommit; exports.verifyThat = verifyThat; exports.wasMessageHandled = wasMessageHandled;
2448
2475
  //# sourceMappingURL=index.cjs.map