@venizia/ignis-helpers 0.5.0-2 → 0.5.0-3
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/esm/common/const-class.d.ts +22 -0
- package/dist/esm/common/const-class.js +41 -0
- package/dist/esm/common/const-class.js.map +1 -0
- package/dist/esm/common/constants/duration.d.ts +3 -4
- package/dist/esm/common/constants/duration.js +3 -15
- package/dist/esm/common/constants/duration.js.map +1 -1
- package/dist/esm/common/constants/http.d.ts +2 -3
- package/dist/esm/common/constants/http.js +2 -5
- package/dist/esm/common/constants/http.js.map +1 -1
- package/dist/esm/common/constants/mime.d.ts +3 -6
- package/dist/esm/common/constants/mime.js +3 -66
- package/dist/esm/common/constants/mime.js.map +1 -1
- package/dist/esm/common/index.d.ts +1 -0
- package/dist/esm/common/index.js +1 -0
- package/dist/esm/common/index.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts +2 -3
- package/dist/esm/modules/crypto/algorithms/aes.constants.js +2 -5
- package/dist/esm/modules/crypto/algorithms/aes.constants.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +1 -1
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/common/constants.d.ts +4 -9
- package/dist/esm/modules/crypto/common/constants.js +4 -21
- package/dist/esm/modules/crypto/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.d.ts +2 -3
- package/dist/esm/modules/logger/common/constants.js +2 -5
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/pino/common/constants.d.ts +2 -3
- package/dist/esm/modules/logger/pino/common/constants.js +2 -5
- package/dist/esm/modules/logger/pino/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/winston/formats.js +2 -2
- package/dist/esm/modules/logger/winston/formats.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +3 -4
- package/dist/esm/modules/queue/kafka/common/constants.js +2 -5
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/retry/common/constants.d.ts +3 -6
- package/dist/esm/modules/retry/common/constants.js +3 -15
- package/dist/esm/modules/retry/common/constants.js.map +1 -1
- package/dist/esm/modules/secrets/common/constants.d.ts +3 -6
- package/dist/esm/modules/secrets/common/constants.js +3 -10
- package/dist/esm/modules/secrets/common/constants.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/constants.d.ts +2 -4
- package/dist/esm/modules/socket/socket-io/common/constants.js +2 -9
- package/dist/esm/modules/socket/socket-io/common/constants.js.map +1 -1
- package/dist/esm/modules/socket/websocket/common/constants.d.ts +4 -9
- package/dist/esm/modules/socket/websocket/common/constants.js +4 -29
- package/dist/esm/modules/socket/websocket/common/constants.js.map +1 -1
- package/dist/esm/modules/temporal/abstract.js +1 -1
- package/dist/esm/modules/temporal/abstract.js.map +1 -1
- package/dist/esm/modules/temporal/common/constants.d.ts +6 -15
- package/dist/esm/modules/temporal/common/constants.js +6 -40
- package/dist/esm/modules/temporal/common/constants.js.map +1 -1
- package/dist/esm/modules/temporal/duration/duration.js +1 -1
- package/dist/esm/modules/temporal/duration/duration.js.map +1 -1
- package/dist/esm/modules/temporal/helper.js +1 -1
- package/dist/esm/modules/temporal/helper.js.map +1 -1
- package/dist/esm/modules/uid/common/constants.d.ts +3 -6
- package/dist/esm/modules/uid/common/constants.js +3 -10
- package/dist/esm/modules/uid/common/constants.js.map +1 -1
- package/dist/esm/modules/uid/opaque.js +1 -1
- package/dist/esm/modules/uid/opaque.js.map +1 -1
- package/dist/esm/modules/uid/token.js +1 -1
- package/dist/esm/modules/uid/token.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +2 -3
- package/dist/esm/utilities/request.utility.js +2 -5
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/dist/esm/utilities/retry.utility.js +2 -2
- package/dist/esm/utilities/retry.utility.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TConstValue } from './types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base of a const class: a class whose `static readonly` string members are its values. Extend it and the
|
|
4
|
+
* class reads its own values (`values`) and checks a candidate against them (`isValid`), so no class keeps a
|
|
5
|
+
* `SCHEME_SET` and an `isValid` of its own.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* class ArtifactTypes extends ConstClass {
|
|
9
|
+
* static readonly SERVICE = 'service';
|
|
10
|
+
* static readonly COMPONENT = 'component';
|
|
11
|
+
* }
|
|
12
|
+
* ArtifactTypes.isValid(input); // narrows `input` to 'service' | 'component'
|
|
13
|
+
* z.enum(ArtifactTypes.values());
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConstClass {
|
|
16
|
+
#private;
|
|
17
|
+
/** The string values of this class and of the classes it extends, base class first. Throws when there are none. */
|
|
18
|
+
static values<T extends typeof ConstClass>(this: T): readonly [TConstValue<T>, ...TConstValue<T>[]];
|
|
19
|
+
/** `true` when `value` is one of this class's values; narrows it to their union. */
|
|
20
|
+
static isValid<T extends typeof ConstClass>(this: T, value: unknown): value is TConstValue<T>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=const-class.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
+
/**
|
|
3
|
+
* Base of a const class: a class whose `static readonly` string members are its values. Extend it and the
|
|
4
|
+
* class reads its own values (`values`) and checks a candidate against them (`isValid`), so no class keeps a
|
|
5
|
+
* `SCHEME_SET` and an `isValid` of its own.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* class ArtifactTypes extends ConstClass {
|
|
9
|
+
* static readonly SERVICE = 'service';
|
|
10
|
+
* static readonly COMPONENT = 'component';
|
|
11
|
+
* }
|
|
12
|
+
* ArtifactTypes.isValid(input); // narrows `input` to 'service' | 'component'
|
|
13
|
+
* z.enum(ArtifactTypes.values());
|
|
14
|
+
*/
|
|
15
|
+
export class ConstClass {
|
|
16
|
+
static #cache = new WeakMap();
|
|
17
|
+
/** The string values of this class and of the classes it extends, base class first. Throws when there are none. */
|
|
18
|
+
static values() {
|
|
19
|
+
let values = ConstClass.#cache.get(this);
|
|
20
|
+
if (!values) {
|
|
21
|
+
// A subclass lists the values it inherits too, the base class's first.
|
|
22
|
+
const chain = [];
|
|
23
|
+
for (let base = this; base !== ConstClass && base !== Function.prototype; base = Object.getPrototypeOf(base)) {
|
|
24
|
+
chain.unshift(base);
|
|
25
|
+
}
|
|
26
|
+
values = [
|
|
27
|
+
...new Set(chain.flatMap((base) => Object.values(base).filter((value) => typeof value === 'string'))),
|
|
28
|
+
];
|
|
29
|
+
if (values.length === 0) {
|
|
30
|
+
throw getError({ message: `${this.name} has no values` });
|
|
31
|
+
}
|
|
32
|
+
ConstClass.#cache.set(this, values);
|
|
33
|
+
}
|
|
34
|
+
return values;
|
|
35
|
+
}
|
|
36
|
+
/** `true` when `value` is one of this class's values; narrows it to their union. */
|
|
37
|
+
static isValid(value) {
|
|
38
|
+
return typeof value === 'string' && this.values().includes(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=const-class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const-class.js","sourceRoot":"","sources":["../../../src/common/const-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,UAAU;IACrB,MAAM,CAAU,MAAM,GAAG,IAAI,OAAO,EAA6B,CAAC;IAElE,mHAAmH;IACnH,MAAM,CAAC,MAAM;QAGX,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,uEAAuE;YACvE,MAAM,KAAK,GAAa,EAAE,CAAC;YAE3B,KACE,IAAI,IAAI,GAAW,IAAI,EACvB,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,QAAQ,CAAC,SAAS,EAClD,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAClC,CAAC;gBACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAED,MAAM,GAAG;gBACP,GAAG,IAAI,GAAG,CACR,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACrB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAClF,CACF;aACF,CAAC;YAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC;YAC5D,CAAC;YAED,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,MAAmE,CAAC;IAC7E,CAAC;IAED,oFAAoF;IACpF,MAAM,CAAC,OAAO,CAAuC,KAAc;QACjE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,IAAI,CAAC,MAAM,EAAwB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3F,CAAC","sourcesContent":["import { getError } from '@venizia/ignis-inversion';\n\nimport type { TConstValue } from './types';\n\n/**\n * Base of a const class: a class whose `static readonly` string members are its values. Extend it and the\n * class reads its own values (`values`) and checks a candidate against them (`isValid`), so no class keeps a\n * `SCHEME_SET` and an `isValid` of its own.\n *\n * @example\n * class ArtifactTypes extends ConstClass {\n * static readonly SERVICE = 'service';\n * static readonly COMPONENT = 'component';\n * }\n * ArtifactTypes.isValid(input); // narrows `input` to 'service' | 'component'\n * z.enum(ArtifactTypes.values());\n */\nexport class ConstClass {\n static readonly #cache = new WeakMap<object, readonly string[]>();\n\n /** The string values of this class and of the classes it extends, base class first. Throws when there are none. */\n static values<T extends typeof ConstClass>(\n this: T,\n ): readonly [TConstValue<T>, ...TConstValue<T>[]] {\n let values = ConstClass.#cache.get(this);\n\n if (!values) {\n // A subclass lists the values it inherits too, the base class's first.\n const chain: object[] = [];\n\n for (\n let base: object = this;\n base !== ConstClass && base !== Function.prototype;\n base = Object.getPrototypeOf(base)\n ) {\n chain.unshift(base);\n }\n\n values = [\n ...new Set(\n chain.flatMap((base) =>\n Object.values(base).filter((value): value is string => typeof value === 'string'),\n ),\n ),\n ];\n\n if (values.length === 0) {\n throw getError({ message: `${this.name} has no values` });\n }\n\n ConstClass.#cache.set(this, values);\n }\n\n return values as unknown as readonly [TConstValue<T>, ...TConstValue<T>[]];\n }\n\n /** `true` when `value` is one of this class's values; narrows it to their union. */\n static isValid<T extends typeof ConstClass>(this: T, value: unknown): value is TConstValue<T> {\n return typeof value === 'string' && (this.values() as readonly string[]).includes(value);\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TConstValue } from '../types/index.js';
|
|
2
|
+
import { ConstClass } from '../const-class.js';
|
|
2
3
|
/** The time units a duration can be expressed in, smallest first. */
|
|
3
|
-
export declare class DurationUnits {
|
|
4
|
+
export declare class DurationUnits extends ConstClass {
|
|
4
5
|
static readonly MILLISECOND = "millisecond";
|
|
5
6
|
static readonly SECOND = "second";
|
|
6
7
|
static readonly MINUTE = "minute";
|
|
@@ -9,8 +10,6 @@ export declare class DurationUnits {
|
|
|
9
10
|
static readonly WEEK = "week";
|
|
10
11
|
static readonly MONTH = "month";
|
|
11
12
|
static readonly YEAR = "year";
|
|
12
|
-
static readonly SCHEME_SET: Set<string>;
|
|
13
|
-
static isValid(input: string): input is TDurationUnit;
|
|
14
13
|
}
|
|
15
14
|
/** One of the `DurationUnits` values, e.g. `'second'`. */
|
|
16
15
|
export type TDurationUnit = TConstValue<typeof DurationUnits>;
|
|
@@ -82,7 +81,7 @@ export declare class DurationMultipliers {
|
|
|
82
81
|
* `null` rather than a throw, so a caller that wants an error raises its own with its own context.
|
|
83
82
|
* Every method here answers the same way.
|
|
84
83
|
*
|
|
85
|
-
* The unit is checked against {@link DurationUnits.
|
|
84
|
+
* The unit is checked against {@link DurationUnits.isValid} first: a plain-object read alone
|
|
86
85
|
* would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.
|
|
87
86
|
*/
|
|
88
87
|
static toMilliseconds(opts: IDuration | null): number | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ConstClass } from '../const-class.js';
|
|
1
2
|
/** The time units a duration can be expressed in, smallest first. */
|
|
2
|
-
export class DurationUnits {
|
|
3
|
+
export class DurationUnits extends ConstClass {
|
|
3
4
|
static { this.MILLISECOND = 'millisecond'; }
|
|
4
5
|
static { this.SECOND = 'second'; }
|
|
5
6
|
static { this.MINUTE = 'minute'; }
|
|
@@ -8,19 +9,6 @@ export class DurationUnits {
|
|
|
8
9
|
static { this.WEEK = 'week'; }
|
|
9
10
|
static { this.MONTH = 'month'; }
|
|
10
11
|
static { this.YEAR = 'year'; }
|
|
11
|
-
static { this.SCHEME_SET = new Set([
|
|
12
|
-
this.MILLISECOND,
|
|
13
|
-
this.SECOND,
|
|
14
|
-
this.MINUTE,
|
|
15
|
-
this.HOUR,
|
|
16
|
-
this.DAY,
|
|
17
|
-
this.WEEK,
|
|
18
|
-
this.MONTH,
|
|
19
|
-
this.YEAR,
|
|
20
|
-
]); }
|
|
21
|
-
static isValid(input) {
|
|
22
|
-
return this.SCHEME_SET.has(input);
|
|
23
|
-
}
|
|
24
12
|
}
|
|
25
13
|
/**
|
|
26
14
|
* Written spellings that resolve to a unit. Member names are the spelling, upper-cased - so
|
|
@@ -122,7 +110,7 @@ export class DurationMultipliers {
|
|
|
122
110
|
* `null` rather than a throw, so a caller that wants an error raises its own with its own context.
|
|
123
111
|
* Every method here answers the same way.
|
|
124
112
|
*
|
|
125
|
-
* The unit is checked against {@link DurationUnits.
|
|
113
|
+
* The unit is checked against {@link DurationUnits.isValid} first: a plain-object read alone
|
|
126
114
|
* would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.
|
|
127
115
|
*/
|
|
128
116
|
static toMilliseconds(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../../src/common/constants/duration.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,MAAM,OAAO,aAAa;aACR,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,QAAG,GAAG,KAAK,CAAC;aACZ,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,IAAI;KACV,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;aACV,OAAE,GAAG,aAAa,CAAC,WAAW,CAAC;aAC/B,SAAI,GAAG,aAAa,CAAC,WAAW,CAAC;aACjC,gBAAW,GAAG,aAAa,CAAC,WAAW,CAAC;aACxC,iBAAY,GAAG,aAAa,CAAC,WAAW,CAAC;aAEzC,MAAC,GAAG,aAAa,CAAC,MAAM,CAAC;aACzB,QAAG,GAAG,aAAa,CAAC,M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ACd,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The time units a duration can be expressed in, smallest first. */\nexport class DurationUnits {\n static readonly MILLISECOND = 'millisecond';\n static readonly SECOND = 'second';\n static readonly MINUTE = 'minute';\n static readonly HOUR = 'hour';\n static readonly DAY = 'day';\n static readonly WEEK = 'week';\n static readonly MONTH = 'month';\n static readonly YEAR = 'year';\n\n static readonly SCHEME_SET = new Set([\n this.MILLISECOND,\n this.SECOND,\n this.MINUTE,\n this.HOUR,\n this.DAY,\n this.WEEK,\n this.MONTH,\n this.YEAR,\n ]);\n\n static isValid(input: string): input is TDurationUnit {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** One of the `DurationUnits` values, e.g. `'second'`. */\nexport type TDurationUnit = TConstValue<typeof DurationUnits>;\n\n/**\n * Written spellings that resolve to a unit. Member names are the spelling, upper-cased - so\n * {@link resolve} upper-cases its input and reads one property, with no second table to keep in step.\n *\n * `M` is MINUTE and `MO` is MONTH - the same choice every duration library makes, and the one\n * ambiguity a reader will trip on. There is no single-letter month.\n */\nexport class DurationAliases {\n static readonly MS = DurationUnits.MILLISECOND;\n static readonly MSEC = DurationUnits.MILLISECOND;\n static readonly MILLISECOND = DurationUnits.MILLISECOND;\n static readonly MILLISECONDS = DurationUnits.MILLISECOND;\n\n static readonly S = DurationUnits.SECOND;\n static readonly SEC = DurationUnits.SECOND;\n static readonly SECOND = DurationUnits.SECOND;\n static readonly SECONDS = DurationUnits.SECOND;\n\n static readonly M = DurationUnits.MINUTE;\n static readonly MIN = DurationUnits.MINUTE;\n static readonly MINUTE = DurationUnits.MINUTE;\n static readonly MINUTES = DurationUnits.MINUTE;\n\n static readonly H = DurationUnits.HOUR;\n static readonly HR = DurationUnits.HOUR;\n static readonly HOUR = DurationUnits.HOUR;\n static readonly HOURS = DurationUnits.HOUR;\n\n static readonly D = DurationUnits.DAY;\n static readonly DAY = DurationUnits.DAY;\n static readonly DAYS = DurationUnits.DAY;\n\n static readonly W = DurationUnits.WEEK;\n static readonly WK = DurationUnits.WEEK;\n static readonly WEEK = DurationUnits.WEEK;\n static readonly WEEKS = DurationUnits.WEEK;\n\n static readonly MO = DurationUnits.MONTH;\n static readonly MON = DurationUnits.MONTH;\n static readonly MONTH = DurationUnits.MONTH;\n static readonly MONTHS = DurationUnits.MONTH;\n\n static readonly Y = DurationUnits.YEAR;\n static readonly YR = DurationUnits.YEAR;\n static readonly YEAR = DurationUnits.YEAR;\n static readonly YEARS = DurationUnits.YEAR;\n\n /** Resolves a written unit - `'d'`, `'days'`, `'DAY'` - to its canonical name, or `null`. */\n static resolve(input: string): TDurationUnit | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n // Try the input as given first. `trim().toUpperCase()` allocates two strings and costs ~55ns,\n // where the lookup itself is ~1ns - so the spellings callers actually pass (`'day'`, `'d'`,\n // `'DAYS'`) must not pay for it. Measured, both ways.\n //\n // The table is declared below because it is derived FROM this class; it is read at call time,\n // never at class-evaluation time.\n /* eslint-disable @typescript-eslint/no-use-before-define */\n return ALIAS_LOOKUP.get(input) ?? ALIAS_LOOKUP.get(input.trim().toUpperCase()) ?? null;\n /* eslint-enable @typescript-eslint/no-use-before-define */\n }\n}\n\n/**\n * Derived from the class once, never hand-listed, so the two cannot drift. Reading the class\n * directly is slower and would need `name`/`length`/`constructor` guarded out. Each spelling is\n * stored upper and lower so the common call allocates nothing.\n */\nconst ALIAS_LOOKUP: Map<string, TDurationUnit> = new Map(\n Object.entries(DurationAliases)\n .filter((entry): entry is [string, TDurationUnit] => DurationUnits.isValid(entry[1] as string))\n .flatMap(([spelling, unit]): Array<[string, TDurationUnit]> => [\n [spelling, unit],\n [spelling.toLowerCase(), unit],\n ]),\n);\n\n/** A parsed duration: a `value` counted in `unit`. The value may be negative or fractional. */\nexport interface IDuration {\n unit: TDurationUnit;\n value: number;\n}\n\n/** `30d`, `1500 ms`, `-2 Hours`. One number, optional space, one unit. */\nconst DURATION_PATTERN = /^([+-]?\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/i;\n\n/**\n * A month is 30 days and a year 365, nominal. These size a WINDOW - a grace period, a cache TTL, a\n * near-expiry horizon - and must never compute a calendar date: adding `MONTH` to 31 January lands\n * on 2 March in a leap year and 3 March otherwise. Use a date library for calendar arithmetic.\n */\nexport class DurationMultipliers {\n static readonly MILLISECOND = 1;\n static readonly SECOND = 1000 * this.MILLISECOND;\n static readonly MINUTE = 60 * this.SECOND;\n static readonly HOUR = 60 * this.MINUTE;\n static readonly DAY = 24 * this.HOUR;\n static readonly WEEK = 7 * this.DAY;\n static readonly MONTH = 30 * this.DAY;\n static readonly YEAR = 365 * this.DAY;\n\n static readonly BY_UNIT: Record<string, number> = {\n [DurationUnits.MILLISECOND]: this.MILLISECOND,\n [DurationUnits.SECOND]: this.SECOND,\n [DurationUnits.MINUTE]: this.MINUTE,\n [DurationUnits.HOUR]: this.HOUR,\n [DurationUnits.DAY]: this.DAY,\n [DurationUnits.WEEK]: this.WEEK,\n [DurationUnits.MONTH]: this.MONTH,\n [DurationUnits.YEAR]: this.YEAR,\n };\n\n /** The multiplier of a known unit, `null` for anything else - inherited property names included. */\n private static multiplierOf(unit: unknown): number | null {\n return typeof unit === 'string' && DurationUnits.isValid(unit) ? this.BY_UNIT[unit] : null;\n }\n\n /**\n * `null` rather than a throw, so a caller that wants an error raises its own with its own context.\n * Every method here answers the same way.\n *\n * The unit is checked against {@link DurationUnits.SCHEME_SET} first: a plain-object read alone\n * would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.\n */\n static toMilliseconds(opts: IDuration | null): number | null {\n if (!opts) {\n return null;\n }\n\n const multiplier = this.multiplierOf(opts.unit);\n\n if (multiplier === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return Math.round(opts.value * multiplier);\n }\n\n /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */\n static fromMilliseconds(opts: { milliseconds: number; unit: TDurationUnit }): number | null {\n const multiplier = this.multiplierOf(opts?.unit);\n\n if (multiplier === null || !Number.isFinite(opts.milliseconds)) {\n return null;\n }\n\n return opts.milliseconds / multiplier;\n }\n\n /** Unit to unit, through milliseconds. Fractional, for the reason {@link fromMilliseconds} gives. */\n static convert(opts: { value: number; from: TDurationUnit; to: TDurationUnit }): number | null {\n const source = this.multiplierOf(opts?.from);\n const target = this.multiplierOf(opts?.to);\n\n if (source === null || target === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return (opts.value * source) / target;\n }\n\n /** Reads a written duration - `'30d'`, `'1500 ms'`, `'2 hours'` - into {@link IDuration}. Aliases and the `M`/`MO` rule are on {@link DurationAliases}. */\n static parse(input: string): IDuration | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n const matched = DURATION_PATTERN.exec(input.trim());\n\n if (!matched) {\n return null;\n }\n\n const unit = DurationAliases.resolve(matched[2]);\n const value = Number(matched[1]);\n\n if (!unit || !Number.isFinite(value)) {\n return null;\n }\n\n return { unit, value };\n }\n\n /** `'30d'` straight to milliseconds - the shape a TTL or a grace period is usually configured in. */\n static parseToMilliseconds(input: string): number | null {\n return this.toMilliseconds(this.parse(input));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../../src/common/constants/duration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,qEAAqE;AACrE,MAAM,OAAO,aAAc,SAAQ,UAAU;aAC3B,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,Q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gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAEjC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC","sourcesContent":["import { type TConstValue } from '../types';\nimport { ConstClass } from '@/common/const-class';\n\n/** The time units a duration can be expressed in, smallest first. */\nexport class DurationUnits extends ConstClass {\n static readonly MILLISECOND = 'millisecond';\n static readonly SECOND = 'second';\n static readonly MINUTE = 'minute';\n static readonly HOUR = 'hour';\n static readonly DAY = 'day';\n static readonly WEEK = 'week';\n static readonly MONTH = 'month';\n static readonly YEAR = 'year';\n}\n\n/** One of the `DurationUnits` values, e.g. `'second'`. */\nexport type TDurationUnit = TConstValue<typeof DurationUnits>;\n\n/**\n * Written spellings that resolve to a unit. Member names are the spelling, upper-cased - so\n * {@link resolve} upper-cases its input and reads one property, with no second table to keep in step.\n *\n * `M` is MINUTE and `MO` is MONTH - the same choice every duration library makes, and the one\n * ambiguity a reader will trip on. There is no single-letter month.\n */\nexport class DurationAliases {\n static readonly MS = DurationUnits.MILLISECOND;\n static readonly MSEC = DurationUnits.MILLISECOND;\n static readonly MILLISECOND = DurationUnits.MILLISECOND;\n static readonly MILLISECONDS = DurationUnits.MILLISECOND;\n\n static readonly S = DurationUnits.SECOND;\n static readonly SEC = DurationUnits.SECOND;\n static readonly SECOND = DurationUnits.SECOND;\n static readonly SECONDS = DurationUnits.SECOND;\n\n static readonly M = DurationUnits.MINUTE;\n static readonly MIN = DurationUnits.MINUTE;\n static readonly MINUTE = DurationUnits.MINUTE;\n static readonly MINUTES = DurationUnits.MINUTE;\n\n static readonly H = DurationUnits.HOUR;\n static readonly HR = DurationUnits.HOUR;\n static readonly HOUR = DurationUnits.HOUR;\n static readonly HOURS = DurationUnits.HOUR;\n\n static readonly D = DurationUnits.DAY;\n static readonly DAY = DurationUnits.DAY;\n static readonly DAYS = DurationUnits.DAY;\n\n static readonly W = DurationUnits.WEEK;\n static readonly WK = DurationUnits.WEEK;\n static readonly WEEK = DurationUnits.WEEK;\n static readonly WEEKS = DurationUnits.WEEK;\n\n static readonly MO = DurationUnits.MONTH;\n static readonly MON = DurationUnits.MONTH;\n static readonly MONTH = DurationUnits.MONTH;\n static readonly MONTHS = DurationUnits.MONTH;\n\n static readonly Y = DurationUnits.YEAR;\n static readonly YR = DurationUnits.YEAR;\n static readonly YEAR = DurationUnits.YEAR;\n static readonly YEARS = DurationUnits.YEAR;\n\n /** Resolves a written unit - `'d'`, `'days'`, `'DAY'` - to its canonical name, or `null`. */\n static resolve(input: string): TDurationUnit | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n // Try the input as given first. `trim().toUpperCase()` allocates two strings and costs ~55ns,\n // where the lookup itself is ~1ns - so the spellings callers actually pass (`'day'`, `'d'`,\n // `'DAYS'`) must not pay for it. Measured, both ways.\n //\n // The table is declared below because it is derived FROM this class; it is read at call time,\n // never at class-evaluation time.\n /* eslint-disable @typescript-eslint/no-use-before-define */\n return ALIAS_LOOKUP.get(input) ?? ALIAS_LOOKUP.get(input.trim().toUpperCase()) ?? null;\n /* eslint-enable @typescript-eslint/no-use-before-define */\n }\n}\n\n/**\n * Derived from the class once, never hand-listed, so the two cannot drift. Reading the class\n * directly is slower and would need `name`/`length`/`constructor` guarded out. Each spelling is\n * stored upper and lower so the common call allocates nothing.\n */\nconst ALIAS_LOOKUP: Map<string, TDurationUnit> = new Map(\n Object.entries(DurationAliases)\n .filter((entry): entry is [string, TDurationUnit] => DurationUnits.isValid(entry[1] as string))\n .flatMap(([spelling, unit]): Array<[string, TDurationUnit]> => [\n [spelling, unit],\n [spelling.toLowerCase(), unit],\n ]),\n);\n\n/** A parsed duration: a `value` counted in `unit`. The value may be negative or fractional. */\nexport interface IDuration {\n unit: TDurationUnit;\n value: number;\n}\n\n/** `30d`, `1500 ms`, `-2 Hours`. One number, optional space, one unit. */\nconst DURATION_PATTERN = /^([+-]?\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/i;\n\n/**\n * A month is 30 days and a year 365, nominal. These size a WINDOW - a grace period, a cache TTL, a\n * near-expiry horizon - and must never compute a calendar date: adding `MONTH` to 31 January lands\n * on 2 March in a leap year and 3 March otherwise. Use a date library for calendar arithmetic.\n */\nexport class DurationMultipliers {\n static readonly MILLISECOND = 1;\n static readonly SECOND = 1000 * this.MILLISECOND;\n static readonly MINUTE = 60 * this.SECOND;\n static readonly HOUR = 60 * this.MINUTE;\n static readonly DAY = 24 * this.HOUR;\n static readonly WEEK = 7 * this.DAY;\n static readonly MONTH = 30 * this.DAY;\n static readonly YEAR = 365 * this.DAY;\n\n static readonly BY_UNIT: Record<string, number> = {\n [DurationUnits.MILLISECOND]: this.MILLISECOND,\n [DurationUnits.SECOND]: this.SECOND,\n [DurationUnits.MINUTE]: this.MINUTE,\n [DurationUnits.HOUR]: this.HOUR,\n [DurationUnits.DAY]: this.DAY,\n [DurationUnits.WEEK]: this.WEEK,\n [DurationUnits.MONTH]: this.MONTH,\n [DurationUnits.YEAR]: this.YEAR,\n };\n\n /** The multiplier of a known unit, `null` for anything else - inherited property names included. */\n private static multiplierOf(unit: unknown): number | null {\n return typeof unit === 'string' && DurationUnits.isValid(unit) ? this.BY_UNIT[unit] : null;\n }\n\n /**\n * `null` rather than a throw, so a caller that wants an error raises its own with its own context.\n * Every method here answers the same way.\n *\n * The unit is checked against {@link DurationUnits.isValid} first: a plain-object read alone\n * would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.\n */\n static toMilliseconds(opts: IDuration | null): number | null {\n if (!opts) {\n return null;\n }\n\n const multiplier = this.multiplierOf(opts.unit);\n\n if (multiplier === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return Math.round(opts.value * multiplier);\n }\n\n /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */\n static fromMilliseconds(opts: { milliseconds: number; unit: TDurationUnit }): number | null {\n const multiplier = this.multiplierOf(opts?.unit);\n\n if (multiplier === null || !Number.isFinite(opts.milliseconds)) {\n return null;\n }\n\n return opts.milliseconds / multiplier;\n }\n\n /** Unit to unit, through milliseconds. Fractional, for the reason {@link fromMilliseconds} gives. */\n static convert(opts: { value: number; from: TDurationUnit; to: TDurationUnit }): number | null {\n const source = this.multiplierOf(opts?.from);\n const target = this.multiplierOf(opts?.to);\n\n if (source === null || target === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return (opts.value * source) / target;\n }\n\n /** Reads a written duration - `'30d'`, `'1500 ms'`, `'2 hours'` - into {@link IDuration}. Aliases and the `M`/`MO` rule are on {@link DurationAliases}. */\n static parse(input: string): IDuration | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n const matched = DURATION_PATTERN.exec(input.trim());\n\n if (!matched) {\n return null;\n }\n\n const unit = DurationAliases.resolve(matched[2]);\n const value = Number(matched[1]);\n\n if (!unit || !Number.isFinite(value)) {\n return null;\n }\n\n return { unit, value };\n }\n\n /** `'30d'` straight to milliseconds - the shape a TTL or a grace period is usually configured in. */\n static parseToMilliseconds(input: string): number | null {\n return this.toMilliseconds(this.parse(input));\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TConstValue, type ValueOf } from '../types/index.js';
|
|
2
|
+
import { ConstClass } from '../const-class.js';
|
|
2
3
|
/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */
|
|
3
4
|
export declare class HTTP {
|
|
4
5
|
/** Standard and common HTTP headers (lowercase per HTTP/2 convention). */
|
|
@@ -199,11 +200,9 @@ export type THttpProtocol = ValueOf<typeof HTTP.Protocols> | Uppercase<ValueOf<t
|
|
|
199
200
|
/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */
|
|
200
201
|
export type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;
|
|
201
202
|
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
202
|
-
export declare class ContentDispositionTypes {
|
|
203
|
+
export declare class ContentDispositionTypes extends ConstClass {
|
|
203
204
|
static readonly ATTACHMENT = "attachment";
|
|
204
205
|
static readonly INLINE = "inline";
|
|
205
|
-
static readonly SCHEME_SET: Set<string>;
|
|
206
|
-
static isValid(value: string): boolean;
|
|
207
206
|
}
|
|
208
207
|
/** Valid Content-Disposition type values. */
|
|
209
208
|
export type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConstClass } from '../const-class.js';
|
|
1
2
|
/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */
|
|
2
3
|
export class HTTP {
|
|
3
4
|
/** Standard and common HTTP headers (lowercase per HTTP/2 convention). */
|
|
@@ -219,12 +220,8 @@ export class HTTP {
|
|
|
219
220
|
}; }
|
|
220
221
|
}
|
|
221
222
|
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
222
|
-
export class ContentDispositionTypes {
|
|
223
|
+
export class ContentDispositionTypes extends ConstClass {
|
|
223
224
|
static { this.ATTACHMENT = 'attachment'; }
|
|
224
225
|
static { this.INLINE = 'inline'; }
|
|
225
|
-
static { this.SCHEME_SET = new Set([this.ATTACHMENT, this.INLINE]); }
|
|
226
|
-
static isValid(value) {
|
|
227
|
-
return this.SCHEME_SET.has(value);
|
|
228
|
-
}
|
|
229
226
|
}
|
|
230
227
|
//# sourceMappingURL=http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/common/constants/http.ts"],"names":[],"mappings":"AAEA,yJAAyJ;AACzJ,MAAM,OAAO,IAAI;IACf,0EAA0E;aAC1D,YAAO,GAAG;QACxB,UAAU;QACV,mBAAmB,EAAE,qBAAqB;QAC1C,gBAAgB,EAAE,kBAAkB;QACpC,cAAc,EAAE,gBAAgB;QAChC,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,eAAe;QAC9B,uBAAuB,EAAE,yBAAyB;QAClD,aAAa,EAAE,eAAe;QAC9B,KAAK,EAAE,OAAO;QAEd,+CAA+C;QAC/C,MAAM,EAAE,QAAQ;QAChB,eAAe,EAAE,iBAAiB;QAClC,eAAe,EAAE,iBAAiB;QAClC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,UAAU;QACpB,iBAAiB,EAAE,mBAAmB;QACtC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,YAAY;QAExB,kDAAkD;QAClD,KAAK,EAAE,OAAO;QACd,aAAa,EAAE,eAAe;QAC9B,IAAI,EAAE,MAAM;QACZ,aAAa,EAAE,eAAe;QAC9B,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,aAAa;QAC1B,UAAU,EAAE,YAAY;QACxB,IAAI,EAAE,MAAM;QACZ,gBAAgB,EAAE,kBAAkB;QAEpC,+BAA+B;QAC/B,gCAAgC,EAAE,kCAAkC;QACpE,4BAA4B,EAAE,8BAA8B;QAC5D,4BAA4B,EAAE,8BAA8B;QAC5D,2BAA2B,EAAE,6BAA6B;QAC1D,6BAA6B,EA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AAG;YACxB,YAAY,EAAE,GAAG;YACjB,6BAA6B,EAAE,GAAG;SACnC;KACO,CAAC;;AAYb,4EAA4E;AAC5E,MAAM,OAAO,uBAAuB;aAClB,eAAU,GAAG,YAAY,CAAC;aAC1B,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7E,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import { type TConstValue, type ValueOf } from '../types';\n\n/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */\nexport class HTTP {\n /** Standard and common HTTP headers (lowercase per HTTP/2 convention). */\n static readonly Headers = {\n // Content\n CONTENT_DISPOSITION: 'content-disposition',\n CONTENT_ENCODING: 'content-encoding',\n CONTENT_LENGTH: 'content-length',\n CONTENT_TYPE: 'content-type',\n CONTENT_RANGE: 'content-range',\n CONTENT_SECURITY_POLICY: 'content-security-policy',\n ACCEPT_RANGES: 'accept-ranges',\n RANGE: 'range',\n\n // Request - content negotiation & conditionals\n ACCEPT: 'accept',\n ACCEPT_ENCODING: 'accept-encoding',\n ACCEPT_LANGUAGE: 'accept-language',\n AUTHORIZATION: 'authorization',\n COOKIE: 'cookie',\n HOST: 'host',\n IF_MATCH: 'if-match',\n IF_MODIFIED_SINCE: 'if-modified-since',\n IF_NONE_MATCH: 'if-none-match',\n ORIGIN: 'origin',\n REFERER: 'referer',\n USER_AGENT: 'user-agent',\n\n // Response - caching, auth challenges & redirects\n ALLOW: 'allow',\n CACHE_CONTROL: 'cache-control',\n ETAG: 'etag',\n LAST_MODIFIED: 'last-modified',\n LOCATION: 'location',\n RETRY_AFTER: 'retry-after',\n SET_COOKIE: 'set-cookie',\n VARY: 'vary',\n WWW_AUTHENTICATE: 'www-authenticate',\n\n // CORS (RFC 6454 / Fetch spec)\n ACCESS_CONTROL_ALLOW_CREDENTIALS: 'access-control-allow-credentials',\n ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers',\n ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods',\n ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin',\n ACCESS_CONTROL_EXPOSE_HEADERS: 'access-control-expose-headers',\n ACCESS_CONTROL_MAX_AGE: 'access-control-max-age',\n ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers',\n ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method',\n\n // Transport\n CONNECTION: 'connection',\n TRANSFER_ENCODING: 'transfer-encoding',\n UPGRADE: 'upgrade',\n\n // Security\n STRICT_TRANSPORT_SECURITY: 'strict-transport-security',\n X_CONTENT_TYPE_OPTIONS: 'x-content-type-options',\n X_FRAME_OPTIONS: 'x-frame-options',\n\n // Proxy / forwarding (de facto standard)\n FORWARDED: 'forwarded',\n X_FORWARDED_FOR: 'x-forwarded-for',\n X_FORWARDED_HOST: 'x-forwarded-host',\n X_FORWARDED_PROTO: 'x-forwarded-proto',\n X_REAL_IP: 'x-real-ip',\n\n // Rate limiting (de facto standard)\n X_RATELIMIT_LIMIT: 'x-ratelimit-limit',\n X_RATELIMIT_REMAINING: 'x-ratelimit-remaining',\n X_RATELIMIT_RESET: 'x-ratelimit-reset',\n\n // IGNIS custom\n REQUEST_TRACING_ID: 'x-request-id',\n REQUEST_DEVICE_INFO: 'x-device-info',\n REQUEST_CHANNEL: 'x-request-channel',\n REQUEST_COUNT_DATA: 'x-request-count',\n REQUEST_EXTRA: 'x-request-extra',\n RESPONSE_COUNT_DATA: 'x-response-count',\n RESPONSE_FORMAT: 'x-response-format',\n RESPONSE_EXTRA: 'x-response-extra',\n\n // Client context\n AUTH_PROVIDER: 'x-auth-provider',\n LOCALE: 'x-locale',\n TIMEZONE: 'timezone',\n TIMEZONE_OFFSET: 'timezone-offset',\n } as const;\n\n /**\n * The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them\n * by hand: spread `ALLOW` into the allowed request headers and `EXPOSE` into the exposed ones, so\n * a header IGNIS adds later needs no change there.\n */\n static readonly CorsHeaders = {\n ALLOW: [\n 'x-request-id',\n 'x-request-count',\n 'x-request-extra',\n 'x-request-channel',\n 'x-device-info',\n ],\n EXPOSE: [\n 'content-range',\n 'x-request-id',\n 'x-response-count',\n 'x-response-format',\n 'x-response-extra',\n ],\n } as const;\n\n /** Common MIME / Content-Type values. */\n static readonly HeaderValues = {\n // Application\n APPLICATION_FORM_URLENCODED: 'application/x-www-form-urlencoded',\n APPLICATION_GRAPHQL_JSON: 'application/graphql+json',\n APPLICATION_GZIP: 'application/gzip',\n APPLICATION_JAVASCRIPT: 'application/javascript',\n APPLICATION_JSON: 'application/json',\n /** A JSON body with its charset named, the value a client sends by default. */\n APPLICATION_JSON_UTF8: 'application/json; charset=utf-8',\n APPLICATION_MSGPACK: 'application/msgpack',\n APPLICATION_NDJSON: 'application/x-ndjson',\n APPLICATION_OCTET_STREAM: 'application/octet-stream',\n APPLICATION_PDF: 'application/pdf',\n APPLICATION_PROTOBUF: 'application/x-protobuf',\n APPLICATION_XML: 'application/xml',\n APPLICATION_ZIP: 'application/zip',\n\n // Multipart\n MULTIPART_FORM_DATA: 'multipart/form-data',\n\n // Text\n TEXT_CSS: 'text/css',\n TEXT_CSV: 'text/csv',\n TEXT_EVENT_STREAM: 'text/event-stream',\n TEXT_HTML: 'text/html',\n TEXT_PLAIN: 'text/plain',\n TEXT_XML: 'text/xml',\n\n // Image\n IMAGE_GIF: 'image/gif',\n IMAGE_JPEG: 'image/jpeg',\n IMAGE_PNG: 'image/png',\n IMAGE_SVG: 'image/svg+xml',\n IMAGE_WEBP: 'image/webp',\n\n // Range units\n RANGE_UNIT_BYTES: 'bytes',\n } as const;\n\n /** Standard HTTP methods (lowercase). */\n static readonly Methods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n QUERY: 'query',\n } as const;\n\n /** Standard HTTP protocols (lowercase). */\n static readonly Protocols = {\n HTTP: 'http',\n HTTPS: 'https',\n } as const;\n\n /** HTTP status codes grouped by class (1xx - 5xx). */\n static readonly ResultCodes = {\n /** 1xx - Informational. */\n RS_1: {\n Continue: 100,\n SwitchingProtocols: 101,\n EarlyHints: 103,\n },\n\n /** 2xx - Success. */\n RS_2: {\n Ok: 200,\n Created: 201,\n Accepted: 202,\n NonAuthoritativeInformation: 203,\n NoContent: 204,\n ResetContent: 205,\n PartialContent: 206,\n MultiStatus: 207,\n },\n\n /** 3xx - Redirection. */\n RS_3: {\n MovedPermanently: 301,\n Found: 302,\n NotModified: 304,\n TemporaryRedirect: 307,\n PermanentRedirect: 308,\n },\n\n /** 4xx - Client error. */\n RS_4: {\n BadRequest: 400,\n Unauthorized: 401,\n PaymentRequired: 402,\n Forbidden: 403,\n NotFound: 404,\n MethodNotAllowed: 405,\n NotAcceptable: 406,\n RequestTimeout: 408,\n Conflict: 409,\n Gone: 410,\n LengthRequired: 411,\n PreconditionFailed: 412,\n ContentTooLarge: 413,\n URITooLong: 414,\n UnsupportedMediaType: 415,\n RangeNotSatisfiable: 416,\n ExpectationFailed: 417,\n UnprocessableEntity: 422,\n Locked: 423,\n FailedDependency: 424,\n TooEarly: 425,\n UpgradeRequired: 426,\n PreconditionRequired: 428,\n TooManyRequests: 429,\n RequestHeaderFieldsTooLarge: 431,\n UnavailableForLegalReasons: 451,\n },\n\n /** 5xx - Server error. */\n RS_5: {\n InternalServerError: 500,\n NotImplemented: 501,\n BadGateway: 502,\n ServiceUnavailable: 503,\n GatewayTimeout: 504,\n HTTPVersionNotSupported: 505,\n InsufficientStorage: 507,\n LoopDetected: 508,\n NetworkAuthenticationRequired: 511,\n },\n } as const;\n}\n\n/** An HTTP method from `HTTP.Methods`, in lowercase or uppercase. */\nexport type THttpMethod = ValueOf<typeof HTTP.Methods> | Uppercase<ValueOf<typeof HTTP.Methods>>;\n/** An HTTP protocol from `HTTP.Protocols`, in lowercase or uppercase. */\nexport type THttpProtocol =\n | ValueOf<typeof HTTP.Protocols>\n | Uppercase<ValueOf<typeof HTTP.Protocols>>;\n/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */\nexport type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n"]}
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/common/constants/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,yJAAyJ;AACzJ,MAAM,OAAO,IAAI;IACf,0EAA0E;aAC1D,YAAO,GAAG;QACxB,UAAU;QACV,mBAAmB,EAAE,qBAAqB;QAC1C,gBAAgB,EAAE,kBAAkB;QACpC,cAAc,EAAE,gBAAgB;QAChC,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,eAAe;QAC9B,uBAAuB,EAAE,yBAAyB;QAClD,aAAa,EAAE,eAAe;QAC9B,KAAK,EAAE,OAAO;QAEd,+CAA+C;QAC/C,MAAM,EAAE,QAAQ;QAChB,eAAe,EAAE,iBAAiB;QAClC,eAAe,EAAE,iBAAiB;QAClC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,UAAU;QACpB,iBAAiB,EAAE,mBAAmB;QACtC,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE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AE,GAAG;YACtB,mBAAmB,EAAE,GAAG;YACxB,MAAM,EAAE,GAAG;YACX,gBAAgB,EAAE,GAAG;YACrB,QAAQ,EAAE,GAAG;YACb,eAAe,EAAE,GAAG;YACpB,oBAAoB,EAAE,GAAG;YACzB,eAAe,EAAE,GAAG;YACpB,2BAA2B,EAAE,GAAG;YAChC,0BAA0B,EAAE,GAAG;SAChC;QAED,0BAA0B;QAC1B,IAAI,EAAE;YACJ,mBAAmB,EAAE,GAAG;YACxB,cAAc,EAAE,GAAG;YACnB,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,GAAG;YACvB,cAAc,EAAE,GAAG;YACnB,uBAAuB,EAAE,GAAG;YAC5B,mBAAmB,EAAE,GAAG;YACxB,YAAY,EAAE,GAAG;YACjB,6BAA6B,EAAE,GAAG;SACnC;KACO,CAAC;;AAYb,4EAA4E;AAC5E,MAAM,OAAO,uBAAwB,SAAQ,UAAU;aACrC,eAAU,GAAG,YAAY,CAAC;aAC1B,WAAM,GAAG,QAAQ,CAAC","sourcesContent":["import { type TConstValue, type ValueOf } from '../types';\nimport { ConstClass } from '@/common/const-class';\n\n/** HTTP constants: header names, CORS headers, header values, methods, protocols and status codes. Header names, methods and protocols are lowercase. */\nexport class HTTP {\n /** Standard and common HTTP headers (lowercase per HTTP/2 convention). */\n static readonly Headers = {\n // Content\n CONTENT_DISPOSITION: 'content-disposition',\n CONTENT_ENCODING: 'content-encoding',\n CONTENT_LENGTH: 'content-length',\n CONTENT_TYPE: 'content-type',\n CONTENT_RANGE: 'content-range',\n CONTENT_SECURITY_POLICY: 'content-security-policy',\n ACCEPT_RANGES: 'accept-ranges',\n RANGE: 'range',\n\n // Request - content negotiation & conditionals\n ACCEPT: 'accept',\n ACCEPT_ENCODING: 'accept-encoding',\n ACCEPT_LANGUAGE: 'accept-language',\n AUTHORIZATION: 'authorization',\n COOKIE: 'cookie',\n HOST: 'host',\n IF_MATCH: 'if-match',\n IF_MODIFIED_SINCE: 'if-modified-since',\n IF_NONE_MATCH: 'if-none-match',\n ORIGIN: 'origin',\n REFERER: 'referer',\n USER_AGENT: 'user-agent',\n\n // Response - caching, auth challenges & redirects\n ALLOW: 'allow',\n CACHE_CONTROL: 'cache-control',\n ETAG: 'etag',\n LAST_MODIFIED: 'last-modified',\n LOCATION: 'location',\n RETRY_AFTER: 'retry-after',\n SET_COOKIE: 'set-cookie',\n VARY: 'vary',\n WWW_AUTHENTICATE: 'www-authenticate',\n\n // CORS (RFC 6454 / Fetch spec)\n ACCESS_CONTROL_ALLOW_CREDENTIALS: 'access-control-allow-credentials',\n ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers',\n ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods',\n ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin',\n ACCESS_CONTROL_EXPOSE_HEADERS: 'access-control-expose-headers',\n ACCESS_CONTROL_MAX_AGE: 'access-control-max-age',\n ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers',\n ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method',\n\n // Transport\n CONNECTION: 'connection',\n TRANSFER_ENCODING: 'transfer-encoding',\n UPGRADE: 'upgrade',\n\n // Security\n STRICT_TRANSPORT_SECURITY: 'strict-transport-security',\n X_CONTENT_TYPE_OPTIONS: 'x-content-type-options',\n X_FRAME_OPTIONS: 'x-frame-options',\n\n // Proxy / forwarding (de facto standard)\n FORWARDED: 'forwarded',\n X_FORWARDED_FOR: 'x-forwarded-for',\n X_FORWARDED_HOST: 'x-forwarded-host',\n X_FORWARDED_PROTO: 'x-forwarded-proto',\n X_REAL_IP: 'x-real-ip',\n\n // Rate limiting (de facto standard)\n X_RATELIMIT_LIMIT: 'x-ratelimit-limit',\n X_RATELIMIT_REMAINING: 'x-ratelimit-remaining',\n X_RATELIMIT_RESET: 'x-ratelimit-reset',\n\n // IGNIS custom\n REQUEST_TRACING_ID: 'x-request-id',\n REQUEST_DEVICE_INFO: 'x-device-info',\n REQUEST_CHANNEL: 'x-request-channel',\n REQUEST_COUNT_DATA: 'x-request-count',\n REQUEST_EXTRA: 'x-request-extra',\n RESPONSE_COUNT_DATA: 'x-response-count',\n RESPONSE_FORMAT: 'x-response-format',\n RESPONSE_EXTRA: 'x-response-extra',\n\n // Client context\n AUTH_PROVIDER: 'x-auth-provider',\n LOCALE: 'x-locale',\n TIMEZONE: 'timezone',\n TIMEZONE_OFFSET: 'timezone-offset',\n } as const;\n\n /**\n * The headers IGNIS adds to a request and to a response, for a CORS configuration that lists them\n * by hand: spread `ALLOW` into the allowed request headers and `EXPOSE` into the exposed ones, so\n * a header IGNIS adds later needs no change there.\n */\n static readonly CorsHeaders = {\n ALLOW: [\n 'x-request-id',\n 'x-request-count',\n 'x-request-extra',\n 'x-request-channel',\n 'x-device-info',\n ],\n EXPOSE: [\n 'content-range',\n 'x-request-id',\n 'x-response-count',\n 'x-response-format',\n 'x-response-extra',\n ],\n } as const;\n\n /** Common MIME / Content-Type values. */\n static readonly HeaderValues = {\n // Application\n APPLICATION_FORM_URLENCODED: 'application/x-www-form-urlencoded',\n APPLICATION_GRAPHQL_JSON: 'application/graphql+json',\n APPLICATION_GZIP: 'application/gzip',\n APPLICATION_JAVASCRIPT: 'application/javascript',\n APPLICATION_JSON: 'application/json',\n /** A JSON body with its charset named, the value a client sends by default. */\n APPLICATION_JSON_UTF8: 'application/json; charset=utf-8',\n APPLICATION_MSGPACK: 'application/msgpack',\n APPLICATION_NDJSON: 'application/x-ndjson',\n APPLICATION_OCTET_STREAM: 'application/octet-stream',\n APPLICATION_PDF: 'application/pdf',\n APPLICATION_PROTOBUF: 'application/x-protobuf',\n APPLICATION_XML: 'application/xml',\n APPLICATION_ZIP: 'application/zip',\n\n // Multipart\n MULTIPART_FORM_DATA: 'multipart/form-data',\n\n // Text\n TEXT_CSS: 'text/css',\n TEXT_CSV: 'text/csv',\n TEXT_EVENT_STREAM: 'text/event-stream',\n TEXT_HTML: 'text/html',\n TEXT_PLAIN: 'text/plain',\n TEXT_XML: 'text/xml',\n\n // Image\n IMAGE_GIF: 'image/gif',\n IMAGE_JPEG: 'image/jpeg',\n IMAGE_PNG: 'image/png',\n IMAGE_SVG: 'image/svg+xml',\n IMAGE_WEBP: 'image/webp',\n\n // Range units\n RANGE_UNIT_BYTES: 'bytes',\n } as const;\n\n /** Standard HTTP methods (lowercase). */\n static readonly Methods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n QUERY: 'query',\n } as const;\n\n /** Standard HTTP protocols (lowercase). */\n static readonly Protocols = {\n HTTP: 'http',\n HTTPS: 'https',\n } as const;\n\n /** HTTP status codes grouped by class (1xx - 5xx). */\n static readonly ResultCodes = {\n /** 1xx - Informational. */\n RS_1: {\n Continue: 100,\n SwitchingProtocols: 101,\n EarlyHints: 103,\n },\n\n /** 2xx - Success. */\n RS_2: {\n Ok: 200,\n Created: 201,\n Accepted: 202,\n NonAuthoritativeInformation: 203,\n NoContent: 204,\n ResetContent: 205,\n PartialContent: 206,\n MultiStatus: 207,\n },\n\n /** 3xx - Redirection. */\n RS_3: {\n MovedPermanently: 301,\n Found: 302,\n NotModified: 304,\n TemporaryRedirect: 307,\n PermanentRedirect: 308,\n },\n\n /** 4xx - Client error. */\n RS_4: {\n BadRequest: 400,\n Unauthorized: 401,\n PaymentRequired: 402,\n Forbidden: 403,\n NotFound: 404,\n MethodNotAllowed: 405,\n NotAcceptable: 406,\n RequestTimeout: 408,\n Conflict: 409,\n Gone: 410,\n LengthRequired: 411,\n PreconditionFailed: 412,\n ContentTooLarge: 413,\n URITooLong: 414,\n UnsupportedMediaType: 415,\n RangeNotSatisfiable: 416,\n ExpectationFailed: 417,\n UnprocessableEntity: 422,\n Locked: 423,\n FailedDependency: 424,\n TooEarly: 425,\n UpgradeRequired: 426,\n PreconditionRequired: 428,\n TooManyRequests: 429,\n RequestHeaderFieldsTooLarge: 431,\n UnavailableForLegalReasons: 451,\n },\n\n /** 5xx - Server error. */\n RS_5: {\n InternalServerError: 500,\n NotImplemented: 501,\n BadGateway: 502,\n ServiceUnavailable: 503,\n GatewayTimeout: 504,\n HTTPVersionNotSupported: 505,\n InsufficientStorage: 507,\n LoopDetected: 508,\n NetworkAuthenticationRequired: 511,\n },\n } as const;\n}\n\n/** An HTTP method from `HTTP.Methods`, in lowercase or uppercase. */\nexport type THttpMethod = ValueOf<typeof HTTP.Methods> | Uppercase<ValueOf<typeof HTTP.Methods>>;\n/** An HTTP protocol from `HTTP.Protocols`, in lowercase or uppercase. */\nexport type THttpProtocol =\n | ValueOf<typeof HTTP.Protocols>\n | Uppercase<ValueOf<typeof HTTP.Protocols>>;\n/** A numeric HTTP status code from any class in `HTTP.ResultCodes`. */\nexport type THttpResultCode = ValueOf<typeof HTTP.ResultCodes>;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes extends ConstClass {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TConstValue } from '../types/index.js';
|
|
2
|
+
import { ConstClass } from '../const-class.js';
|
|
2
3
|
/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */
|
|
3
4
|
export declare class MimeTypes {
|
|
4
5
|
static readonly UNKNOWN = "unknown";
|
|
@@ -9,7 +10,7 @@ export declare class MimeTypes {
|
|
|
9
10
|
/** One of the `MimeTypes` values. */
|
|
10
11
|
export type TMimeTypes = TConstValue<typeof MimeTypes>;
|
|
11
12
|
/** The leading dot is part of the value: `path.extname` returns one. */
|
|
12
|
-
export declare class FileExtensions {
|
|
13
|
+
export declare class FileExtensions extends ConstClass {
|
|
13
14
|
static readonly PNG = ".png";
|
|
14
15
|
static readonly JPG = ".jpg";
|
|
15
16
|
static readonly JPEG = ".jpeg";
|
|
@@ -37,13 +38,11 @@ export declare class FileExtensions {
|
|
|
37
38
|
static readonly PPT = ".ppt";
|
|
38
39
|
static readonly ODT = ".odt";
|
|
39
40
|
static readonly ODS = ".ods";
|
|
40
|
-
static readonly SCHEME_SET: Set<string>;
|
|
41
|
-
static isValid(value: string): boolean;
|
|
42
41
|
}
|
|
43
42
|
/** One of the `FileExtensions` values, with its leading dot. */
|
|
44
43
|
export type TFileExtension = TConstValue<typeof FileExtensions>;
|
|
45
44
|
/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */
|
|
46
|
-
export declare class ContentTypes {
|
|
45
|
+
export declare class ContentTypes extends ConstClass {
|
|
47
46
|
static readonly OCTET_STREAM = "application/octet-stream";
|
|
48
47
|
static readonly PNG = "image/png";
|
|
49
48
|
static readonly JPEG = "image/jpeg";
|
|
@@ -71,8 +70,6 @@ export declare class ContentTypes {
|
|
|
71
70
|
static readonly PPT = "application/vnd.ms-powerpoint";
|
|
72
71
|
static readonly ODT = "application/vnd.oasis.opendocument.text";
|
|
73
72
|
static readonly ODS = "application/vnd.oasis.opendocument.spreadsheet";
|
|
74
|
-
static readonly SCHEME_SET: Set<string>;
|
|
75
|
-
static isValid(value: string): boolean;
|
|
76
73
|
}
|
|
77
74
|
/** One of the `ContentTypes` values. */
|
|
78
75
|
export type TContentType = TConstValue<typeof ContentTypes>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConstClass } from '../const-class.js';
|
|
1
2
|
/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */
|
|
2
3
|
export class MimeTypes {
|
|
3
4
|
static { this.UNKNOWN = 'unknown'; }
|
|
@@ -6,7 +7,7 @@ export class MimeTypes {
|
|
|
6
7
|
static { this.TEXT = 'text'; }
|
|
7
8
|
}
|
|
8
9
|
/** The leading dot is part of the value: `path.extname` returns one. */
|
|
9
|
-
export class FileExtensions {
|
|
10
|
+
export class FileExtensions extends ConstClass {
|
|
10
11
|
static { this.PNG = '.png'; }
|
|
11
12
|
static { this.JPG = '.jpg'; }
|
|
12
13
|
static { this.JPEG = '.jpeg'; }
|
|
@@ -34,41 +35,9 @@ export class FileExtensions {
|
|
|
34
35
|
static { this.PPT = '.ppt'; }
|
|
35
36
|
static { this.ODT = '.odt'; }
|
|
36
37
|
static { this.ODS = '.ods'; }
|
|
37
|
-
static { this.SCHEME_SET = new Set([
|
|
38
|
-
this.PNG,
|
|
39
|
-
this.JPG,
|
|
40
|
-
this.JPEG,
|
|
41
|
-
this.GIF,
|
|
42
|
-
this.WEBP,
|
|
43
|
-
this.SVG,
|
|
44
|
-
this.PDF,
|
|
45
|
-
this.JSON,
|
|
46
|
-
this.TXT,
|
|
47
|
-
this.HTML,
|
|
48
|
-
this.CSS,
|
|
49
|
-
this.JS,
|
|
50
|
-
this.MP4,
|
|
51
|
-
this.WEBM,
|
|
52
|
-
this.MP3,
|
|
53
|
-
this.WAV,
|
|
54
|
-
this.ZIP,
|
|
55
|
-
this.CSV,
|
|
56
|
-
this.XML,
|
|
57
|
-
this.XLSX,
|
|
58
|
-
this.XLS,
|
|
59
|
-
this.DOCX,
|
|
60
|
-
this.DOC,
|
|
61
|
-
this.PPTX,
|
|
62
|
-
this.PPT,
|
|
63
|
-
this.ODT,
|
|
64
|
-
this.ODS,
|
|
65
|
-
]); }
|
|
66
|
-
static isValid(value) {
|
|
67
|
-
return this.SCHEME_SET.has(value);
|
|
68
|
-
}
|
|
69
38
|
}
|
|
70
39
|
/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */
|
|
71
|
-
export class ContentTypes {
|
|
40
|
+
export class ContentTypes extends ConstClass {
|
|
72
41
|
static { this.OCTET_STREAM = 'application/octet-stream'; }
|
|
73
42
|
static { this.PNG = 'image/png'; }
|
|
74
43
|
static { this.JPEG = 'image/jpeg'; }
|
|
@@ -96,38 +65,6 @@ export class ContentTypes {
|
|
|
96
65
|
static { this.PPT = 'application/vnd.ms-powerpoint'; }
|
|
97
66
|
static { this.ODT = 'application/vnd.oasis.opendocument.text'; }
|
|
98
67
|
static { this.ODS = 'application/vnd.oasis.opendocument.spreadsheet'; }
|
|
99
|
-
static { this.SCHEME_SET = new Set([
|
|
100
|
-
this.OCTET_STREAM,
|
|
101
|
-
this.PNG,
|
|
102
|
-
this.JPEG,
|
|
103
|
-
this.GIF,
|
|
104
|
-
this.WEBP,
|
|
105
|
-
this.SVG,
|
|
106
|
-
this.PDF,
|
|
107
|
-
this.JSON,
|
|
108
|
-
this.PLAIN_TEXT,
|
|
109
|
-
this.HTML,
|
|
110
|
-
this.CSS,
|
|
111
|
-
this.JAVASCRIPT,
|
|
112
|
-
this.MP4,
|
|
113
|
-
this.WEBM,
|
|
114
|
-
this.MPEG_AUDIO,
|
|
115
|
-
this.WAV,
|
|
116
|
-
this.ZIP,
|
|
117
|
-
this.CSV,
|
|
118
|
-
this.XML,
|
|
119
|
-
this.XLSX,
|
|
120
|
-
this.XLS,
|
|
121
|
-
this.DOCX,
|
|
122
|
-
this.DOC,
|
|
123
|
-
this.PPTX,
|
|
124
|
-
this.PPT,
|
|
125
|
-
this.ODT,
|
|
126
|
-
this.ODS,
|
|
127
|
-
]); }
|
|
128
|
-
static isValid(value) {
|
|
129
|
-
return this.SCHEME_SET.has(value);
|
|
130
|
-
}
|
|
131
68
|
}
|
|
132
69
|
/** The extension table and the lookup that reads it, together - the `DurationMultipliers` shape. */
|
|
133
70
|
export class ContentTypeTable {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/common/constants/mime.ts"],"names":[],"mappings":"AAEA,kIAAkI;AAClI,MAAM,OAAO,SAAS;aACJ,YAAO,GAAG,SAAS,CAAC;aACpB,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;;AAKhC,wEAAwE;AACxE,MAAM,OAAO,cAAc;aACT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,CAAC,EAAE,YAAY,CAAC,GAAG;KACkB,CAAC;IAE3D;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,IAA0B;QACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAE9E,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,YAAY,CAAC;IACnE,CAAC;;AAGH,gGAAgG;AAChG,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,YAAY,CAAC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */\nexport class MimeTypes {\n static readonly UNKNOWN = 'unknown';\n static readonly IMAGE = 'image';\n static readonly VIDEO = 'video';\n static readonly TEXT = 'text';\n}\n/** One of the `MimeTypes` values. */\nexport type TMimeTypes = TConstValue<typeof MimeTypes>;\n\n/** The leading dot is part of the value: `path.extname` returns one. */\nexport class FileExtensions {\n static readonly PNG = '.png';\n static readonly JPG = '.jpg';\n static readonly JPEG = '.jpeg';\n static readonly GIF = '.gif';\n static readonly WEBP = '.webp';\n static readonly SVG = '.svg';\n static readonly PDF = '.pdf';\n static readonly JSON = '.json';\n static readonly TXT = '.txt';\n static readonly HTML = '.html';\n static readonly CSS = '.css';\n static readonly JS = '.js';\n static readonly MP4 = '.mp4';\n static readonly WEBM = '.webm';\n static readonly MP3 = '.mp3';\n static readonly WAV = '.wav';\n static readonly ZIP = '.zip';\n static readonly CSV = '.csv';\n static readonly XML = '.xml';\n static readonly XLSX = '.xlsx';\n static readonly XLS = '.xls';\n static readonly DOCX = '.docx';\n static readonly DOC = '.doc';\n static readonly PPTX = '.pptx';\n static readonly PPT = '.ppt';\n static readonly ODT = '.odt';\n static readonly ODS = '.ods';\n\n static readonly SCHEME_SET = new Set<string>([\n this.PNG,\n this.JPG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.TXT,\n this.HTML,\n this.CSS,\n this.JS,\n this.MP4,\n this.WEBM,\n this.MP3,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `FileExtensions` values, with its leading dot. */\nexport type TFileExtension = TConstValue<typeof FileExtensions>;\n\n/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */\nexport class ContentTypes {\n static readonly OCTET_STREAM = 'application/octet-stream';\n static readonly PNG = 'image/png';\n static readonly JPEG = 'image/jpeg';\n static readonly GIF = 'image/gif';\n static readonly WEBP = 'image/webp';\n static readonly SVG = 'image/svg+xml';\n static readonly PDF = 'application/pdf';\n static readonly JSON = 'application/json';\n static readonly PLAIN_TEXT = 'text/plain';\n static readonly HTML = 'text/html';\n static readonly CSS = 'text/css';\n static readonly JAVASCRIPT = 'text/javascript';\n static readonly MP4 = 'video/mp4';\n static readonly WEBM = 'video/webm';\n static readonly MPEG_AUDIO = 'audio/mpeg';\n static readonly WAV = 'audio/wav';\n static readonly ZIP = 'application/zip';\n static readonly CSV = 'text/csv';\n static readonly XML = 'application/xml';\n static readonly XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n static readonly XLS = 'application/vnd.ms-excel';\n static readonly DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';\n static readonly DOC = 'application/msword';\n static readonly PPTX =\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation';\n\n static readonly PPT = 'application/vnd.ms-powerpoint';\n static readonly ODT = 'application/vnd.oasis.opendocument.text';\n static readonly ODS = 'application/vnd.oasis.opendocument.spreadsheet';\n\n static readonly SCHEME_SET = new Set<string>([\n this.OCTET_STREAM,\n this.PNG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.PLAIN_TEXT,\n this.HTML,\n this.CSS,\n this.JAVASCRIPT,\n this.MP4,\n this.WEBM,\n this.MPEG_AUDIO,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `ContentTypes` values. */\nexport type TContentType = TConstValue<typeof ContentTypes>;\n\n/** The extension table and the lookup that reads it, together - the `DurationMultipliers` shape. */\nexport class ContentTypeTable {\n /** `satisfies` makes the table total; the declared `string` key keeps a lookup cast-free. */\n static readonly BY_EXTENSION: Readonly<Partial<Record<string, TContentType>>> = {\n [FileExtensions.PNG]: ContentTypes.PNG,\n [FileExtensions.JPG]: ContentTypes.JPEG,\n [FileExtensions.JPEG]: ContentTypes.JPEG,\n [FileExtensions.GIF]: ContentTypes.GIF,\n [FileExtensions.WEBP]: ContentTypes.WEBP,\n [FileExtensions.SVG]: ContentTypes.SVG,\n [FileExtensions.PDF]: ContentTypes.PDF,\n [FileExtensions.JSON]: ContentTypes.JSON,\n [FileExtensions.TXT]: ContentTypes.PLAIN_TEXT,\n [FileExtensions.HTML]: ContentTypes.HTML,\n [FileExtensions.CSS]: ContentTypes.CSS,\n [FileExtensions.JS]: ContentTypes.JAVASCRIPT,\n [FileExtensions.MP4]: ContentTypes.MP4,\n [FileExtensions.WEBM]: ContentTypes.WEBM,\n [FileExtensions.MP3]: ContentTypes.MPEG_AUDIO,\n [FileExtensions.WAV]: ContentTypes.WAV,\n [FileExtensions.ZIP]: ContentTypes.ZIP,\n [FileExtensions.CSV]: ContentTypes.CSV,\n [FileExtensions.XML]: ContentTypes.XML,\n [FileExtensions.XLSX]: ContentTypes.XLSX,\n [FileExtensions.XLS]: ContentTypes.XLS,\n [FileExtensions.DOCX]: ContentTypes.DOCX,\n [FileExtensions.DOC]: ContentTypes.DOC,\n [FileExtensions.PPTX]: ContentTypes.PPTX,\n [FileExtensions.PPT]: ContentTypes.PPT,\n [FileExtensions.ODT]: ContentTypes.ODT,\n [FileExtensions.ODS]: ContentTypes.ODS,\n } satisfies Readonly<Record<TFileExtension, TContentType>>;\n\n /**\n * The content type an object name implies. `node:path` is deliberately not used: this file is\n * reachable from the browser-pure `./common` subpath, and an extension is the tail after the last\n * dot either way.\n */\n static resolve(opts: { filename: string }): TContentType {\n const { filename } = opts;\n const lastDot = filename.lastIndexOf('.');\n const extension = lastDot === -1 ? '' : filename.slice(lastDot).toLowerCase();\n\n return this.BY_EXTENSION[extension] ?? ContentTypes.OCTET_STREAM;\n }\n}\n\n/** Published before the table moved onto the class; kept as the one-line delegate it now is. */\nexport const CONTENT_TYPE_BY_EXTENSION = ContentTypeTable.BY_EXTENSION;\n"]}
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/common/constants/mime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,kIAAkI;AAClI,MAAM,OAAO,SAAS;aACJ,YAAO,GAAG,SAAS,CAAC;aACpB,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;;AAKhC,wEAAwE;AACxE,MAAM,OAAO,cAAe,SAAQ,UAAU;aAC5B,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GA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AM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,YAAY,CAAC","sourcesContent":["import { type TConstValue } from '../types';\nimport { ConstClass } from '@/common/const-class';\n\n/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */\nexport class MimeTypes {\n static readonly UNKNOWN = 'unknown';\n static readonly IMAGE = 'image';\n static readonly VIDEO = 'video';\n static readonly TEXT = 'text';\n}\n/** One of the `MimeTypes` values. */\nexport type TMimeTypes = TConstValue<typeof MimeTypes>;\n\n/** The leading dot is part of the value: `path.extname` returns one. */\nexport class FileExtensions extends ConstClass {\n static readonly PNG = '.png';\n static readonly JPG = '.jpg';\n static readonly JPEG = '.jpeg';\n static readonly GIF = '.gif';\n static readonly WEBP = '.webp';\n static readonly SVG = '.svg';\n static readonly PDF = '.pdf';\n static readonly JSON = '.json';\n static readonly TXT = '.txt';\n static readonly HTML = '.html';\n static readonly CSS = '.css';\n static readonly JS = '.js';\n static readonly MP4 = '.mp4';\n static readonly WEBM = '.webm';\n static readonly MP3 = '.mp3';\n static readonly WAV = '.wav';\n static readonly ZIP = '.zip';\n static readonly CSV = '.csv';\n static readonly XML = '.xml';\n static readonly XLSX = '.xlsx';\n static readonly XLS = '.xls';\n static readonly DOCX = '.docx';\n static readonly DOC = '.doc';\n static readonly PPTX = '.pptx';\n static readonly PPT = '.ppt';\n static readonly ODT = '.odt';\n static readonly ODS = '.ods';\n}\n/** One of the `FileExtensions` values, with its leading dot. */\nexport type TFileExtension = TConstValue<typeof FileExtensions>;\n\n/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */\nexport class ContentTypes extends ConstClass {\n static readonly OCTET_STREAM = 'application/octet-stream';\n static readonly PNG = 'image/png';\n static readonly JPEG = 'image/jpeg';\n static readonly GIF = 'image/gif';\n static readonly WEBP = 'image/webp';\n static readonly SVG = 'image/svg+xml';\n static readonly PDF = 'application/pdf';\n static readonly JSON = 'application/json';\n static readonly PLAIN_TEXT = 'text/plain';\n static readonly HTML = 'text/html';\n static readonly CSS = 'text/css';\n static readonly JAVASCRIPT = 'text/javascript';\n static readonly MP4 = 'video/mp4';\n static readonly WEBM = 'video/webm';\n static readonly MPEG_AUDIO = 'audio/mpeg';\n static readonly WAV = 'audio/wav';\n static readonly ZIP = 'application/zip';\n static readonly CSV = 'text/csv';\n static readonly XML = 'application/xml';\n static readonly XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n static readonly XLS = 'application/vnd.ms-excel';\n static readonly DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';\n static readonly DOC = 'application/msword';\n static readonly PPTX =\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation';\n\n static readonly PPT = 'application/vnd.ms-powerpoint';\n static readonly ODT = 'application/vnd.oasis.opendocument.text';\n static readonly ODS = 'application/vnd.oasis.opendocument.spreadsheet';\n}\n/** One of the `ContentTypes` values. */\nexport type TContentType = TConstValue<typeof ContentTypes>;\n\n/** The extension table and the lookup that reads it, together - the `DurationMultipliers` shape. */\nexport class ContentTypeTable {\n /** `satisfies` makes the table total; the declared `string` key keeps a lookup cast-free. */\n static readonly BY_EXTENSION: Readonly<Partial<Record<string, TContentType>>> = {\n [FileExtensions.PNG]: ContentTypes.PNG,\n [FileExtensions.JPG]: ContentTypes.JPEG,\n [FileExtensions.JPEG]: ContentTypes.JPEG,\n [FileExtensions.GIF]: ContentTypes.GIF,\n [FileExtensions.WEBP]: ContentTypes.WEBP,\n [FileExtensions.SVG]: ContentTypes.SVG,\n [FileExtensions.PDF]: ContentTypes.PDF,\n [FileExtensions.JSON]: ContentTypes.JSON,\n [FileExtensions.TXT]: ContentTypes.PLAIN_TEXT,\n [FileExtensions.HTML]: ContentTypes.HTML,\n [FileExtensions.CSS]: ContentTypes.CSS,\n [FileExtensions.JS]: ContentTypes.JAVASCRIPT,\n [FileExtensions.MP4]: ContentTypes.MP4,\n [FileExtensions.WEBM]: ContentTypes.WEBM,\n [FileExtensions.MP3]: ContentTypes.MPEG_AUDIO,\n [FileExtensions.WAV]: ContentTypes.WAV,\n [FileExtensions.ZIP]: ContentTypes.ZIP,\n [FileExtensions.CSV]: ContentTypes.CSV,\n [FileExtensions.XML]: ContentTypes.XML,\n [FileExtensions.XLSX]: ContentTypes.XLSX,\n [FileExtensions.XLS]: ContentTypes.XLS,\n [FileExtensions.DOCX]: ContentTypes.DOCX,\n [FileExtensions.DOC]: ContentTypes.DOC,\n [FileExtensions.PPTX]: ContentTypes.PPTX,\n [FileExtensions.PPT]: ContentTypes.PPT,\n [FileExtensions.ODT]: ContentTypes.ODT,\n [FileExtensions.ODS]: ContentTypes.ODS,\n } satisfies Readonly<Record<TFileExtension, TContentType>>;\n\n /**\n * The content type an object name implies. `node:path` is deliberately not used: this file is\n * reachable from the browser-pure `./common` subpath, and an extension is the tail after the last\n * dot either way.\n */\n static resolve(opts: { filename: string }): TContentType {\n const { filename } = opts;\n const lastDot = filename.lastIndexOf('.');\n const extension = lastDot === -1 ? '' : filename.slice(lastDot).toLowerCase();\n\n return this.BY_EXTENSION[extension] ?? ContentTypes.OCTET_STREAM;\n }\n}\n\n/** Published before the table moved onto the class; kept as the one-line delegate it now is. */\nexport const CONTENT_TYPE_BY_EXTENSION = ContentTypeTable.BY_EXTENSION;\n"]}
|
package/dist/esm/common/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC","sourcesContent":["export * from './constants';\nexport * from './redact';\nexport * from './resolvers';\nexport * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC","sourcesContent":["export * from './const-class';\nexport * from './constants';\nexport * from './redact';\nexport * from './resolvers';\nexport * from './types';\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { TConstValue } from '../../../common/types/index.js';
|
|
2
|
+
import { ConstClass } from '../../../common/const-class.js';
|
|
2
3
|
/** The ciphers `AES` supports. */
|
|
3
|
-
export declare class AESAlgorithms {
|
|
4
|
+
export declare class AESAlgorithms extends ConstClass {
|
|
4
5
|
static readonly AES_256_CBC = "aes-256-cbc";
|
|
5
6
|
static readonly AES_256_GCM = "aes-256-gcm";
|
|
6
|
-
static readonly SCHEME_SET: Set<string>;
|
|
7
|
-
static isValid(value: string): boolean;
|
|
8
7
|
}
|
|
9
8
|
/** Valid AES algorithm values. */
|
|
10
9
|
export type AESAlgorithmType = TConstValue<typeof AESAlgorithms>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import { ConstClass } from '../../../common/const-class.js';
|
|
1
2
|
/** The ciphers `AES` supports. */
|
|
2
|
-
export class AESAlgorithms {
|
|
3
|
+
export class AESAlgorithms extends ConstClass {
|
|
3
4
|
static { this.AES_256_CBC = 'aes-256-cbc'; }
|
|
4
5
|
static { this.AES_256_GCM = 'aes-256-gcm'; }
|
|
5
|
-
static { this.SCHEME_SET = new Set([this.AES_256_CBC, this.AES_256_GCM]); }
|
|
6
|
-
static isValid(value) {
|
|
7
|
-
return this.SCHEME_SET.has(value);
|
|
8
|
-
}
|
|
9
6
|
}
|
|
10
7
|
//# sourceMappingURL=aes.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.constants.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes.constants.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,kCAAkC;AAClC,MAAM,OAAO,aAAc,SAAQ,UAAU;aAC3B,gBAAW,GAAG,aAAa,CAAC;aAC5B,gBAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { ConstClass } from '@/common/const-class';\n\n/** The ciphers `AES` supports. */\nexport class AESAlgorithms extends ConstClass {\n static readonly AES_256_CBC = 'aes-256-cbc';\n static readonly AES_256_GCM = 'aes-256-gcm';\n}\n\n/** Valid AES algorithm values. */\nexport type AESAlgorithmType = TConstValue<typeof AESAlgorithms>;\n"]}
|
|
@@ -44,7 +44,7 @@ export class CredentialUtility {
|
|
|
44
44
|
}
|
|
45
45
|
if (typeof algorithm !== 'string' || !CredentialAlgorithms.isValid(algorithm)) {
|
|
46
46
|
throw getError({
|
|
47
|
-
message: `[CredentialUtility.hash] Invalid algorithm | Expected one of ${
|
|
47
|
+
message: `[CredentialUtility.hash] Invalid algorithm | Expected one of ${CredentialAlgorithms.values().join(', ')} | Got: ${String(algorithm)}`,
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
if (algorithm === CredentialAlgorithms.ARGON2ID) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/credential.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAE7B,MAAM,WAAW,CAAC;AAEnB,uDAAuD;AACvD,MAAM,aAAa,GAAG,aAAa,CAAC;AAEpC,0DAA0D;AAC1D,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,YAAY,GAAG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,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAE1D,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EACL,mFAAmF;gBACrF,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,IAAwB;QAC/C,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,sBAAsB,IAAI,CAAC,MAAM,8DAA8D;aACzG,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport { getError } from '@/modules/error';\nimport {\n CredentialAlgorithms,\n DEFAULT_CREDENTIAL_ALGORITHM,\n type TCredentialAlgorithm,\n} from '../common';\n\n/** The bcrypt versions the `bcrypt` package writes. */\nconst BCRYPT_PREFIX = /^\\$2[aby]\\$/;\n\n/** bcrypt reads only the first 72 bytes of a password. */\nconst BCRYPT_MAX_PASSWORD_BYTES = 72;\nconst MIN_COST = 4;\nconst MAX_COST = 31;\nconst DEFAULT_COST = 10;\n\n/**\n * Storing and checking a credential (a password) over `Bun.password`. `hash` writes an argon2id hash (Bun's\n * default parameters), or bcrypt when `algorithm: 'bcrypt'` asks for it (`$2b$`, 60 characters, the stored\n * format of the `bcrypt` package). `verify` reads every existing bcrypt and argon2 hash, whichever\n * algorithm `hash` wrote, so a stored password is never rehashed or migrated. Needs Bun: it throws on\n * another runtime.\n *\n * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ, and it only matters for\n * bcrypt. The package keeps only the first 72 bytes; Bun keeps all of them, by hashing a longer password\n * before bcrypt sees it. Two things follow, and they are the whole truth about \"the same format\":\n *\n * - A hash `hash` writes for a password longer than 72 bytes is read by Bun only. The `bcrypt` package\n * cannot verify it, so rolling back to that package, or another service reading the same column, locks\n * those users out. Up to 72 bytes the two read each other's hashes.\n * - A hash the `bcrypt` package wrote for a longer password fails a plain `Bun.password.verify` with the full\n * password. `verify` therefore retries a bcrypt hash with the first 72 bytes when the password is longer.\n * That retry is for the legacy hashes. A hash `hash` wrote never needs it, because Bun reads its own hash on\n * the first attempt. The retry has one price: a hash of a password of exactly 72 bytes also accepts that\n * password followed by anything, the way bcrypt itself always has.\n */\nexport class CredentialUtility {\n /**\n * A hash of `password`: argon2id (Bun's default parameters), or bcrypt with `algorithm: 'bcrypt'`.\n * For bcrypt, `cost` (4 to 31) is the work factor, `2 ** cost` rounds. `cost` with argon2id\n * is refused rather than ignored: a caller who tuned a cost is told the default changed.\n */\n static async hash(opts: {\n password: string;\n /**\n * The hashing scheme.\n * @default DEFAULT_CREDENTIAL_ALGORITHM\n */\n algorithm?: TCredentialAlgorithm;\n /**\n * The bcrypt work factor; refused with argon2id.\n * @default 10\n */\n cost?: number;\n }): Promise<string> {\n const { password, algorithm = DEFAULT_CREDENTIAL_ALGORITHM, cost } = opts;\n\n CredentialUtility.assertBun({ caller: 'hash' });\n\n if (typeof password !== 'string' || password.length === 0) {\n throw getError({\n message: '[CredentialUtility.hash] Invalid password | Expected a non-empty string',\n });\n }\n\n if (typeof algorithm !== 'string' || !CredentialAlgorithms.isValid(algorithm)) {\n throw getError({\n message: `[CredentialUtility.hash] Invalid algorithm | Expected one of ${CredentialAlgorithms.values().join(', ')} | Got: ${String(algorithm)}`,\n });\n }\n\n if (algorithm === CredentialAlgorithms.ARGON2ID) {\n if (cost !== undefined && cost !== null) {\n throw getError({\n message: `[CredentialUtility.hash] Invalid cost | cost applies to bcrypt only | Pass algorithm: 'bcrypt' to keep a bcrypt cost, or drop cost for argon2id`,\n });\n }\n\n return Bun.password.hash(password, { algorithm: 'argon2id' });\n }\n\n const bcryptCost = cost ?? DEFAULT_COST;\n\n if (!Number.isInteger(bcryptCost) || bcryptCost < MIN_COST || bcryptCost > MAX_COST) {\n throw getError({\n message: `[CredentialUtility.hash] Invalid cost | Expected an integer from ${MIN_COST} to ${MAX_COST} | Got: ${bcryptCost}`,\n });\n }\n\n return Bun.password.hash(password, { algorithm: 'bcrypt', cost: bcryptCost });\n }\n\n /**\n * Whether `password` matches `hash`. Nothing to match is `false`: an empty or non-string password, an empty\n * or non-string hash. A stored value that is not a password hash is a server fault (500), so a corrupt row is\n * never answered like a wrong password, and the runtime's own message stays out of it.\n */\n static async verify(opts: { password: string; hash: string }): Promise<boolean> {\n const { password, hash } = opts;\n\n CredentialUtility.assertBun({ caller: 'verify' });\n\n if (typeof password !== 'string' || password.length === 0) {\n return false;\n }\n\n if (typeof hash !== 'string' || hash.length === 0) {\n return false;\n }\n\n const matched = await CredentialUtility.verifyHash({ password, hash });\n\n if (matched || !BCRYPT_PREFIX.test(hash)) {\n return matched;\n }\n\n const bytes = Buffer.from(password, 'utf8');\n\n if (bytes.length <= BCRYPT_MAX_PASSWORD_BYTES) {\n return false;\n }\n\n return CredentialUtility.verifyHash({\n password: bytes.subarray(0, BCRYPT_MAX_PASSWORD_BYTES),\n hash,\n });\n }\n\n private static async verifyHash(opts: {\n password: string | Uint8Array;\n hash: string;\n }): Promise<boolean> {\n const { password, hash } = opts;\n\n try {\n const matched = await Bun.password.verify(password, hash);\n\n return matched;\n } catch (error) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message:\n '[CredentialUtility.verify] Invalid hash | The stored value is not a password hash',\n cause: error,\n });\n }\n }\n\n private static assertBun(opts: { caller: string }): void {\n if (typeof Bun === 'undefined') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[CredentialUtility.${opts.caller}] Unsupported runtime | CredentialUtility needs Bun.password`,\n });\n }\n }\n}\n"]}
|