@bessemer/cornerstone 0.5.86 → 0.5.88
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/aspect-ratio.d.ts +7 -4
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +16 -7
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/async.d.ts +1 -1
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +1 -1
- package/dist/async.js.map +1 -1
- package/dist/cache.d.ts +7 -6
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +12 -12
- package/dist/cache.js.map +1 -1
- package/dist/comparator.js +1 -1
- package/dist/comparator.js.map +1 -1
- package/dist/content.d.ts +5 -5
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js.map +1 -1
- package/dist/data-size.d.ts +2 -2
- package/dist/data-size.d.ts.map +1 -1
- package/dist/data-size.js.map +1 -1
- package/dist/{error-event.d.ts → error/error-event.d.ts} +42 -23
- package/dist/error/error-event.d.ts.map +1 -0
- package/dist/{error-event.js → error/error-event.js} +82 -60
- package/dist/error/error-event.js.map +1 -0
- package/dist/error/error-type.d.ts +11 -0
- package/dist/error/error-type.d.ts.map +1 -0
- package/dist/error/error-type.js +20 -0
- package/dist/error/error-type.js.map +1 -0
- package/dist/error/error.d.ts.map +1 -0
- package/dist/{error.js → error/error.js} +1 -1
- package/dist/error/error.js.map +1 -0
- package/dist/expression.d.ts +2 -2
- package/dist/expression.d.ts.map +1 -1
- package/dist/expression.js.map +1 -1
- package/dist/glob.d.ts +7 -3
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +23 -15
- package/dist/glob.js.map +1 -1
- package/dist/hash.d.ts +2 -2
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/hex-code.d.ts +7 -4
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +19 -5
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +7 -4
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +52 -43
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +7 -4
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +16 -5
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +7 -4
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +20 -11
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +7 -4
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +39 -30
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +8 -5
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +37 -30
- package/dist/intl/locale.js.map +1 -1
- package/dist/math.d.ts +2 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +12 -1
- package/dist/math.js.map +1 -1
- package/dist/mime-type.d.ts +7 -4
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +44 -35
- package/dist/mime-type.js.map +1 -1
- package/dist/monetary-amount.d.ts +3 -3
- package/dist/monetary-amount.d.ts.map +1 -1
- package/dist/monetary-amount.js +4 -4
- package/dist/monetary-amount.js.map +1 -1
- package/dist/object/object-path.d.ts +2 -2
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.d.ts +2 -2
- package/dist/object/type-path.d.ts.map +1 -1
- package/dist/object/type-path.js.map +1 -1
- package/dist/object.d.ts +2 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +3 -2
- package/dist/object.js.map +1 -1
- package/dist/range.d.ts +2 -2
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js.map +1 -1
- package/dist/reference.d.ts +2 -2
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js.map +1 -1
- package/dist/resource-key.d.ts +17 -8
- package/dist/resource-key.d.ts.map +1 -1
- package/dist/resource-key.js +42 -13
- package/dist/resource-key.js.map +1 -1
- package/dist/result.d.ts +6 -5
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +4 -4
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +1 -1
- package/dist/retry.js.map +1 -1
- package/dist/rich-text.d.ts +2 -2
- package/dist/rich-text.d.ts.map +1 -1
- package/dist/rich-text.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +5 -1
- package/dist/signature.js.map +1 -1
- package/dist/sql.d.ts +2 -2
- package/dist/sql.d.ts.map +1 -1
- package/dist/sql.js.map +1 -1
- package/dist/tag.d.ts +3 -3
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js.map +1 -1
- package/dist/temporal/chrono.d.ts +34 -0
- package/dist/temporal/chrono.d.ts.map +1 -0
- package/dist/temporal/chrono.js +34 -0
- package/dist/temporal/chrono.js.map +1 -0
- package/dist/temporal/clock.d.ts +21 -0
- package/dist/temporal/clock.d.ts.map +1 -0
- package/dist/temporal/clock.js +76 -0
- package/dist/temporal/clock.js.map +1 -0
- package/dist/temporal/date.d.ts +2 -0
- package/dist/temporal/date.d.ts.map +1 -0
- package/dist/temporal/date.js +8 -0
- package/dist/temporal/date.js.map +1 -0
- package/dist/temporal/duration.d.ts +54 -0
- package/dist/temporal/duration.d.ts.map +1 -0
- package/dist/temporal/duration.js +162 -0
- package/dist/temporal/duration.js.map +1 -0
- package/dist/temporal/instant.d.ts +35 -0
- package/dist/temporal/instant.d.ts.map +1 -0
- package/dist/temporal/instant.js +91 -0
- package/dist/temporal/instant.js.map +1 -0
- package/dist/temporal/plain-time.d.ts +49 -0
- package/dist/temporal/plain-time.d.ts.map +1 -0
- package/dist/temporal/plain-time.js +110 -0
- package/dist/temporal/plain-time.js.map +1 -0
- package/dist/temporal/time-zone-id.d.ts +12 -0
- package/dist/temporal/time-zone-id.d.ts.map +1 -0
- package/dist/temporal/time-zone-id.js +35 -0
- package/dist/temporal/time-zone-id.js.map +1 -0
- package/dist/temporal/time-zone-offset.d.ts +22 -0
- package/dist/temporal/time-zone-offset.d.ts.map +1 -0
- package/dist/temporal/time-zone-offset.js +145 -0
- package/dist/temporal/time-zone-offset.js.map +1 -0
- package/dist/types.d.ts +12 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/ulid.d.ts +7 -4
- package/dist/ulid.d.ts.map +1 -1
- package/dist/ulid.js +14 -5
- package/dist/ulid.js.map +1 -1
- package/dist/unit.d.ts +2 -2
- package/dist/unit.d.ts.map +1 -1
- package/dist/unit.js.map +1 -1
- package/dist/uri.d.ts +2 -2
- package/dist/uri.d.ts.map +1 -1
- package/dist/uri.js.map +1 -1
- package/dist/uuid.d.ts +7 -4
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +14 -5
- package/dist/uuid.js.map +1 -1
- package/dist/zod-util.d.ts +5 -0
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +28 -2
- package/dist/zod-util.js.map +1 -1
- package/package.json +2 -2
- package/dist/date.d.ts +0 -13
- package/dist/date.d.ts.map +0 -1
- package/dist/date.js +0 -40
- package/dist/date.js.map +0 -1
- package/dist/duration.d.ts +0 -18
- package/dist/duration.d.ts.map +0 -1
- package/dist/duration.js +0 -53
- package/dist/duration.js.map +0 -1
- package/dist/error-event.d.ts.map +0 -1
- package/dist/error-event.js.map +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js.map +0 -1
- /package/dist/{error.d.ts → error/error.d.ts} +0 -0
package/dist/aspect-ratio.d.ts
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
import Zod from 'zod';
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
2
|
+
import { NominalType } from '@bessemer/cornerstone/types';
|
3
|
+
import { Result } from '@bessemer/cornerstone/result';
|
4
|
+
import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
|
5
|
+
export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"aspect-ratio">;
|
6
|
+
export type AspectRatio = NominalType<string, typeof Namespace>;
|
7
|
+
export declare const parseString: (value: string) => Result<AspectRatio, ErrorEvent>;
|
8
|
+
export declare const fromString: (value: string) => AspectRatio;
|
5
9
|
export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<AspectRatio, string>>;
|
6
|
-
export declare const fromString: (aspectRatio: string) => AspectRatio;
|
7
10
|
export declare const fromDimensions: (width: number, height: number) => AspectRatio;
|
8
11
|
export declare const numericValue: (aspectRatio: AspectRatio) => number;
|
9
12
|
export declare const calculateHeight: (width: number, aspectRatio: AspectRatio) => number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aspect-ratio.d.ts","sourceRoot":"","sources":["../src/aspect-ratio.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"aspect-ratio.d.ts","sourceRoot":"","sources":["../src/aspect-ratio.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAIhG,eAAO,MAAM,SAAS,gFAA4B,CAAA;AAClD,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CAMzE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,WAE1C,CAAA;AAED,eAAO,MAAM,MAAM,mEAAiD,CAAA;AAEpE,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,WAK9D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,aAAa,WAAW,KAAG,MAGvD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,aAAa,WAAW,KAAG,MAGzE,CAAA"}
|
package/dist/aspect-ratio.js
CHANGED
@@ -1,18 +1,26 @@
|
|
1
1
|
// src/aspect-ratio.ts
|
2
2
|
import Zod from "zod";
|
3
3
|
import { greatestCommonFactor } from "@bessemer/cornerstone/math";
|
4
|
-
|
5
|
-
|
4
|
+
import { failure, success } from "@bessemer/cornerstone/result";
|
5
|
+
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
6
|
+
import { namespace } from "@bessemer/cornerstone/resource-key";
|
7
|
+
import { structuredTransform } from "@bessemer/cornerstone/zod-util";
|
8
|
+
var Namespace = namespace("aspect-ratio");
|
9
|
+
var parseString = (value) => {
|
10
|
+
if (!/^[1-9]\d*:[1-9]\d*$/.test(value)) {
|
11
|
+
return failure(invalidValue(value, { namespace: Namespace, message: `Aspect Ratio must be in the format 'width:height' (e.g., '16:9', '4:3').` }));
|
12
|
+
}
|
13
|
+
return success(value);
|
6
14
|
};
|
7
|
-
var
|
8
|
-
|
9
|
-
return Schema.parse(aspectRatio);
|
15
|
+
var fromString = (value) => {
|
16
|
+
return unpackResult(parseString(value));
|
10
17
|
};
|
18
|
+
var Schema = structuredTransform(Zod.string(), parseString);
|
11
19
|
var fromDimensions = (width, height) => {
|
12
20
|
const factor = greatestCommonFactor(width, height);
|
13
21
|
const ratioWidth = width / factor;
|
14
22
|
const ratioHeight = height / factor;
|
15
|
-
return
|
23
|
+
return `${ratioWidth}:${ratioHeight}`;
|
16
24
|
};
|
17
25
|
var numericValue = (aspectRatio) => {
|
18
26
|
const [width, height] = aspectRatio.split(":").map(Number);
|
@@ -27,12 +35,13 @@ var calculateWidth = (height, aspectRatio) => {
|
|
27
35
|
return height * ratio;
|
28
36
|
};
|
29
37
|
export {
|
38
|
+
Namespace,
|
30
39
|
Schema,
|
31
40
|
calculateHeight,
|
32
41
|
calculateWidth,
|
33
42
|
fromDimensions,
|
34
43
|
fromString,
|
35
44
|
numericValue,
|
36
|
-
|
45
|
+
parseString
|
37
46
|
};
|
38
47
|
//# sourceMappingURL=aspect-ratio.js.map
|
package/dist/aspect-ratio.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/aspect-ratio.ts"],"sourcesContent":["import Zod from 'zod'\nimport { greatestCommonFactor } from '@bessemer/cornerstone/math'\nimport {
|
1
|
+
{"version":3,"sources":["../src/aspect-ratio.ts"],"sourcesContent":["import Zod from 'zod'\nimport { greatestCommonFactor } from '@bessemer/cornerstone/math'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('aspect-ratio')\nexport type AspectRatio = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<AspectRatio, ErrorEvent> => {\n if (!/^[1-9]\\d*:[1-9]\\d*$/.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `Aspect Ratio must be in the format 'width:height' (e.g., '16:9', '4:3').` }))\n }\n\n return success(value as AspectRatio)\n}\n\nexport const fromString = (value: string): AspectRatio => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const fromDimensions = (width: number, height: number): AspectRatio => {\n const factor = greatestCommonFactor(width, height)\n const ratioWidth = width / factor\n const ratioHeight = height / factor\n return `${ratioWidth}:${ratioHeight}` as AspectRatio\n}\n\nexport const numericValue = (aspectRatio: AspectRatio): number => {\n const [width, height] = aspectRatio.split(':').map(Number)\n return width! / height!\n}\n\nexport const calculateHeight = (width: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return width / ratio\n}\n\nexport const calculateWidth = (height: number, aspectRatio: AspectRatio): number => {\n const ratio = numericValue(aspectRatio)\n return height * ratio\n}\n"],"mappings":";AAAA,OAAO,SAAS;AAChB,SAAS,4BAA4B;AAErC,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,cAAc;AAG1C,IAAM,cAAc,CAAC,UAAmD;AAC7E,MAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,2EAA2E,CAAC,CAAC;AAAA,EACnJ;AAEA,SAAO,QAAQ,KAAoB;AACrC;AAEO,IAAM,aAAa,CAAC,UAA+B;AACxD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,iBAAiB,CAAC,OAAe,WAAgC;AAC5E,QAAM,SAAS,qBAAqB,OAAO,MAAM;AACjD,QAAM,aAAa,QAAQ;AAC3B,QAAM,cAAc,SAAS;AAC7B,SAAO,GAAG,UAAU,IAAI,WAAW;AACrC;AAEO,IAAM,eAAe,CAAC,gBAAqC;AAChE,QAAM,CAAC,OAAO,MAAM,IAAI,YAAY,MAAM,GAAG,EAAE,IAAI,MAAM;AACzD,SAAO,QAAS;AAClB;AAEO,IAAM,kBAAkB,CAAC,OAAe,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,QAAQ;AACjB;AAEO,IAAM,iBAAiB,CAAC,QAAgB,gBAAqC;AAClF,QAAM,QAAQ,aAAa,WAAW;AACtC,SAAO,SAAS;AAClB;","names":[]}
|
package/dist/async.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Duration } from '@bessemer/cornerstone/duration';
|
1
|
+
import { Duration } from '@bessemer/cornerstone/temporal/duration';
|
2
2
|
export declare const execute: <T>(runnable: () => Promise<T>) => Promise<T>;
|
3
3
|
export declare const sleep: (duration: Duration) => Promise<void>;
|
4
4
|
//# sourceMappingURL=async.d.ts.map
|
package/dist/async.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,yCAAyC,CAAA;AAElF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,UAAU,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAWhE,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,UAAU,QAAQ,KAAG,OAAO,CAAC,IAAI,CAItD,CAAA"}
|
package/dist/async.js
CHANGED
package/dist/async.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/async.ts"],"sourcesContent":["import { Duration, toMilliseconds } from '@bessemer/cornerstone/duration'\n\nexport const execute = <T>(runnable: () => Promise<T>): Promise<T> => {\n return new Promise(async (resolve, reject) => {\n setTimeout(async () => {\n try {\n const value = await runnable()\n resolve(value)\n } catch (e) {\n reject(e)\n }\n }, 0)\n })\n}\n\nexport const sleep = (duration: Duration): Promise<void> => {\n return new Promise((resolve) => {\n setTimeout(resolve, toMilliseconds(duration))\n })\n}\n"],"mappings":";AAAA,SAAmB,sBAAsB;AAElC,IAAM,UAAU,CAAI,aAA2C;AACpE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,eAAW,YAAY;AACrB,UAAI;AACF,cAAM,QAAQ,MAAM,SAAS;AAC7B,gBAAQ,KAAK;AAAA,MACf,SAAS,GAAG;AACV,eAAO,CAAC;AAAA,MACV;AAAA,IACF,GAAG,CAAC;AAAA,EACN,CAAC;AACH;AAEO,IAAM,QAAQ,CAAC,aAAsC;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,SAAS,eAAe,QAAQ,CAAC;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
1
|
+
{"version":3,"sources":["../src/async.ts"],"sourcesContent":["import { Duration, toMilliseconds } from '@bessemer/cornerstone/temporal/duration'\n\nexport const execute = <T>(runnable: () => Promise<T>): Promise<T> => {\n return new Promise(async (resolve, reject) => {\n setTimeout(async () => {\n try {\n const value = await runnable()\n resolve(value)\n } catch (e) {\n reject(e)\n }\n }, 0)\n })\n}\n\nexport const sleep = (duration: Duration): Promise<void> => {\n return new Promise((resolve) => {\n setTimeout(resolve, toMilliseconds(duration))\n })\n}\n"],"mappings":";AAAA,SAAmB,sBAAsB;AAElC,IAAM,UAAU,CAAI,aAA2C;AACpE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,eAAW,YAAY;AACrB,UAAI;AACF,cAAM,QAAQ,MAAM,SAAS;AAC7B,gBAAQ,KAAK;AAAA,MACf,SAAS,GAAG;AACV,eAAO,CAAC;AAAA,MACV;AAAA,IACF,GAAG,CAAC;AAAA,EACN,CAAC;AACH;AAEO,IAAM,QAAQ,CAAC,aAAsC;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,SAAS,eAAe,QAAQ,CAAC;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
package/dist/cache.d.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
import { AbstractLocalKeyValueStore, AbstractRemoteKeyValueStore, LocalKeyValueStore, RemoteKeyValueStore } from '@bessemer/cornerstone/store';
|
2
|
-
import { Duration } from '@bessemer/cornerstone/duration';
|
2
|
+
import { Duration } from '@bessemer/cornerstone/temporal/duration';
|
3
3
|
import { ResourceKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key';
|
4
4
|
import { AbstractApplicationContext } from '@bessemer/cornerstone/context';
|
5
|
-
import {
|
5
|
+
import { TaggedType } from '@bessemer/cornerstone/types';
|
6
6
|
import { RecordEntry } from '@bessemer/cornerstone/entry';
|
7
7
|
import { GlobPattern } from '@bessemer/cornerstone/glob';
|
8
8
|
import { Arrayable } from 'type-fest';
|
9
9
|
import { ZodType } from 'zod';
|
10
|
+
import { InstantLiteral } from '@bessemer/cornerstone/temporal/instant';
|
10
11
|
export type CacheProps = {
|
11
12
|
maxSize: number | null;
|
12
13
|
timeToLive: Duration;
|
@@ -25,7 +26,7 @@ export declare namespace CacheSector {
|
|
25
26
|
};
|
26
27
|
const namespace: (namespace: ResourceNamespace, sector: CacheSector) => CacheSector;
|
27
28
|
}
|
28
|
-
export type CacheName =
|
29
|
+
export type CacheName = TaggedType<string, 'CacheName'>;
|
29
30
|
export declare const CacheNameSchema: ZodType<CacheName>;
|
30
31
|
export interface AsyncCache<T> {
|
31
32
|
name: CacheName;
|
@@ -69,8 +70,8 @@ export declare abstract class AbstractLocalCacheProvider<T> extends AbstractLoca
|
|
69
70
|
}
|
70
71
|
export type CacheEntry<T> = {
|
71
72
|
value: T;
|
72
|
-
liveTimestamp:
|
73
|
-
staleTimestamp:
|
73
|
+
liveTimestamp: InstantLiteral | null;
|
74
|
+
staleTimestamp: InstantLiteral | null;
|
74
75
|
};
|
75
76
|
export declare namespace CacheEntry {
|
76
77
|
const isActive: <T>(entry: CacheEntry<T>) => boolean;
|
@@ -95,7 +96,7 @@ export type CacheDefinition = {
|
|
95
96
|
options?: CacheOptions;
|
96
97
|
providers: Array<CacheProviderConfiguration>;
|
97
98
|
};
|
98
|
-
export type CacheProviderType =
|
99
|
+
export type CacheProviderType = TaggedType<string, 'CacheProviderType'>;
|
99
100
|
export type CacheProviderConfiguration = CacheOptions & {
|
100
101
|
type: CacheProviderType;
|
101
102
|
};
|
package/dist/cache.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAC9I,OAAO,EAAE,QAAQ,
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAC9I,OAAO,EAAE,QAAQ,EAAmB,MAAM,yCAAyC,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACnF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,UAAU,EAAE,QAAQ,CAAA;IACpB,WAAW,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAE9C,yBAAiB,UAAU,CAAC;IAOnB,MAA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B,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,WAAW,SAAS,0BAA0B,IAAI;IAClF,IAAI,EAAE,iBAAiB,CAAA;IACvB,SAAS,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,KAAK,aAAa,CAAC,CAAC,CAAC,CAAA;CAC5E,CAAA"}
|
package/dist/cache.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
// src/cache.ts
|
2
2
|
import { AbstractLocalKeyValueStore, AbstractRemoteKeyValueStore } from "@bessemer/cornerstone/store";
|
3
|
-
import { OneDay, OneHour
|
3
|
+
import { OneDay, OneHour } from "@bessemer/cornerstone/temporal/duration";
|
4
4
|
import Zod from "zod";
|
5
5
|
import { deepMerge, isNil } from "@bessemer/cornerstone/object";
|
6
6
|
import { toArray } from "@bessemer/cornerstone/array";
|
7
|
-
import {
|
8
|
-
import
|
7
|
+
import { Arrays, Entries, ResourceKeys } from "@bessemer/cornerstone";
|
8
|
+
import * as Instants from "@bessemer/cornerstone/temporal/instant";
|
9
9
|
var CacheProps;
|
10
10
|
((CacheProps2) => {
|
11
11
|
const DefaultCacheProps = {
|
@@ -28,7 +28,7 @@ var CacheSector;
|
|
28
28
|
return { globs: toArray(globs) };
|
29
29
|
};
|
30
30
|
CacheSector2.namespace = (namespace2, sector) => {
|
31
|
-
return { globs: ResourceKeys.applyNamespaceAll(
|
31
|
+
return { globs: ResourceKeys.applyNamespaceAll(sector.globs, namespace2).map((it) => it) };
|
32
32
|
};
|
33
33
|
})(CacheSector || (CacheSector = {}));
|
34
34
|
var CacheNameSchema = Zod.string();
|
@@ -65,14 +65,14 @@ var CacheEntry;
|
|
65
65
|
if (isNil(entry.liveTimestamp)) {
|
66
66
|
return false;
|
67
67
|
}
|
68
|
-
return isBefore(entry.liveTimestamp, now());
|
68
|
+
return Instants.isBefore(entry.liveTimestamp, Instants.now());
|
69
69
|
};
|
70
70
|
CacheEntry2.isAlive = (entry) => !(0, CacheEntry2.isDead)(entry);
|
71
71
|
CacheEntry2.isStale = (entry) => {
|
72
72
|
if (isNil(entry.staleTimestamp)) {
|
73
73
|
return false;
|
74
74
|
}
|
75
|
-
return isBefore(entry.staleTimestamp, now());
|
75
|
+
return Instants.isBefore(entry.staleTimestamp, Instants.now());
|
76
76
|
};
|
77
77
|
CacheEntry2.of = (value) => {
|
78
78
|
const entry = {
|
@@ -85,16 +85,16 @@ var CacheEntry;
|
|
85
85
|
CacheEntry2.applyProps = (originalEntry, props) => {
|
86
86
|
let liveTimestamp = originalEntry.liveTimestamp;
|
87
87
|
if (!isNil(props.timeToLive)) {
|
88
|
-
const limit =
|
89
|
-
if (isBefore(limit, liveTimestamp ?? limit)) {
|
90
|
-
liveTimestamp = limit;
|
88
|
+
const limit = Instants.add(Instants.now(), props.timeToLive);
|
89
|
+
if (Instants.isBefore(limit, liveTimestamp ?? limit)) {
|
90
|
+
liveTimestamp = Instants.toLiteral(limit);
|
91
91
|
}
|
92
92
|
}
|
93
93
|
let staleTimestamp = originalEntry.staleTimestamp;
|
94
94
|
if (!isNil(props.timeToStale)) {
|
95
|
-
const limit =
|
96
|
-
if (isBefore(limit, staleTimestamp ?? limit)) {
|
97
|
-
staleTimestamp = limit;
|
95
|
+
const limit = Instants.add(Instants.now(), props.timeToStale);
|
96
|
+
if (Instants.isBefore(limit, staleTimestamp ?? limit)) {
|
97
|
+
staleTimestamp = Instants.toLiteral(limit);
|
98
98
|
}
|
99
99
|
}
|
100
100
|
const limitedEntry = {
|
package/dist/cache.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/cache.ts"],"sourcesContent":["import { AbstractLocalKeyValueStore, AbstractRemoteKeyValueStore, LocalKeyValueStore, RemoteKeyValueStore } from '@bessemer/cornerstone/store'\nimport { Duration, OneDay, OneHour, toMilliseconds } from '@bessemer/cornerstone/duration'\nimport { ResourceKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport { AbstractApplicationContext } from '@bessemer/cornerstone/context'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { RecordEntry } from '@bessemer/cornerstone/entry'\nimport { GlobPattern } from '@bessemer/cornerstone/glob'\nimport { Arrayable } from 'type-fest'\nimport Zod, { ZodType } from 'zod'\nimport { deepMerge, isNil } from '@bessemer/cornerstone/object'\nimport { toArray } from '@bessemer/cornerstone/array'\nimport { addMilliseconds, isBefore, now } from '@bessemer/cornerstone/date'\nimport { Arrays, Entries, ResourceKeys } from '@bessemer/cornerstone/index'\n\nexport type CacheProps = {\n maxSize: number | null\n timeToLive: Duration\n timeToStale: Duration | null\n}\n\nexport type CacheOptions = Partial<CacheProps>\n\nexport namespace CacheProps {\n const DefaultCacheProps = {\n maxSize: 50000,\n timeToLive: OneDay,\n timeToStale: OneHour,\n }\n\n export const buildCacheProps = (options?: CacheOptions): CacheProps => {\n options = options ?? {}\n\n const props = deepMerge(DefaultCacheProps, options)\n\n if (props.maxSize === null && props.timeToLive === null) {\n throw new Error('Invalid cache configuration, both maxSize and timeToLive are null')\n }\n\n return props\n }\n}\n\nexport type CacheSector = {\n globs: Array<GlobPattern>\n}\n\nexport namespace CacheSector {\n export const of = (globs: Arrayable<GlobPattern>) => {\n return { globs: toArray(globs) }\n }\n\n export const namespace = (namespace: ResourceNamespace, sector: CacheSector): CacheSector => {\n return { globs: ResourceKeys.applyNamespaceAll(namespace, sector.globs) }\n }\n}\n\nexport type CacheName = NominalType<string, 'CacheName'>\nexport const CacheNameSchema: ZodType<CacheName> = Zod.string()\n\nexport interface AsyncCache<T> {\n name: CacheName\n\n fetchValue(key: ResourceKey, fetch: () => Promise<T>): Promise<T>\n\n fetchValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Promise<Array<RecordEntry<T>>>): Promise<Array<RecordEntry<T>>>\n\n writeValue(key: ResourceKey, value: T | undefined): Promise<void>\n\n writeValues(entries: Array<RecordEntry<T | undefined>>): Promise<void>\n\n evictAll(sector: CacheSector): Promise<void>\n}\n\nexport abstract class AbstractAsyncCache<T> implements AsyncCache<T> {\n abstract name: CacheName\n\n fetchValue = async (key: ResourceKey, fetch: () => Promise<T>): Promise<T> => {\n const results = await this.fetchValues([key], async () => {\n return [Entries.of(key, await fetch())]\n })\n\n return Arrays.first(results)![1]\n }\n\n abstract fetchValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Promise<RecordEntry<T>[]>): Promise<RecordEntry<T>[]>\n\n writeValue = async (key: ResourceKey, value: T | undefined): Promise<void> => {\n await this.writeValues([Entries.of(key, value)])\n }\n\n abstract writeValues(entries: RecordEntry<T | undefined>[]): Promise<void>\n\n abstract evictAll(sector: CacheSector): Promise<void>\n}\n\nexport interface CacheProvider<T> extends RemoteKeyValueStore<CacheEntry<T>> {\n type: CacheProviderType\n\n evictAll(sector: CacheSector): Promise<void>\n}\n\nexport abstract class AbstractCacheProvider<T> extends AbstractRemoteKeyValueStore<CacheEntry<T>> implements CacheProvider<T> {\n abstract type: CacheProviderType\n\n abstract evictAll(sector: CacheSector): Promise<void>\n}\n\nexport interface LocalCache<T> {\n name: CacheName\n\n getValue(key: ResourceKey, fetch: () => T): T\n\n getValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Array<RecordEntry<T>>): Array<RecordEntry<T>>\n\n setValue(key: ResourceKey, value: T | undefined): void\n\n setValues(entries: Array<RecordEntry<T | undefined>>): void\n\n removeAll(sector: CacheSector): void\n}\n\nexport interface LocalCacheProvider<T> extends LocalKeyValueStore<CacheEntry<T>>, CacheProvider<T> {\n removeAll(sector: CacheSector): void\n}\n\nexport abstract class AbstractLocalCacheProvider<T> extends AbstractLocalKeyValueStore<CacheEntry<T>> implements LocalCacheProvider<T> {\n abstract type: CacheProviderType\n\n abstract removeAll(sector: CacheSector): void\n\n async evictAll(sector: CacheSector): Promise<void> {\n this.removeAll(sector)\n }\n}\n\nexport type CacheEntry<T> = {\n value: T\n liveTimestamp: Date | null\n staleTimestamp: Date | null\n}\n\nexport namespace CacheEntry {\n export const isActive = <T>(entry: CacheEntry<T>): boolean => {\n if (isDead(entry) || isStale(entry)) {\n return false\n }\n\n return true\n }\n\n export const isDead = <T>(entry: CacheEntry<T> | undefined): boolean => {\n if (isNil(entry)) {\n return true\n }\n\n if (isNil(entry.liveTimestamp)) {\n return false\n }\n\n return isBefore(entry.liveTimestamp, now())\n }\n\n export const isAlive = <T>(entry: CacheEntry<T> | undefined): boolean => !isDead(entry)\n\n export const isStale = <T>(entry: CacheEntry<T>): boolean => {\n if (isNil(entry.staleTimestamp)) {\n return false\n }\n\n return isBefore(entry.staleTimestamp, now())\n }\n\n export const of = <T>(value: T) => {\n const entry: CacheEntry<T> = {\n value,\n liveTimestamp: null,\n staleTimestamp: null,\n }\n\n return entry\n }\n\n // JOHN do we want to enforce some kind of minimum liveness threshold?\n export const applyProps = <T>(originalEntry: CacheEntry<T>, props: CacheProps): CacheEntry<T> => {\n let liveTimestamp: Date | null = originalEntry.liveTimestamp\n if (!isNil(props.timeToLive)) {\n const limit = addMilliseconds(now(), toMilliseconds(props.timeToLive))\n if (isBefore(limit, liveTimestamp ?? limit)) {\n liveTimestamp = limit\n }\n }\n\n let staleTimestamp: Date | null = originalEntry.staleTimestamp\n if (!isNil(props.timeToStale)) {\n const limit = addMilliseconds(now(), toMilliseconds(props.timeToStale))\n if (isBefore(limit, staleTimestamp ?? limit)) {\n staleTimestamp = limit\n }\n }\n\n const limitedEntry: CacheEntry<T> = {\n value: originalEntry.value,\n liveTimestamp,\n staleTimestamp,\n }\n\n return limitedEntry\n }\n}\n\nexport type CacheConfigurationOptions = CacheConfigurationSection & {\n local: CacheConfigurationSection\n}\n\nexport type CacheConfigurationSection = {\n defaults: CacheDefinition\n\n /**\n * These options map from cache name key to configuration. They are a way for the tenant to override the configurations\n * for specific caches from the cache configuration here.\n */\n caches?: Record<string, Partial<CacheDefinition>>\n}\n\nexport type CacheDefinition = {\n options?: CacheOptions\n providers: Array<CacheProviderConfiguration>\n}\n\nexport type CacheProviderType = NominalType<string, 'CacheProviderType'>\nexport type CacheProviderConfiguration = CacheOptions & {\n type: CacheProviderType\n}\n\nexport type CacheConfiguration = CacheConfigurationSection & {\n local: CacheConfigurationSection\n}\n\nexport type CacheProviderRegistry<ContextType extends AbstractApplicationContext> = {\n type: CacheProviderType\n construct: <T>(props: CacheProps, context: ContextType) => CacheProvider<T>\n}\n"],"mappings":";AAAA,SAAS,4BAA4B,mCAA4E;AACjH,SAAmB,QAAQ,SAAS,sBAAsB;AAO1D,OAAO,SAAsB;AAC7B,SAAS,WAAW,aAAa;AACjC,SAAS,eAAe;AACxB,SAAS,iBAAiB,UAAU,WAAW;AAC/C,SAAS,QAAQ,SAAS,oBAAoB;AAUvC,IAAU;AAAA,CAAV,CAAUA,gBAAV;AACL,QAAM,oBAAoB;AAAA,IACxB,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,aAAa;AAAA,EACf;AAEO,EAAMA,YAAA,kBAAkB,CAAC,YAAuC;AACrE,cAAU,WAAW,CAAC;AAEtB,UAAM,QAAQ,UAAU,mBAAmB,OAAO;AAElD,QAAI,MAAM,YAAY,QAAQ,MAAM,eAAe,MAAM;AACvD,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACrF;AAEA,WAAO;AAAA,EACT;AAAA,GAjBe;AAwBV,IAAU;AAAA,CAAV,CAAUC,iBAAV;AACE,EAAMA,aAAA,KAAK,CAAC,UAAkC;AACnD,WAAO,EAAE,OAAO,QAAQ,KAAK,EAAE;AAAA,EACjC;AAEO,EAAMA,aAAA,YAAY,CAACC,YAA8B,WAAqC;AAC3F,WAAO,EAAE,OAAO,aAAa,kBAAkBA,YAAW,OAAO,KAAK,EAAE;AAAA,EAC1E;AAAA,GAPe;AAWV,IAAM,kBAAsC,IAAI,OAAO;AAgBvD,IAAe,qBAAf,MAA8D;AAAA,EAGnE,aAAa,OAAO,KAAkB,UAAwC;AAC5E,UAAM,UAAU,MAAM,KAAK,YAAY,CAAC,GAAG,GAAG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BAA6B,cAAc;AAC/C,QAAI,CAAC,MAAM,MAAM,UAAU,GAAG;AAC5B,YAAM,QAAQ,gBAAgB,IAAI,GAAG,eAAe,MAAM,UAAU,CAAC;AACrE,UAAI,SAAS,OAAO,iBAAiB,KAAK,GAAG;AAC3C,wBAAgB;AAAA,MAClB;AAAA,IACF;AAEA,QAAI,iBAA8B,cAAc;AAChD,QAAI,CAAC,MAAM,MAAM,WAAW,GAAG;AAC7B,YAAM,QAAQ,gBAAgB,IAAI,GAAG,eAAe,MAAM,WAAW,CAAC;AACtE,UAAI,SAAS,OAAO,kBAAkB,KAAK,GAAG;AAC5C,yBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,UAAM,eAA8B;AAAA,MAClC,OAAO,cAAc;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,GAlEe;","names":["CacheProps","CacheSector","namespace","CacheEntry"]}
|
1
|
+
{"version":3,"sources":["../src/cache.ts"],"sourcesContent":["import { AbstractLocalKeyValueStore, AbstractRemoteKeyValueStore, LocalKeyValueStore, RemoteKeyValueStore } from '@bessemer/cornerstone/store'\nimport { Duration, OneDay, OneHour } from '@bessemer/cornerstone/temporal/duration'\nimport { ResourceKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport { AbstractApplicationContext } from '@bessemer/cornerstone/context'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport { RecordEntry } from '@bessemer/cornerstone/entry'\nimport { GlobPattern } from '@bessemer/cornerstone/glob'\nimport { Arrayable } from 'type-fest'\nimport Zod, { ZodType } from 'zod'\nimport { deepMerge, isNil } from '@bessemer/cornerstone/object'\nimport { toArray } from '@bessemer/cornerstone/array'\nimport { Arrays, Entries, ResourceKeys } from '@bessemer/cornerstone'\nimport * as Instants from '@bessemer/cornerstone/temporal/instant'\nimport { InstantLiteral } from '@bessemer/cornerstone/temporal/instant'\n\nexport type CacheProps = {\n maxSize: number | null\n timeToLive: Duration\n timeToStale: Duration | null\n}\n\nexport type CacheOptions = Partial<CacheProps>\n\nexport namespace CacheProps {\n const DefaultCacheProps = {\n maxSize: 50000,\n timeToLive: OneDay,\n timeToStale: OneHour,\n }\n\n export const buildCacheProps = (options?: CacheOptions): CacheProps => {\n options = options ?? {}\n\n const props = deepMerge(DefaultCacheProps, options)\n\n if (props.maxSize === null && props.timeToLive === null) {\n throw new Error('Invalid cache configuration, both maxSize and timeToLive are null')\n }\n\n return props\n }\n}\n\nexport type CacheSector = {\n globs: Array<GlobPattern>\n}\n\nexport namespace CacheSector {\n export const of = (globs: Arrayable<GlobPattern>) => {\n return { globs: toArray(globs) }\n }\n\n export const namespace = (namespace: ResourceNamespace, sector: CacheSector): CacheSector => {\n return { globs: ResourceKeys.applyNamespaceAll(sector.globs, namespace).map((it) => it as string as GlobPattern) }\n }\n}\n\nexport type CacheName = TaggedType<string, 'CacheName'>\nexport const CacheNameSchema: ZodType<CacheName> = Zod.string()\n\nexport interface AsyncCache<T> {\n name: CacheName\n\n fetchValue(key: ResourceKey, fetch: () => Promise<T>): Promise<T>\n\n fetchValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Promise<Array<RecordEntry<T>>>): Promise<Array<RecordEntry<T>>>\n\n writeValue(key: ResourceKey, value: T | undefined): Promise<void>\n\n writeValues(entries: Array<RecordEntry<T | undefined>>): Promise<void>\n\n evictAll(sector: CacheSector): Promise<void>\n}\n\nexport abstract class AbstractAsyncCache<T> implements AsyncCache<T> {\n abstract name: CacheName\n\n fetchValue = async (key: ResourceKey, fetch: () => Promise<T>): Promise<T> => {\n const results = await this.fetchValues([key], async () => {\n return [Entries.of(key, await fetch())]\n })\n\n return Arrays.first(results)![1]\n }\n\n abstract fetchValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Promise<RecordEntry<T>[]>): Promise<RecordEntry<T>[]>\n\n writeValue = async (key: ResourceKey, value: T | undefined): Promise<void> => {\n await this.writeValues([Entries.of(key, value)])\n }\n\n abstract writeValues(entries: RecordEntry<T | undefined>[]): Promise<void>\n\n abstract evictAll(sector: CacheSector): Promise<void>\n}\n\nexport interface CacheProvider<T> extends RemoteKeyValueStore<CacheEntry<T>> {\n type: CacheProviderType\n\n evictAll(sector: CacheSector): Promise<void>\n}\n\nexport abstract class AbstractCacheProvider<T> extends AbstractRemoteKeyValueStore<CacheEntry<T>> implements CacheProvider<T> {\n abstract type: CacheProviderType\n\n abstract evictAll(sector: CacheSector): Promise<void>\n}\n\nexport interface LocalCache<T> {\n name: CacheName\n\n getValue(key: ResourceKey, fetch: () => T): T\n\n getValues(keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Array<RecordEntry<T>>): Array<RecordEntry<T>>\n\n setValue(key: ResourceKey, value: T | undefined): void\n\n setValues(entries: Array<RecordEntry<T | undefined>>): void\n\n removeAll(sector: CacheSector): void\n}\n\nexport interface LocalCacheProvider<T> extends LocalKeyValueStore<CacheEntry<T>>, CacheProvider<T> {\n removeAll(sector: CacheSector): void\n}\n\nexport abstract class AbstractLocalCacheProvider<T> extends AbstractLocalKeyValueStore<CacheEntry<T>> implements LocalCacheProvider<T> {\n abstract type: CacheProviderType\n\n abstract removeAll(sector: CacheSector): void\n\n async evictAll(sector: CacheSector): Promise<void> {\n this.removeAll(sector)\n }\n}\n\nexport type CacheEntry<T> = {\n value: T\n liveTimestamp: InstantLiteral | null\n staleTimestamp: InstantLiteral | null\n}\n\nexport namespace CacheEntry {\n export const isActive = <T>(entry: CacheEntry<T>): boolean => {\n if (isDead(entry) || isStale(entry)) {\n return false\n }\n\n return true\n }\n\n export const isDead = <T>(entry: CacheEntry<T> | undefined): boolean => {\n if (isNil(entry)) {\n return true\n }\n\n if (isNil(entry.liveTimestamp)) {\n return false\n }\n\n return Instants.isBefore(entry.liveTimestamp, Instants.now())\n }\n\n export const isAlive = <T>(entry: CacheEntry<T> | undefined): boolean => !isDead(entry)\n\n export const isStale = <T>(entry: CacheEntry<T>): boolean => {\n if (isNil(entry.staleTimestamp)) {\n return false\n }\n\n return Instants.isBefore(entry.staleTimestamp, Instants.now())\n }\n\n export const of = <T>(value: T) => {\n const entry: CacheEntry<T> = {\n value,\n liveTimestamp: null,\n staleTimestamp: null,\n }\n\n return entry\n }\n\n // JOHN do we want to enforce some kind of minimum liveness threshold?\n export const applyProps = <T>(originalEntry: CacheEntry<T>, props: CacheProps): CacheEntry<T> => {\n let liveTimestamp: InstantLiteral | null = originalEntry.liveTimestamp\n if (!isNil(props.timeToLive)) {\n const limit = Instants.add(Instants.now(), props.timeToLive)\n if (Instants.isBefore(limit, liveTimestamp ?? limit)) {\n liveTimestamp = Instants.toLiteral(limit)\n }\n }\n\n let staleTimestamp: InstantLiteral | null = originalEntry.staleTimestamp\n if (!isNil(props.timeToStale)) {\n const limit = Instants.add(Instants.now(), props.timeToStale)\n if (Instants.isBefore(limit, staleTimestamp ?? limit)) {\n staleTimestamp = Instants.toLiteral(limit)\n }\n }\n\n const limitedEntry: CacheEntry<T> = {\n value: originalEntry.value,\n liveTimestamp,\n staleTimestamp,\n }\n\n return limitedEntry\n }\n}\n\nexport type CacheConfigurationOptions = CacheConfigurationSection & {\n local: CacheConfigurationSection\n}\n\nexport type CacheConfigurationSection = {\n defaults: CacheDefinition\n\n /**\n * These options map from cache name key to configuration. They are a way for the tenant to override the configurations\n * for specific caches from the cache configuration here.\n */\n caches?: Record<string, Partial<CacheDefinition>>\n}\n\nexport type CacheDefinition = {\n options?: CacheOptions\n providers: Array<CacheProviderConfiguration>\n}\n\nexport type CacheProviderType = TaggedType<string, 'CacheProviderType'>\nexport type CacheProviderConfiguration = CacheOptions & {\n type: CacheProviderType\n}\n\nexport type CacheConfiguration = CacheConfigurationSection & {\n local: CacheConfigurationSection\n}\n\nexport type CacheProviderRegistry<ContextType extends AbstractApplicationContext> = {\n type: CacheProviderType\n construct: <T>(props: CacheProps, context: ContextType) => CacheProvider<T>\n}\n"],"mappings":";AAAA,SAAS,4BAA4B,mCAA4E;AACjH,SAAmB,QAAQ,e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B,aAAa,aAAI,GAAG,MAAM,WAAW;AAC5D,UAAa,kBAAS,OAAO,kBAAkB,KAAK,GAAG;AACrD,yBAA0B,mBAAU,KAAK;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,eAA8B;AAAA,MAClC,OAAO,cAAc;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,GAlEe;","names":["CacheProps","CacheSector","namespace","CacheEntry"]}
|
package/dist/comparator.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// src/comparator.ts
|
2
2
|
import { isString } from "@bessemer/cornerstone/string";
|
3
3
|
import { isNumber } from "@bessemer/cornerstone/math";
|
4
|
-
import { isDate } from "@bessemer/cornerstone/date";
|
4
|
+
import { isDate } from "@bessemer/cornerstone/temporal/date";
|
5
5
|
import { isBoolean } from "@bessemer/cornerstone/object";
|
6
6
|
var aggregate = (comparators) => {
|
7
7
|
return (first, second) => {
|
package/dist/comparator.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { BasicType } from '@bessemer/cornerstone/types'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isDate } from '@bessemer/cornerstone/date'\nimport { isBoolean } from '@bessemer/cornerstone/object'\n\nexport type Comparator<T> = (first: T, second: T) => number\n\nexport const aggregate = <T>(comparators: Array<Comparator<T>>): Comparator<T> => {\n return (first, second) => {\n if (first === second) {\n return 0\n }\n\n for (const comparator of comparators) {\n const result = comparator(first, second)\n if (result !== 0) {\n return result\n }\n }\n\n return 0\n }\n}\n\nexport const compareBy = <T, N>(mapper: (element: T) => N, comparator: Comparator<N>): Comparator<T> => {\n return (first, second) => comparator(mapper(first), mapper(second))\n}\n\nexport const reverse = <T>(comparator: Comparator<T>): Comparator<T> => {\n return (first, second) => -comparator(first, second)\n}\n\nexport const trueFirst = (): Comparator<boolean> => {\n return (first, second) => natural()(first ? 1 : 0, second ? 1 : 0)\n}\n\nexport const natural = (): Comparator<BasicType | null> => {\n // Comparing by nulls first allows us to assume the elements are non-null for future comparisons\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (isString(first) && isString(second)) {\n return first.localeCompare(second)\n } else if (isNumber(first) && isNumber(second)) {\n return first! - second!\n } else if (isDate(first) && isDate(second)) {\n return first.getTime() - second.getTime()\n } else if (isBoolean(first) && isBoolean(second)) {\n if (first !== second) {\n return second ? 1 : 0\n } else {\n return 0\n }\n }\n\n throw new Error(`Illegal natural comparison on values: [${first}, ${second}]`)\n },\n ])\n}\n\nexport function matchedFirst<T>(target: T): Comparator<T | null> {\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (first === target && second !== target) {\n return -1\n } else if (first !== target && second === target) {\n return 1\n } else {\n return 0\n }\n },\n ])\n}\n\nexport const nullsLast = <T>(): Comparator<T> => {\n return (first, second) => {\n if (first === null) {\n return 1\n }\n if (second === null) {\n return -1\n }\n\n return 0\n }\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAInB,IAAM,YAAY,CAAI,gBAAqD;AAChF,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,QAAQ;AACpB,aAAO;AAAA,IACT;AAEA,eAAW,cAAc,aAAa;AACpC,YAAM,SAAS,WAAW,OAAO,MAAM;AACvC,UAAI,WAAW,GAAG;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,IAAM,YAAY,CAAO,QAA2B,eAA6C;AACtG,SAAO,CAAC,OAAO,WAAW,WAAW,OAAO,KAAK,GAAG,OAAO,MAAM,CAAC;AACpE;AAEO,IAAM,UAAU,CAAI,eAA6C;AACtE,SAAO,CAAC,OAAO,WAAW,CAAC,WAAW,OAAO,MAAM;AACrD;AAEO,IAAM,YAAY,MAA2B;AAClD,SAAO,CAAC,OAAO,WAAW,QAAQ,EAAE,QAAQ,IAAI,GAAG,SAAS,IAAI,CAAC;AACnE;AAEO,IAAM,UAAU,MAAoC;AAEzD,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,SAAS,KAAK,KAAK,SAAS,MAAM,GAAG;AACvC,eAAO,MAAM,cAAc,MAAM;AAAA,MACnC,WAAW,SAAS,KAAK,KAAK,SAAS,MAAM,GAAG;AAC9C,eAAO,QAAS;AAAA,MAClB,WAAW,OAAO,KAAK,KAAK,OAAO,MAAM,GAAG;AAC1C,eAAO,MAAM,QAAQ,IAAI,OAAO,QAAQ;AAAA,MAC1C,WAAW,UAAU,KAAK,KAAK,UAAU,MAAM,GAAG;AAChD,YAAI,UAAU,QAAQ;AACpB,iBAAO,SAAS,IAAI;AAAA,QACtB,OAAO;AACL,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,YAAM,IAAI,MAAM,0CAA0C,KAAK,KAAK,MAAM,GAAG;AAAA,IAC/E;AAAA,EACF,CAAC;AACH;AAEO,SAAS,aAAgB,QAAiC;AAC/D,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,UAAU,UAAU,WAAW,QAAQ;AACzC,eAAO;AAAA,MACT,WAAW,UAAU,UAAU,WAAW,QAAQ;AAChD,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,YAAY,MAAwB;AAC/C,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,QAAI,WAAW,MAAM;AACnB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
1
|
+
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { BasicType } from '@bessemer/cornerstone/types'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isDate } from '@bessemer/cornerstone/temporal/date'\nimport { isBoolean } from '@bessemer/cornerstone/object'\n\nexport type Comparator<T> = (first: T, second: T) => number\n\nexport const aggregate = <T>(comparators: Array<Comparator<T>>): Comparator<T> => {\n return (first, second) => {\n if (first === second) {\n return 0\n }\n\n for (const comparator of comparators) {\n const result = comparator(first, second)\n if (result !== 0) {\n return result\n }\n }\n\n return 0\n }\n}\n\nexport const compareBy = <T, N>(mapper: (element: T) => N, comparator: Comparator<N>): Comparator<T> => {\n return (first, second) => comparator(mapper(first), mapper(second))\n}\n\nexport const reverse = <T>(comparator: Comparator<T>): Comparator<T> => {\n return (first, second) => -comparator(first, second)\n}\n\nexport const trueFirst = (): Comparator<boolean> => {\n return (first, second) => natural()(first ? 1 : 0, second ? 1 : 0)\n}\n\nexport const natural = (): Comparator<BasicType | null> => {\n // Comparing by nulls first allows us to assume the elements are non-null for future comparisons\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (isString(first) && isString(second)) {\n return first.localeCompare(second)\n } else if (isNumber(first) && isNumber(second)) {\n return first! - second!\n } else if (isDate(first) && isDate(second)) {\n return first.getTime() - second.getTime()\n } else if (isBoolean(first) && isBoolean(second)) {\n if (first !== second) {\n return second ? 1 : 0\n } else {\n return 0\n }\n }\n\n throw new Error(`Illegal natural comparison on values: [${first}, ${second}]`)\n },\n ])\n}\n\nexport function matchedFirst<T>(target: T): Comparator<T | null> {\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (first === target && second !== target) {\n return -1\n } else if (first !== target && second === target) {\n return 1\n } else {\n return 0\n }\n },\n ])\n}\n\nexport const nullsLast = <T>(): Comparator<T> => {\n return (first, second) => {\n if (first === null) {\n return 1\n }\n if (second === null) {\n return -1\n }\n\n return 0\n }\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAInB,IAAM,YAAY,CAAI,gBAAqD;AAChF,SAAO,CAAC,OAAO,WAA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Q;AACzC,eAAO;AAAA,MACT,WAAW,UAAU,UAAU,WAAW,QAAQ;AAChD,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,YAAY,MAAwB;AAC/C,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,QAAI,WAAW,MAAM;AACnB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/content.d.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference';
|
2
|
-
import {
|
2
|
+
import { TaggedType } from '@bessemer/cornerstone/types';
|
3
3
|
import { AbstractApplicationContext } from '@bessemer/cornerstone/context';
|
4
4
|
import { RichTextJson } from '@bessemer/cornerstone/rich-text';
|
5
5
|
import { Tag } from '@bessemer/cornerstone/tag';
|
6
6
|
import Zod, { ZodType } from 'zod';
|
7
|
-
export type ContentSector =
|
7
|
+
export type ContentSector = TaggedType<string, 'ContentSector'>;
|
8
8
|
export declare const ContentSectorSchema: ZodType<ContentSector>;
|
9
|
-
export type ContentKey =
|
9
|
+
export type ContentKey = TaggedType<string, 'ContentKey'>;
|
10
10
|
export declare const ContentKeySchema: ZodType<ContentKey>;
|
11
|
-
export type ContentType<Data = unknown> =
|
11
|
+
export type ContentType<Data = unknown> = TaggedType<string, ['ContentType', Data]>;
|
12
12
|
export declare const ContentTypeSchema: ZodType<ContentType>;
|
13
13
|
export type ContentReference = Reference<'Content'>;
|
14
14
|
type ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never;
|
@@ -25,7 +25,7 @@ export type ContentData<Type extends ContentType = ContentType, Data = ContentDa
|
|
25
25
|
sector: ContentSector | null;
|
26
26
|
};
|
27
27
|
export type ContentTypeConstructor<Content extends ContentData> = Content['type'];
|
28
|
-
export type ContentDisplayType =
|
28
|
+
export type ContentDisplayType = TaggedType<string, 'ContentDisplayType'>;
|
29
29
|
export declare namespace ContentDisplayTypes {
|
30
30
|
const Default: ContentDisplayType;
|
31
31
|
const Label: ContentDisplayType;
|
package/dist/content.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACxF,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AAC/C,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAC/D,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,aAAa,CAAgB,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AACzD,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,UAAU,CAAgB,CAAA;AAEjE,MAAM,MAAM,WAAW,CAAC,IAAI,GAAG,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAA;AACnF,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,WAAW,CAAgB,CAAA;AAEnE,MAAM,MAAM,gBAAgB,GAAG,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AG,eAAe,CAAC,IAAI,CAAC,EAC7F,KAAK,UAAU,EACf,MAAM,IAAI,EACV,MAAM,IAAI,EACV,UAAU;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,KACtD,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAS9B,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,kBAAkB,SAAS,0BAA0B,EAClF,SAAS,KAAK,CAAC,iBAAiB,CAAC,EACjC,cAAc,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,KACzD,eAAe,CAAC,kBAAkB,CA2BpC,CAAA"}
|
package/dist/content.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/content.ts"],"sourcesContent":["import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference'\nimport {
|
1
|
+
{"version":3,"sources":["../src/content.ts"],"sourcesContent":["import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport { AbstractApplicationContext } from '@bessemer/cornerstone/context'\nimport { Arrays, Objects, References, Tags, Ulids } from '@bessemer/cornerstone'\nimport { RichTextJson } from '@bessemer/cornerstone/rich-text'\nimport { Tag } from '@bessemer/cornerstone/tag'\nimport Zod, { ZodType } from 'zod'\n\nexport type ContentSector = TaggedType<string, 'ContentSector'>\nexport const ContentSectorSchema: ZodType<ContentSector> = Zod.string()\n\nexport type ContentKey = TaggedType<string, 'ContentKey'>\nexport const ContentKeySchema: ZodType<ContentKey> = Zod.string()\n\nexport type ContentType<Data = unknown> = TaggedType<string, ['ContentType', Data]>\nexport const ContentTypeSchema: ZodType<ContentType> = Zod.string()\n\nexport type ContentReference = Reference<'Content'>\n\ntype ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never\n\nexport const ContentDataSchema = Zod.object({\n key: ContentKeySchema,\n type: ContentTypeSchema,\n data: Zod.unknown(),\n sector: ContentSectorSchema.nullable(),\n})\n\nexport type ContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = Referencable<ContentReference> & {\n key: ContentKey\n type: Type\n data: Data\n sector: ContentSector | null\n}\n\nexport type ContentTypeConstructor<Content extends ContentData> = Content['type']\n\nexport type ContentDisplayType = TaggedType<string, 'ContentDisplayType'>\n\nexport namespace ContentDisplayTypes {\n export const Default: ContentDisplayType = 'Default'\n export const Label: ContentDisplayType = 'Label'\n export const Desktop: ContentDisplayType = 'Desktop'\n export const Mobile: ContentDisplayType = 'Mobile'\n export const Modal: ContentDisplayType = 'Modal'\n export const Tooltip: ContentDisplayType = 'Tooltip'\n}\n\nexport const TextContentType: ContentType<RichTextJson> = 'Text'\nexport type TextContent = ContentData<typeof TextContentType>\n\nexport interface ContentProvider<ContextType extends AbstractApplicationContext = AbstractApplicationContext> {\n fetchContentByIds: (references: Array<ReferenceType<ContentReference>>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentByKeys: (keys: Array<ContentKey>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentBySectors: (sectors: Array<ContentSector>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n}\n\nexport type ContentNormalizer<\n ApplicationContext extends AbstractApplicationContext = AbstractApplicationContext,\n Type extends ContentData = ContentData\n> = {\n type: Type['type']\n normalize: (data: Array<ContentData>, context: ApplicationContext) => Promise<Array<Type>>\n}\n\n// TODO might be more efficient to put the normalizers in a map at some point\nexport const normalizeContent = async <ApplicationContext extends AbstractApplicationContext>(\n content: Array<ContentData>,\n normalizers: Array<ContentNormalizer<ApplicationContext>>,\n context: ApplicationContext\n): Promise<Array<ContentData>> => {\n const groupedContent = Arrays.groupBy(content, (it) => it.type)\n const normalizedGroupedContent = Object.entries(groupedContent).map(async ([type, values]) => {\n const normalizer = normalizers.find((it) => it.type === type)\n if (Objects.isNil(normalizer)) {\n return values\n }\n\n return await normalizer.normalize(values, context)\n })\n\n const normalizedContent = (await Promise.all(normalizedGroupedContent)).flatMap((it) => it)\n return normalizedContent\n}\n\nexport type StaticContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = ContentData<Type, Data> & {\n tags: Array<Tag>\n}\n\nexport const staticData = <Type extends ContentType = ContentType, Data = ContentDataType<Type>>(\n key: ContentKey,\n type: Type,\n data: Data,\n options?: { tags?: Array<Tag>; sector?: ContentSector }\n): StaticContentData<Type, Data> => {\n return {\n reference: References.reference(Ulids.generate() as string, 'Content'),\n key,\n type,\n data,\n tags: options?.tags ?? [],\n sector: options?.sector ?? null,\n }\n}\n\nexport const staticProvider = <ApplicationContext extends AbstractApplicationContext>(\n content: Array<StaticContentData>,\n normalizers?: Array<ContentNormalizer<ApplicationContext>>\n): ContentProvider<ApplicationContext> => {\n return {\n async fetchContentByIds(references: Array<ReferenceType<ContentReference>>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(references, it.reference))\n return normalizeContent(matchingContent, normalizers ?? [], context)\n },\n async fetchContentByKeys(keys: Array<ContentKey>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(keys, it.key))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [], context)\n },\n async fetchContentBySectors(sectors: Array<ContentSector>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Objects.isPresent(it.sector)).filter((it) => Arrays.contains(sectors, it.sector!))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [],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ContentDisplayTypes","resolvedContent","it"]}
|
package/dist/data-size.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { NominalType } from '@bessemer/cornerstone/types';
|
2
2
|
import Zod from 'zod';
|
3
|
-
export type DataSize =
|
3
|
+
export type DataSize = NominalType<number, 'DataSize'>;
|
4
4
|
export declare const fromBytes: (value: number) => DataSize;
|
5
5
|
export declare const Schema: Zod.ZodPipe<Zod.ZodNumber, Zod.ZodTransform<DataSize, number>>;
|
6
6
|
export declare const toBytes: (byte: DataSize) => number;
|
package/dist/data-size.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-size.d.ts","sourceRoot":"","sources":["../src/data-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"data-size.d.ts","sourceRoot":"","sources":["../src/data-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAEtD,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,QAEzC,CAAA;AAED,eAAO,MAAM,MAAM,gEAAoC,CAAA;AAEvD,eAAO,MAAM,OAAO,GAAI,MAAM,QAAQ,KAAG,MAExC,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAE7C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,KAAG,MAE5C,CAAA"}
|
package/dist/data-size.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/data-size.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/data-size.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\n\nexport type DataSize = NominalType<number, 'DataSize'>\n\nexport const fromBytes = (value: number): DataSize => {\n return value as DataSize\n}\n\nexport const Schema = Zod.number().transform(fromBytes)\n\nexport const toBytes = (byte: DataSize): number => {\n return byte\n}\n\n// === SI (Decimal) Units ===\nexport const fromKilobytes = (value: number): DataSize => {\n return fromBytes(value * 1000)\n}\n\nexport const toKilobytes = (byte: DataSize): number => {\n return toBytes(byte) / 1000\n}\n\nexport const fromMegabytes = (value: number): DataSize => {\n return fromKilobytes(value * 1000)\n}\n\nexport const toMegabytes = (byte: DataSize): number => {\n return toKilobytes(byte) / 1000\n}\n\nexport const fromGigabytes = (value: number): DataSize => {\n return fromMegabytes(value * 1000)\n}\n\nexport const toGigabytes = (byte: DataSize): number => {\n return toMegabytes(byte) / 1000\n}\n\n// === IEC (Binary) Units ===\nexport const fromKibibytes = (value: number): DataSize => {\n return fromBytes(value * 1024)\n}\n\nexport const toKibibytes = (byte: DataSize): number => {\n return toBytes(byte) / 1024\n}\n\nexport const fromMebibytes = (value: number): DataSize => {\n return fromKibibytes(value * 1024)\n}\n\nexport const toMebibytes = (byte: DataSize): number => {\n return toKibibytes(byte) / 1024\n}\n\nexport const fromGibibytes = (value: number): DataSize => {\n return fromMebibytes(value * 1024)\n}\n\nexport const toGibibytes = (byte: DataSize): number => {\n return toMebibytes(byte) / 1024\n}\n"],"mappings":";AACA,OAAO,SAAS;AAIT,IAAM,YAAY,CAAC,UAA4B;AACpD,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,OAAO,EAAE,UAAU,SAAS;AAE/C,IAAM,UAAU,CAAC,SAA2B;AACjD,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,UAAU,QAAQ,GAAI;AAC/B;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,QAAQ,IAAI,IAAI;AACzB;AAEO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,cAAc,QAAQ,GAAI;AACnC;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,YAAY,IAAI,IAAI;AAC7B;AAEO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,cAAc,QAAQ,GAAI;AACnC;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,YAAY,IAAI,IAAI;AAC7B;AAGO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,UAAU,QAAQ,IAAI;AAC/B;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,QAAQ,IAAI,IAAI;AACzB;AAEO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,cAAc,QAAQ,IAAI;AACnC;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,YAAY,IAAI,IAAI;AAC7B;AAEO,IAAM,gBAAgB,CAAC,UAA4B;AACxD,SAAO,cAAc,QAAQ,IAAI;AACnC;AAEO,IAAM,cAAc,CAAC,SAA2B;AACrD,SAAO,YAAY,IAAI,IAAI;AAC7B;","names":[]}
|
@@ -1,25 +1,51 @@
|
|
1
|
-
import { Dictionary,
|
1
|
+
import { Dictionary, Throwable } from '@bessemer/cornerstone/types';
|
2
2
|
import { RecordAttribute } from '@bessemer/cornerstone/object';
|
3
3
|
import Zod, { ZodType } from 'zod';
|
4
4
|
import { LazyValue } from '@bessemer/cornerstone/lazy';
|
5
|
-
|
6
|
-
|
5
|
+
import { NamespacedKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key';
|
6
|
+
import { ErrorType } from '@bessemer/cornerstone/error/error-type';
|
7
|
+
import { Result } from '@bessemer/cornerstone/result';
|
8
|
+
export type ErrorCode = NamespacedKey<ErrorType>;
|
9
|
+
export declare const ErrorCodeSchema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<NamespacedKey<ErrorType>, string>>;
|
10
|
+
export declare const splitErrorCode: (code: ErrorCode) => [ErrorType, ResourceNamespace];
|
11
|
+
export declare const getErrorCodeType: (code: ErrorCode) => ErrorType;
|
12
|
+
export type ErrorCodeBuilder = {
|
13
|
+
code: ErrorCode;
|
14
|
+
} | {
|
15
|
+
type: ErrorType;
|
16
|
+
namespace?: ResourceNamespace;
|
17
|
+
};
|
18
|
+
export declare const buildErrorCode: (builder: ErrorCodeBuilder) => ErrorCode;
|
7
19
|
export type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>;
|
8
20
|
export declare const ErrorAttributeSchema: ZodType<ErrorAttribute, string>;
|
9
|
-
declare const
|
10
|
-
code: Zod.
|
21
|
+
export declare const ErrorEventCauseSchema: Zod.ZodObject<{
|
22
|
+
code: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<NamespacedKey<ErrorType>, string>>;
|
23
|
+
message: Zod.ZodString;
|
24
|
+
attributes: Zod.ZodRecord<Zod.ZodString, Zod.ZodUnknown>;
|
25
|
+
}, Zod.core.$strip>;
|
26
|
+
export type ErrorEventCause = Zod.infer<typeof ErrorEventCauseSchema>;
|
27
|
+
export declare const Schema: Zod.ZodObject<{
|
11
28
|
message: Zod.ZodString;
|
29
|
+
causes: Zod.ZodArray<Zod.ZodObject<{
|
30
|
+
code: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<NamespacedKey<ErrorType>, string>>;
|
31
|
+
message: Zod.ZodString;
|
32
|
+
attributes: Zod.ZodRecord<Zod.ZodString, Zod.ZodUnknown>;
|
33
|
+
}, Zod.core.$strip>>;
|
12
34
|
attributes: Zod.ZodRecord<Zod.ZodType<ErrorAttribute<unknown>, string, Zod.core.$ZodTypeInternals<ErrorAttribute<unknown>, string>>, Zod.ZodUnknown>;
|
13
35
|
}, Zod.core.$strip>;
|
14
|
-
export type ErrorEvent = Zod.infer<typeof
|
15
|
-
|
36
|
+
export type ErrorEvent = Zod.infer<typeof Schema>;
|
37
|
+
export type ErrorEventCauseBuilder = ErrorCodeBuilder & {
|
38
|
+
message: string;
|
39
|
+
attributes?: Dictionary<unknown>;
|
16
40
|
};
|
17
41
|
export type ErrorEventBuilder = {
|
18
|
-
code: ErrorCode;
|
19
|
-
message?: string | null;
|
20
42
|
attributes?: Record<ErrorAttribute, unknown>;
|
21
|
-
|
22
|
-
|
43
|
+
} & ({
|
44
|
+
causes: Array<ErrorEventCauseBuilder>;
|
45
|
+
message: string;
|
46
|
+
} | (ErrorCodeBuilder & {
|
47
|
+
message: string;
|
48
|
+
}));
|
23
49
|
export type ErrorEventAugment = Partial<ErrorEventBuilder>;
|
24
50
|
export declare class ErrorEventException extends Error {
|
25
51
|
readonly errorEvent: ErrorEvent;
|
@@ -32,25 +58,18 @@ export declare const from: (throwable: Throwable) => ErrorEvent;
|
|
32
58
|
export declare function withPropagation<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType;
|
33
59
|
export declare function withPropagation<ReturnType>(runnable: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>;
|
34
60
|
export declare const propagate: (throwable: Throwable, attributes: Dictionary<unknown>) => never;
|
35
|
-
export declare const
|
36
|
-
export declare const findInCausalChain: (error: ErrorEvent, predicate: (error: ErrorEvent) => boolean) => ErrorEvent | undefined;
|
37
|
-
export declare const aggregate: (builder: ErrorEventBuilder, causes: Array<ErrorEvent>) => ErrorEvent | undefined;
|
38
|
-
export declare const UnhandledErrorCode: ErrorCode;
|
39
|
-
export declare const NotFoundErrorCode: ErrorCode;
|
40
|
-
export declare const ForbiddenErrorCode: ErrorCode;
|
41
|
-
export declare const UnauthorizedErrorCode: ErrorCode;
|
42
|
-
export declare const BadRequestErrorCode: ErrorCode;
|
61
|
+
export declare const ValueAttribute: ErrorAttribute;
|
43
62
|
export declare const RequestCorrelationIdAttribute: ErrorAttribute<string>;
|
44
63
|
export declare const HttpStatusCodeAttribute: ErrorAttribute<number>;
|
45
64
|
export declare const unhandled: (builder?: ErrorEventAugment) => ErrorEvent;
|
46
|
-
export declare const
|
65
|
+
export declare const required: (builder?: ErrorEventAugment) => ErrorEvent;
|
47
66
|
export declare const unauthorized: (builder?: ErrorEventAugment) => ErrorEvent;
|
48
67
|
export declare const forbidden: (builder?: ErrorEventAugment) => ErrorEvent;
|
49
|
-
export declare const
|
68
|
+
export declare const invalidValue: (value: unknown, builder?: ErrorEventAugment) => ErrorEvent;
|
50
69
|
export declare function assertPresent<T>(value: T, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is NonNullable<T>;
|
51
70
|
export declare function assertAuthorized(value: boolean, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
52
71
|
export declare function assertPermitted(value: boolean, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
53
|
-
export declare function assertValid(
|
72
|
+
export declare function assertValid(valid: boolean, value: unknown, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
54
73
|
export declare function assert(value: boolean, builder: LazyValue<ErrorEventBuilder>): asserts value is true;
|
55
|
-
export
|
74
|
+
export declare const unpackResult: <T>(result: Result<T, ErrorEvent>) => T;
|
56
75
|
//# sourceMappingURL=error-event.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
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