@bessemer/cornerstone 0.5.0 → 0.5.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/array.d.ts +57 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js +137 -0
- package/dist/array.js.map +1 -0
- package/dist/async.d.ts +59 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +62 -0
- package/dist/async.js.map +1 -0
- package/dist/cache.d.ts +106 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +112 -0
- package/dist/cache.js.map +1 -0
- package/dist/combinable.d.ts +16 -0
- package/dist/combinable.d.ts.map +1 -0
- package/dist/combinable.js +31 -0
- package/dist/combinable.js.map +1 -0
- package/dist/comparator.d.ts +9 -0
- package/dist/comparator.d.ts.map +1 -0
- package/dist/comparator.js +76 -0
- package/dist/comparator.js.map +1 -0
- package/dist/content.d.ts +68 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +79 -0
- package/dist/content.js.map +1 -0
- package/dist/context.d.ts +7 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +15 -0
- package/dist/crypto.js.map +1 -0
- package/dist/date.d.ts +10 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +24 -0
- package/dist/date.js.map +1 -0
- package/dist/duration.d.ts +39 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +52 -0
- package/dist/duration.js.map +1 -0
- package/dist/either.d.ts +20 -0
- package/dist/either.d.ts.map +1 -0
- package/dist/either.js +25 -0
- package/dist/either.js.map +1 -0
- package/dist/entry.d.ts +7 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +24 -0
- package/dist/entry.js.map +1 -0
- package/dist/equalitor.d.ts +5 -0
- package/dist/equalitor.d.ts.map +1 -0
- package/dist/equalitor.js +10 -0
- package/dist/equalitor.js.map +1 -0
- package/dist/error-event.d.ts +34 -0
- package/dist/error-event.d.ts.map +1 -0
- package/dist/error-event.js +91 -0
- package/dist/error-event.js.map +1 -0
- package/dist/error.d.ts +3 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +18 -0
- package/dist/error.js.map +1 -0
- package/dist/expression/array-expression.d.ts +14 -0
- package/dist/expression/array-expression.d.ts.map +1 -0
- package/dist/expression/array-expression.js +32 -0
- package/dist/expression/array-expression.js.map +1 -0
- package/dist/expression/expression-evaluator.d.ts +8 -0
- package/dist/expression/expression-evaluator.d.ts.map +1 -0
- package/dist/expression/expression-evaluator.js +31 -0
- package/dist/expression/expression-evaluator.js.map +1 -0
- package/dist/expression/expression.d.ts +54 -0
- package/dist/expression/expression.d.ts.map +1 -0
- package/dist/expression/expression.js +173 -0
- package/dist/expression/expression.js.map +1 -0
- package/dist/expression/internal.d.ts +10 -0
- package/dist/expression/internal.d.ts.map +1 -0
- package/dist/expression/internal.js +28 -0
- package/dist/expression/internal.js.map +1 -0
- package/dist/expression/numeric-expression.d.ts +79 -0
- package/dist/expression/numeric-expression.d.ts.map +1 -0
- package/dist/expression/numeric-expression.js +177 -0
- package/dist/expression/numeric-expression.js.map +1 -0
- package/dist/expression/string-expression.d.ts +24 -0
- package/dist/expression/string-expression.d.ts.map +1 -0
- package/dist/expression/string-expression.js +41 -0
- package/dist/expression/string-expression.js.map +1 -0
- package/dist/expression.d.ts +35 -0
- package/dist/expression.d.ts.map +1 -0
- package/dist/expression.js +12 -0
- package/dist/expression.js.map +1 -0
- package/dist/function.d.ts +2 -0
- package/dist/function.d.ts.map +1 -0
- package/dist/function.js +7 -0
- package/dist/function.js.map +1 -0
- package/dist/glob.d.ts +8 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +20 -0
- package/dist/glob.js.map +1 -0
- package/dist/global-variable.d.ts +7 -0
- package/dist/global-variable.d.ts.map +1 -0
- package/dist/global-variable.js +34 -0
- package/dist/global-variable.js.map +1 -0
- package/dist/hash.d.ts +11 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +30 -0
- package/dist/hash.js.map +1 -0
- package/dist/hex-code.d.ts +5 -0
- package/dist/hex-code.d.ts.map +1 -0
- package/dist/hex-code.js +7 -0
- package/dist/hex-code.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy.d.ts +3 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +13 -0
- package/dist/lazy.js.map +1 -0
- package/dist/logger.d.ts +30 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +124 -0
- package/dist/logger.js.map +1 -0
- package/dist/math.d.ts +22 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +123 -0
- package/dist/math.js.map +1 -0
- package/dist/misc.d.ts +3 -0
- package/dist/misc.d.ts.map +1 -0
- package/dist/misc.js +21 -0
- package/dist/misc.js.map +1 -0
- package/dist/object.d.ts +62 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +170 -0
- package/dist/object.js.map +1 -0
- package/dist/patch.d.ts +41 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +87 -0
- package/dist/patch.js.map +1 -0
- package/dist/precondition.d.ts +8 -0
- package/dist/precondition.d.ts.map +1 -0
- package/dist/precondition.js +27 -0
- package/dist/precondition.js.map +1 -0
- package/dist/promise.d.ts +8 -0
- package/dist/promise.d.ts.map +1 -0
- package/dist/promise.js +18 -0
- package/dist/promise.js.map +1 -0
- package/dist/property.d.ts +11 -0
- package/dist/property.d.ts.map +1 -0
- package/dist/property.js +21 -0
- package/dist/property.js.map +1 -0
- package/dist/reference.d.ts +22 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +51 -0
- package/dist/reference.js.map +1 -0
- package/dist/resource.d.ts +13 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +27 -0
- package/dist/resource.js.map +1 -0
- package/dist/result.d.ts +18 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +50 -0
- package/dist/result.js.map +1 -0
- package/dist/retry.d.ts +18 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +51 -0
- package/dist/retry.js.map +1 -0
- package/dist/rich-text.d.ts +17 -0
- package/dist/rich-text.d.ts.map +1 -0
- package/dist/rich-text.js +9 -0
- package/dist/rich-text.js.map +1 -0
- package/dist/set.d.ts +5 -0
- package/dist/set.d.ts.map +1 -0
- package/dist/set.js +44 -0
- package/dist/set.js.map +1 -0
- package/dist/signature.d.ts +9 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +20 -0
- package/dist/signature.js.map +1 -0
- package/dist/store.d.ts +40 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +50 -0
- package/dist/store.js.map +1 -0
- package/dist/string.d.ts +40 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +154 -0
- package/dist/string.js.map +1 -0
- package/dist/tag.d.ts +24 -0
- package/dist/tag.d.ts.map +1 -0
- package/dist/tag.js +50 -0
- package/dist/tag.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/ulid.d.ts +8 -0
- package/dist/ulid.d.ts.map +1 -0
- package/dist/ulid.js +28 -0
- package/dist/ulid.js.map +1 -0
- package/dist/unit.d.ts +4 -0
- package/dist/unit.d.ts.map +1 -0
- package/dist/unit.js +6 -0
- package/dist/unit.js.map +1 -0
- package/dist/uri.d.ts +47 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +211 -0
- package/dist/uri.js.map +1 -0
- package/dist/url.d.ts +25 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +120 -0
- package/dist/url.js.map +1 -0
- package/dist/uuid.d.ts +8 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +35 -0
- package/dist/uuid.js.map +1 -0
- package/dist/zod.d.ts +17 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +31 -0
- package/dist/zod.js.map +1 -0
- package/package.json +5 -2
- package/jest.config.js +0 -3
- package/src/array.ts +0 -142
- package/src/async.ts +0 -114
- package/src/cache.ts +0 -236
- package/src/combinable.ts +0 -40
- package/src/comparator.ts +0 -78
- package/src/content.ts +0 -138
- package/src/context.ts +0 -6
- package/src/crypto.ts +0 -11
- package/src/date.ts +0 -18
- package/src/duration.ts +0 -57
- package/src/either.ts +0 -29
- package/src/entry.ts +0 -21
- package/src/equalitor.ts +0 -12
- package/src/error-event.ts +0 -126
- package/src/error.ts +0 -16
- package/src/expression/array-expression.ts +0 -29
- package/src/expression/expression-evaluator.ts +0 -34
- package/src/expression/expression.ts +0 -188
- package/src/expression/internal.ts +0 -34
- package/src/expression/numeric-expression.ts +0 -182
- package/src/expression/string-expression.ts +0 -38
- package/src/expression.ts +0 -48
- package/src/function.ts +0 -3
- package/src/glob.ts +0 -19
- package/src/global-variable.ts +0 -40
- package/src/hash.ts +0 -28
- package/src/hex-code.ts +0 -6
- package/src/index.ts +0 -82
- package/src/lazy.ts +0 -11
- package/src/logger.ts +0 -144
- package/src/math.ts +0 -132
- package/src/misc.ts +0 -22
- package/src/object.ts +0 -236
- package/src/patch.ts +0 -128
- package/src/precondition.ts +0 -25
- package/src/promise.ts +0 -16
- package/src/property.ts +0 -29
- package/src/reference.ts +0 -68
- package/src/resource.ts +0 -32
- package/src/result.ts +0 -66
- package/src/retry.ts +0 -70
- package/src/rich-text.ts +0 -24
- package/src/set.ts +0 -46
- package/src/signature.ts +0 -20
- package/src/store.ts +0 -91
- package/src/string.ts +0 -173
- package/src/tag.ts +0 -68
- package/src/types.ts +0 -21
- package/src/ulid.ts +0 -28
- package/src/unit.ts +0 -4
- package/src/uri.ts +0 -321
- package/src/url.ts +0 -155
- package/src/uuid.ts +0 -37
- package/src/zod.ts +0 -24
- package/test/comparator.test.ts +0 -1
- package/test/expression.test.ts +0 -12
- package/test/object.test.ts +0 -104
- package/test/patch.test.ts +0 -170
- package/test/set.test.ts +0 -20
- package/test/string.test.ts +0 -22
- package/test/uri.test.ts +0 -111
- package/test/url.test.ts +0 -174
- package/tsconfig.build.json +0 -13
- package/tsup.config.ts +0 -4
package/dist/uuid.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
// src/uuid.ts
|
2
|
+
import { Objects, Preconditions, Strings } from "@bessemer/cornerstone";
|
3
|
+
var generate = () => {
|
4
|
+
if (Objects.isNil(crypto.randomUUID)) {
|
5
|
+
return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}`;
|
6
|
+
} else {
|
7
|
+
return crypto.randomUUID();
|
8
|
+
}
|
9
|
+
};
|
10
|
+
var asString = (value) => {
|
11
|
+
return value;
|
12
|
+
};
|
13
|
+
var generateString = () => {
|
14
|
+
return asString(generate());
|
15
|
+
};
|
16
|
+
var randomHex = (characters) => {
|
17
|
+
const randomNum = Math.floor(Math.random() * (16 ** characters - 1));
|
18
|
+
return Strings.padStart(randomNum.toString(16), characters, "0");
|
19
|
+
};
|
20
|
+
var of = (value) => {
|
21
|
+
Preconditions.isTrue(isValid(value), () => `Attempted to coerce invalid value to Uuid: ${value}`);
|
22
|
+
return value;
|
23
|
+
};
|
24
|
+
var pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
25
|
+
var isValid = (value) => {
|
26
|
+
return Strings.isString(value) && pattern.test(value);
|
27
|
+
};
|
28
|
+
export {
|
29
|
+
asString,
|
30
|
+
generate,
|
31
|
+
generateString,
|
32
|
+
isValid,
|
33
|
+
of
|
34
|
+
};
|
35
|
+
//# sourceMappingURL=uuid.js.map
|
package/dist/uuid.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/uuid.ts"],"sourcesContent":["import { Objects, Preconditions, Strings } from '@bessemer/cornerstone'\nimport { TaggedType } from '@bessemer/cornerstone/types'\n\nexport type Uuid = TaggedType<string, 'Uuid'>\n\nexport const generate = (): Uuid => {\n if (Objects.isNil(crypto.randomUUID)) {\n return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}` as Uuid\n } else {\n return crypto.randomUUID() as Uuid\n }\n}\n\nexport const asString = (value: Uuid): string => {\n return value\n}\n\nexport const generateString = (): string => {\n return asString(generate())\n}\n\nconst randomHex = (characters: number) => {\n // Generates a random number between 0x0..0 and 0xF..F for the target number of characters\n const randomNum = Math.floor(Math.random() * (16 ** characters - 1))\n return Strings.padStart(randomNum.toString(16), characters, '0')\n}\n\nexport const of = (value: string): Uuid => {\n Preconditions.isTrue(isValid(value), () => `Attempted to coerce invalid value to Uuid: ${value}`)\n return value as Uuid\n}\n\nconst pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i\n\nexport const isValid = (value: unknown): value is Uuid => {\n return Strings.isString(value) && pattern.test(value)\n}\n"],"mappings":";AAAA,SAAS,SAAS,eAAe,eAAe;AAKzC,IAAM,WAAW,MAAY;AAClC,MAAI,QAAQ,MAAM,OAAO,UAAU,GAAG;AACpC,WAAO,GAAG,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;AAAA,EACzF,OAAO;AACL,WAAO,OAAO,WAAW;AAAA,EAC3B;AACF;AAEO,IAAM,WAAW,CAAC,UAAwB;AAC/C,SAAO;AACT;AAEO,IAAM,iBAAiB,MAAc;AAC1C,SAAO,SAAS,SAAS,CAAC;AAC5B;AAEA,IAAM,YAAY,CAAC,eAAuB;AAExC,QAAM,YAAY,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,aAAa,EAAE;AACnE,SAAO,QAAQ,SAAS,UAAU,SAAS,EAAE,GAAG,YAAY,GAAG;AACjE;AAEO,IAAM,KAAK,CAAC,UAAwB;AACzC,gBAAc,OAAO,QAAQ,KAAK,GAAG,MAAM,8CAA8C,KAAK,EAAE;AAChG,SAAO;AACT;AAEA,IAAM,UAAU;AAET,IAAM,UAAU,CAAC,UAAkC;AACxD,SAAO,QAAQ,SAAS,KAAK,KAAK,QAAQ,KAAK,KAAK;AACtD;","names":[]}
|
package/dist/zod.d.ts
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import z, { ZodType } from 'zod';
|
2
|
+
import { ResourceKey } from '@bessemer/cornerstone/resource';
|
3
|
+
import { Entry } from '@bessemer/cornerstone/entry';
|
4
|
+
export type infer<T extends ZodType<any, any, any>> = z.infer<T>;
|
5
|
+
export declare const object: <T extends z.ZodRawShape>(shape: T, params?: z.RawCreateParams) => z.ZodObject<T, "strip", z.ZodTypeAny, z.objectOutputType<T, z.ZodTypeAny, "strip">, z.objectInputType<T, z.ZodTypeAny, "strip">>;
|
6
|
+
export declare const string: (params?: z.RawCreateParams & {
|
7
|
+
coerce?: true;
|
8
|
+
}) => z.ZodString;
|
9
|
+
export declare const union: <T extends readonly [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>(types: T, params?: z.RawCreateParams) => z.ZodUnion<T>;
|
10
|
+
export declare const array: <T extends z.ZodTypeAny>(schema: T, params?: z.RawCreateParams) => z.ZodArray<T>;
|
11
|
+
export declare const unknown: (params?: z.RawCreateParams) => z.ZodUnknown;
|
12
|
+
export declare const nullType: (params?: z.RawCreateParams) => z.ZodNull;
|
13
|
+
export declare const undefined: (params?: z.RawCreateParams) => z.ZodUndefined;
|
14
|
+
export declare const arrayable: <T>(type: ZodType<T>) => z.ZodUnion<[z.ZodType<T, z.ZodTypeDef, T>, z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">]>;
|
15
|
+
export declare const key: () => ZodType<ResourceKey>;
|
16
|
+
export declare const entry: <Value, Key = string>(value: ZodType<Value>, key?: ZodType<Key>) => ZodType<Entry<Value, Key>>;
|
17
|
+
//# sourceMappingURL=zod.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AAEnD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAChE,eAAO,MAAM,MAAM,qMAAW,CAAA;AAC9B,eAAO,MAAM,MAAM;UAkBk16C,CAAC;iBAlBx06C,CAAA;AAC9B,eAAO,MAAM,KAAK,6HAAU,CAAA;AAC5B,eAAO,MAAM,KAAK,kFAAU,CAAA;AAC5B,eAAO,MAAM,OAAO,8CAAY,CAAA;AAChC,eAAO,MAAM,QAAQ,2CAAS,CAAA;AAC9B,eAAO,MAAM,SAAS,gDAAc,CAAA;AAEpC,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,mGAE5C,CAAA;AAED,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,WAAW,CAEzC,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAE/G,CAAA"}
|
package/dist/zod.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
// src/zod.ts
|
2
|
+
import z from "zod";
|
3
|
+
var object = z.object;
|
4
|
+
var string = z.string;
|
5
|
+
var union = z.union;
|
6
|
+
var array = z.array;
|
7
|
+
var unknown = z.unknown;
|
8
|
+
var nullType = z.null;
|
9
|
+
var undefined = z.undefined;
|
10
|
+
var arrayable = (type) => {
|
11
|
+
return z.union([type, z.array(type)]);
|
12
|
+
};
|
13
|
+
var key = () => {
|
14
|
+
return z.string();
|
15
|
+
};
|
16
|
+
var entry = (value, key2) => {
|
17
|
+
return z.tuple([key2 ?? z.string(), value]);
|
18
|
+
};
|
19
|
+
export {
|
20
|
+
array,
|
21
|
+
arrayable,
|
22
|
+
entry,
|
23
|
+
key,
|
24
|
+
nullType,
|
25
|
+
object,
|
26
|
+
string,
|
27
|
+
undefined,
|
28
|
+
union,
|
29
|
+
unknown
|
30
|
+
};
|
31
|
+
//# sourceMappingURL=zod.js.map
|
package/dist/zod.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/zod.ts"],"sourcesContent":["import z, { ZodType } from 'zod'\nimport { ResourceKey } from '@bessemer/cornerstone/resource'\nimport { Entry } from '@bessemer/cornerstone/entry'\n\nexport type infer<T extends ZodType<any, any, any>> = z.infer<T>\nexport const object = z.object\nexport const string = z.string\nexport const union = z.union\nexport const array = z.array\nexport const unknown = z.unknown\nexport const nullType = z.null\nexport const undefined = z.undefined\n\nexport const arrayable = <T>(type: ZodType<T>) => {\n return z.union([type, z.array(type)])\n}\n\nexport const key = (): ZodType<ResourceKey> => {\n return z.string()\n}\n\nexport const entry = <Value, Key = string>(value: ZodType<Value>, key?: ZodType<Key>): ZodType<Entry<Value, Key>> => {\n return z.tuple([key ?? z.string(), value]) as ZodType<Entry<Value, Key>>\n}\n"],"mappings":";AAAA,OAAO,OAAoB;AAKpB,IAAM,SAAS,EAAE;AACjB,IAAM,SAAS,EAAE;AACjB,IAAM,QAAQ,EAAE;AAChB,IAAM,QAAQ,EAAE;AAChB,IAAM,UAAU,EAAE;AAClB,IAAM,WAAW,EAAE;AACnB,IAAM,YAAY,EAAE;AAEpB,IAAM,YAAY,CAAI,SAAqB;AAChD,SAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;AACtC;AAEO,IAAM,MAAM,MAA4B;AAC7C,SAAO,EAAE,OAAO;AAClB;AAEO,IAAM,QAAQ,CAAsB,OAAuBA,SAAmD;AACnH,SAAO,EAAE,MAAM,CAACA,QAAO,EAAE,OAAO,GAAG,KAAK,CAAC;AAC3C;","names":["key"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bessemer/cornerstone",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.5.
|
4
|
+
"version": "0.5.3",
|
5
5
|
"main": "./dist/index.cjs",
|
6
6
|
"module": "./dist/index.js",
|
7
7
|
"types": "./dist/index.d.ts",
|
@@ -35,5 +35,8 @@
|
|
35
35
|
"devDependencies": {
|
36
36
|
"@types/lodash-es": "4.17.12",
|
37
37
|
"pino-pretty": "13.0.0"
|
38
|
-
}
|
38
|
+
},
|
39
|
+
"files": [
|
40
|
+
"dist"
|
41
|
+
]
|
39
42
|
}
|
package/jest.config.js
DELETED
package/src/array.ts
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
concat,
|
3
|
-
differenceBy as _differenceBy,
|
4
|
-
differenceWith as _differenceWith,
|
5
|
-
first as _first,
|
6
|
-
flatten as _flatten,
|
7
|
-
groupBy as _groupBy,
|
8
|
-
isEmpty as _isEmpty,
|
9
|
-
last as _last,
|
10
|
-
range as _range,
|
11
|
-
remove as _remove,
|
12
|
-
uniqBy,
|
13
|
-
uniqWith,
|
14
|
-
} from 'lodash-es'
|
15
|
-
import { Equalitor } from '@bessemer/cornerstone/equalitor'
|
16
|
-
import { Signable } from '@bessemer/cornerstone/signature'
|
17
|
-
import { Comparators, Eithers, Preconditions, Signatures } from '@bessemer/cornerstone'
|
18
|
-
import { Either } from '@bessemer/cornerstone/either'
|
19
|
-
import { Comparator } from '@bessemer/cornerstone/comparator'
|
20
|
-
import { Arrayable } from 'type-fest'
|
21
|
-
|
22
|
-
export const equalWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean => {
|
23
|
-
if (first.length !== second.length) {
|
24
|
-
return false
|
25
|
-
}
|
26
|
-
|
27
|
-
return first.every((element, index) => equalitor(element, second[index]!))
|
28
|
-
}
|
29
|
-
|
30
|
-
export const equalBy = <T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean => {
|
31
|
-
return equalWith(first, second, (first, second) => Signatures.sign(mapper(first)) === Signatures.sign(mapper(second)))
|
32
|
-
}
|
33
|
-
|
34
|
-
export const equal = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => {
|
35
|
-
return equalBy(first, second, Signatures.sign)
|
36
|
-
}
|
37
|
-
|
38
|
-
export const differenceWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): Array<T> => {
|
39
|
-
return _differenceWith(first, second, equalitor)
|
40
|
-
}
|
41
|
-
|
42
|
-
export const differenceBy = <T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): Array<T> => {
|
43
|
-
return _differenceBy(first, second, (it) => Signatures.sign(mapper(it)))
|
44
|
-
}
|
45
|
-
|
46
|
-
export const difference = <T extends Signable>(first: Array<T>, second: Array<T>): Array<T> => {
|
47
|
-
return differenceBy(first, second, Signatures.sign)
|
48
|
-
}
|
49
|
-
|
50
|
-
export const removeWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): Array<T> => {
|
51
|
-
return differenceWith(array, [element], equalitor)
|
52
|
-
}
|
53
|
-
|
54
|
-
export const removeBy = <T>(array: Array<T>, element: T, mapper: (element: T) => Signable): Array<T> => {
|
55
|
-
return differenceBy(array, [element], mapper)
|
56
|
-
}
|
57
|
-
|
58
|
-
export const remove = <T extends Signable>(array: Array<T>, element: T): Array<T> => {
|
59
|
-
return difference(array, [element])
|
60
|
-
}
|
61
|
-
|
62
|
-
export const containsWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): boolean => {
|
63
|
-
return array.some((it) => equalitor(it, element))
|
64
|
-
}
|
65
|
-
|
66
|
-
export const containsBy = <T>(array: Array<T>, element: T, mapper: (element: T) => Signable): boolean => {
|
67
|
-
return containsWith(array, element, (first, second) => Signatures.sign(mapper(first)) === Signatures.sign(mapper(second)))
|
68
|
-
}
|
69
|
-
|
70
|
-
export const contains = <T extends Signable>(array: Array<T>, element: T): boolean => containsBy(array, element, Signatures.sign)
|
71
|
-
|
72
|
-
export const containsAllWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean =>
|
73
|
-
isEmpty(differenceWith(second, first, equalitor))
|
74
|
-
|
75
|
-
export const containsAllBy = <T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean =>
|
76
|
-
isEmpty(differenceBy(second, first, mapper))
|
77
|
-
|
78
|
-
export const containsAll = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => isEmpty(difference(second, first))
|
79
|
-
|
80
|
-
export const dedupeWith = <T>(array: Array<T>, equalitor: Equalitor<T>): Array<T> => {
|
81
|
-
return uniqWith(array, equalitor)
|
82
|
-
}
|
83
|
-
|
84
|
-
export const dedupeBy = <T>(array: Array<T>, mapper: (element: T) => Signable): Array<T> => {
|
85
|
-
return uniqBy(array, (it) => Signatures.sign(mapper(it)))
|
86
|
-
}
|
87
|
-
|
88
|
-
export const dedupe = <T extends Signable>(array: Array<T>): Array<T> => {
|
89
|
-
return dedupeBy(array, Signatures.sign)
|
90
|
-
}
|
91
|
-
|
92
|
-
export const sortWith = <T>(array: Array<T>, comparator: Comparator<T>): Array<T> => {
|
93
|
-
return [...array].sort(comparator)
|
94
|
-
}
|
95
|
-
|
96
|
-
export const sortBy = <T>(array: Array<T>, mapper: (element: T) => Signable): Array<T> => {
|
97
|
-
return sortWith(
|
98
|
-
array,
|
99
|
-
Comparators.compareBy((it) => Signatures.sign(mapper(it)), Comparators.natural())
|
100
|
-
)
|
101
|
-
}
|
102
|
-
|
103
|
-
export const sort = <T extends Signable>(array: Array<T>): Array<T> => sortBy(array, Signatures.sign)
|
104
|
-
|
105
|
-
export const concatenate = concat
|
106
|
-
|
107
|
-
export const first = _first
|
108
|
-
|
109
|
-
export const only = <T>(array: Array<T>): T => {
|
110
|
-
Preconditions.isTrue(array.length === 1)
|
111
|
-
return first(array)!
|
112
|
-
}
|
113
|
-
|
114
|
-
export const last = _last
|
115
|
-
|
116
|
-
export const isEmpty = _isEmpty
|
117
|
-
// TODO make a better range function
|
118
|
-
export const range = _range
|
119
|
-
// TODO should this live in collections?
|
120
|
-
export const groupBy = _groupBy
|
121
|
-
|
122
|
-
export const rest = <T>(array: Array<T>, elementsToSkip: number = 1): Array<T> => {
|
123
|
-
return array.slice(elementsToSkip)
|
124
|
-
}
|
125
|
-
|
126
|
-
export const clear = (array: Array<unknown>): void => {
|
127
|
-
_remove(array, () => true)
|
128
|
-
}
|
129
|
-
|
130
|
-
export const bisect = <T, L, R>(array: Array<T>, bisector: (element: T, index: number) => Either<L, R>): [Array<L>, Array<R>] => {
|
131
|
-
return Eithers.split(array.map(bisector))
|
132
|
-
}
|
133
|
-
|
134
|
-
export const toArray = <T>(array: Arrayable<T>): Array<T> => {
|
135
|
-
if (Array.isArray(array)) {
|
136
|
-
return array
|
137
|
-
}
|
138
|
-
|
139
|
-
return [array]
|
140
|
-
}
|
141
|
-
|
142
|
-
export const flatten = _flatten
|
package/src/async.ts
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
import { Duration } from '@bessemer/cornerstone/duration'
|
2
|
-
import { Durations, Objects } from '@bessemer/cornerstone'
|
3
|
-
|
4
|
-
export type PendingValue = {
|
5
|
-
isSuccess: false
|
6
|
-
isError: false
|
7
|
-
isLoading: false
|
8
|
-
isFetching: boolean
|
9
|
-
data: undefined
|
10
|
-
}
|
11
|
-
|
12
|
-
export type LoadingValue = {
|
13
|
-
isSuccess: false
|
14
|
-
isError: false
|
15
|
-
isLoading: true
|
16
|
-
isFetching: boolean
|
17
|
-
data: undefined
|
18
|
-
}
|
19
|
-
|
20
|
-
export type ErrorValue = {
|
21
|
-
isSuccess: false
|
22
|
-
isError: true
|
23
|
-
isLoading: false
|
24
|
-
isFetching: boolean
|
25
|
-
data: unknown
|
26
|
-
}
|
27
|
-
|
28
|
-
export type FetchingValueSuccess<T> = {
|
29
|
-
isSuccess: true
|
30
|
-
isError: false
|
31
|
-
isLoading: false
|
32
|
-
isFetching: true
|
33
|
-
data: T
|
34
|
-
}
|
35
|
-
|
36
|
-
export type FetchingValueError = {
|
37
|
-
isSuccess: false
|
38
|
-
isError: true
|
39
|
-
isLoading: false
|
40
|
-
isFetching: true
|
41
|
-
data: unknown
|
42
|
-
}
|
43
|
-
|
44
|
-
export type SettledValue<T> = {
|
45
|
-
isSuccess: true
|
46
|
-
isError: false
|
47
|
-
isLoading: false
|
48
|
-
isFetching: false
|
49
|
-
data: T
|
50
|
-
}
|
51
|
-
|
52
|
-
export type AsyncValue<T> = PendingValue | LoadingValue | ErrorValue | FetchingValueSuccess<T> | FetchingValueError | SettledValue<T>
|
53
|
-
|
54
|
-
export const isSettled = <T>(value: AsyncValue<T>): value is SettledValue<T> => {
|
55
|
-
return value.isSuccess && !value.isError && !value.isLoading && !value.isFetching
|
56
|
-
}
|
57
|
-
|
58
|
-
export const loading = (): LoadingValue => ({ isSuccess: false, isError: false, isLoading: true, isFetching: true, data: undefined })
|
59
|
-
|
60
|
-
export const fetching = <T>(data: T): FetchingValueSuccess<T> => ({
|
61
|
-
isSuccess: true,
|
62
|
-
isError: false,
|
63
|
-
isLoading: false,
|
64
|
-
isFetching: true,
|
65
|
-
data,
|
66
|
-
})
|
67
|
-
|
68
|
-
export const settled = <T>(data: T): SettledValue<T> => ({ isSuccess: true, isError: false, isLoading: false, isFetching: false, data })
|
69
|
-
|
70
|
-
export const error = (error: unknown): ErrorValue => ({ isSuccess: false, isError: true, isLoading: false, isFetching: false, data: error })
|
71
|
-
|
72
|
-
export const handle = <T, N>(
|
73
|
-
value: AsyncValue<T | null>,
|
74
|
-
handlers: { loading: () => N; error: (error: unknown) => N; absent: () => N; success: (data: T) => N }
|
75
|
-
): N => {
|
76
|
-
if (value.isLoading || (value.isError && value.isFetching)) {
|
77
|
-
return handlers.loading()
|
78
|
-
}
|
79
|
-
if (value.isError) {
|
80
|
-
return handlers.error(value.data)
|
81
|
-
}
|
82
|
-
if (Objects.isNil(value.data)) {
|
83
|
-
return handlers.absent()
|
84
|
-
}
|
85
|
-
|
86
|
-
return handlers.success(value.data)
|
87
|
-
}
|
88
|
-
|
89
|
-
export const map = <T, N>(value: AsyncValue<T>, mapper: (value: T) => N): AsyncValue<N> => {
|
90
|
-
if (!value.isSuccess) {
|
91
|
-
return value
|
92
|
-
}
|
93
|
-
|
94
|
-
return { ...value, data: mapper(value.data) }
|
95
|
-
}
|
96
|
-
|
97
|
-
export const execute = <T>(runnable: () => Promise<T>): Promise<T> => {
|
98
|
-
return new Promise(async (resolve, reject) => {
|
99
|
-
setTimeout(async () => {
|
100
|
-
try {
|
101
|
-
const value = await runnable()
|
102
|
-
resolve(value)
|
103
|
-
} catch (e) {
|
104
|
-
reject(e)
|
105
|
-
}
|
106
|
-
}, 0)
|
107
|
-
})
|
108
|
-
}
|
109
|
-
|
110
|
-
export const sleep = (duration: Duration): Promise<void> => {
|
111
|
-
return new Promise((resolve) => {
|
112
|
-
setTimeout(resolve, Durations.inMilliseconds(duration))
|
113
|
-
})
|
114
|
-
}
|
package/src/cache.ts
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
import { AbstractLocalKeyValueStore, AbstractRemoteKeyValueStore, LocalKeyValueStore, RemoteKeyValueStore } from '@bessemer/cornerstone/store'
|
2
|
-
import { Arrays, Dates, Durations, Objects, Strings, Zod } from '@bessemer/cornerstone'
|
3
|
-
import { Duration } from '@bessemer/cornerstone/duration'
|
4
|
-
import { ResourceKey, ResourceNamespace } from '@bessemer/cornerstone/resource'
|
5
|
-
import { AbstractApplicationContext } from '@bessemer/cornerstone/context'
|
6
|
-
import { NominalType } from '@bessemer/cornerstone/types'
|
7
|
-
import { Entry } from '@bessemer/cornerstone/entry'
|
8
|
-
import { GlobPattern } from '@bessemer/cornerstone/glob'
|
9
|
-
import { Arrayable } from 'type-fest'
|
10
|
-
import { ZodType } from 'zod'
|
11
|
-
|
12
|
-
// JOHN should this even be in cornerstone? especially consider the config types down at the bottom
|
13
|
-
|
14
|
-
export type CacheProps = {
|
15
|
-
maxSize: number | null
|
16
|
-
timeToLive: Duration
|
17
|
-
timeToStale: Duration | null
|
18
|
-
}
|
19
|
-
|
20
|
-
export type CacheOptions = Partial<CacheProps>
|
21
|
-
|
22
|
-
export namespace CacheProps {
|
23
|
-
const DefaultCacheProps = {
|
24
|
-
maxSize: 50000,
|
25
|
-
timeToLive: Durations.OneDay,
|
26
|
-
timeToStale: Durations.OneHour,
|
27
|
-
}
|
28
|
-
|
29
|
-
export const buildCacheProps = (options?: CacheOptions): CacheProps => {
|
30
|
-
options = options ?? {}
|
31
|
-
|
32
|
-
const props = Objects.merge(DefaultCacheProps, options)
|
33
|
-
|
34
|
-
if (props.maxSize === null && props.timeToLive === null) {
|
35
|
-
throw new Error('Invalid cache configuration, both maxSize and timeToLive are null')
|
36
|
-
}
|
37
|
-
|
38
|
-
return props
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
export namespace CacheKey {
|
43
|
-
// We use a hardcoded UUID to represent a unique token value that serves as a flag to disable caching
|
44
|
-
const DisableCacheToken = 'f6822c1a-d527-4c65-b9dd-ddc24620b684'
|
45
|
-
|
46
|
-
export const disableCaching = (): ResourceNamespace => {
|
47
|
-
return DisableCacheToken
|
48
|
-
}
|
49
|
-
|
50
|
-
export const isDisabled = (key: ResourceNamespace): boolean => {
|
51
|
-
return Strings.contains(key, DisableCacheToken)
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
export type CacheSector = {
|
56
|
-
globs: Array<GlobPattern>
|
57
|
-
}
|
58
|
-
|
59
|
-
export namespace CacheSector {
|
60
|
-
export const of = (globs: Arrayable<GlobPattern>) => {
|
61
|
-
return { globs: Arrays.toArray(globs) }
|
62
|
-
}
|
63
|
-
|
64
|
-
export const namespace = (namespace: ResourceNamespace, sector: CacheSector): CacheSector => {
|
65
|
-
return { globs: ResourceKey.namespaceAll(namespace, sector.globs) }
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
export type CacheName = NominalType<string, 'CacheName'>
|
70
|
-
export const CacheNameSchema: ZodType<CacheName> = Zod.string()
|
71
|
-
|
72
|
-
export interface AbstractCache<T> {
|
73
|
-
name: CacheName
|
74
|
-
}
|
75
|
-
|
76
|
-
export interface Cache<T> extends AbstractCache<T> {
|
77
|
-
fetchValue(namespace: ResourceNamespace, key: ResourceKey, fetch: () => Promise<T>): Promise<T>
|
78
|
-
|
79
|
-
fetchValues(
|
80
|
-
namespace: ResourceNamespace,
|
81
|
-
keys: Array<ResourceKey>,
|
82
|
-
fetch: (keys: Array<ResourceKey>) => Promise<Array<Entry<T>>>
|
83
|
-
): Promise<Array<Entry<T>>>
|
84
|
-
|
85
|
-
writeValue(namespace: ResourceNamespace, key: ResourceKey, value: T | undefined): Promise<void>
|
86
|
-
|
87
|
-
writeValues(namespace: ResourceNamespace, entries: Array<Entry<T | undefined>>): Promise<void>
|
88
|
-
|
89
|
-
evictAll(sector: CacheSector): Promise<void>
|
90
|
-
}
|
91
|
-
|
92
|
-
export interface CacheProvider<T> extends RemoteKeyValueStore<CacheEntry<T>> {
|
93
|
-
type: CacheProviderType
|
94
|
-
|
95
|
-
evictAll(sector: CacheSector): Promise<void>
|
96
|
-
}
|
97
|
-
|
98
|
-
export abstract class AbstractCacheProvider<T> extends AbstractRemoteKeyValueStore<CacheEntry<T>> implements CacheProvider<T> {
|
99
|
-
abstract type: CacheProviderType
|
100
|
-
|
101
|
-
abstract evictAll(sector: CacheSector): Promise<void>
|
102
|
-
}
|
103
|
-
|
104
|
-
export interface LocalCache<T> extends AbstractCache<T> {
|
105
|
-
getValue(namespace: ResourceNamespace, key: ResourceKey, fetch: () => T): T
|
106
|
-
|
107
|
-
getValues(namespace: ResourceNamespace, keys: Array<ResourceKey>, fetch: (keys: Array<ResourceKey>) => Array<Entry<T>>): Array<Entry<T>>
|
108
|
-
|
109
|
-
setValue(namespace: ResourceNamespace, key: ResourceKey, value: T | undefined): void
|
110
|
-
|
111
|
-
setValues(namespace: ResourceNamespace, entries: Array<Entry<T | undefined>>): void
|
112
|
-
|
113
|
-
removeAll(sector: CacheSector): void
|
114
|
-
}
|
115
|
-
|
116
|
-
export interface LocalCacheProvider<T> extends LocalKeyValueStore<CacheEntry<T>>, CacheProvider<T> {
|
117
|
-
removeAll(sector: CacheSector): void
|
118
|
-
}
|
119
|
-
|
120
|
-
export abstract class AbstractLocalCacheProvider<T> extends AbstractLocalKeyValueStore<CacheEntry<T>> implements LocalCacheProvider<T> {
|
121
|
-
abstract type: CacheProviderType
|
122
|
-
|
123
|
-
abstract removeAll(sector: CacheSector): void
|
124
|
-
|
125
|
-
async evictAll(sector: CacheSector): Promise<void> {
|
126
|
-
this.removeAll(sector)
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
export type CacheEntry<T> = {
|
131
|
-
value: T
|
132
|
-
liveTimestamp: Date | null
|
133
|
-
staleTimestamp: Date | null
|
134
|
-
}
|
135
|
-
|
136
|
-
export namespace CacheEntry {
|
137
|
-
export const isActive = <T>(entry: CacheEntry<T>): boolean => {
|
138
|
-
if (isDead(entry) || isStale(entry)) {
|
139
|
-
return false
|
140
|
-
}
|
141
|
-
|
142
|
-
return true
|
143
|
-
}
|
144
|
-
|
145
|
-
export const isDead = <T>(entry: CacheEntry<T> | undefined): boolean => {
|
146
|
-
if (Objects.isNil(entry)) {
|
147
|
-
return true
|
148
|
-
}
|
149
|
-
|
150
|
-
if (Objects.isNil(entry.liveTimestamp)) {
|
151
|
-
return false
|
152
|
-
}
|
153
|
-
|
154
|
-
return Dates.isBefore(entry.liveTimestamp, Dates.now())
|
155
|
-
}
|
156
|
-
|
157
|
-
export const isAlive = <T>(entry: CacheEntry<T> | undefined): boolean => !isDead(entry)
|
158
|
-
|
159
|
-
export const isStale = <T>(entry: CacheEntry<T>): boolean => {
|
160
|
-
if (Objects.isNil(entry.staleTimestamp)) {
|
161
|
-
return false
|
162
|
-
}
|
163
|
-
|
164
|
-
return Dates.isBefore(entry.staleTimestamp, Dates.now())
|
165
|
-
}
|
166
|
-
|
167
|
-
export const of = <T>(value: T) => {
|
168
|
-
const entry: CacheEntry<T> = {
|
169
|
-
value,
|
170
|
-
liveTimestamp: null,
|
171
|
-
staleTimestamp: null,
|
172
|
-
}
|
173
|
-
|
174
|
-
return entry
|
175
|
-
}
|
176
|
-
|
177
|
-
// JOHN do we want to enforce some kind of minimum liveness threshold?
|
178
|
-
export const applyProps = <T>(originalEntry: CacheEntry<T>, props: CacheProps): CacheEntry<T> => {
|
179
|
-
let liveTimestamp: Date | null = originalEntry.liveTimestamp
|
180
|
-
if (!Objects.isNil(props.timeToLive)) {
|
181
|
-
const limit = Dates.addMilliseconds(Dates.now(), Durations.inMilliseconds(props.timeToLive))
|
182
|
-
if (Dates.isBefore(limit, liveTimestamp ?? limit)) {
|
183
|
-
liveTimestamp = limit
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
let staleTimestamp: Date | null = originalEntry.staleTimestamp
|
188
|
-
if (!Objects.isNil(props.timeToStale)) {
|
189
|
-
const limit = Dates.addMilliseconds(Dates.now(), Durations.inMilliseconds(props.timeToStale))
|
190
|
-
if (Dates.isBefore(limit, staleTimestamp ?? limit)) {
|
191
|
-
staleTimestamp = limit
|
192
|
-
}
|
193
|
-
}
|
194
|
-
|
195
|
-
const limitedEntry: CacheEntry<T> = {
|
196
|
-
value: originalEntry.value,
|
197
|
-
liveTimestamp,
|
198
|
-
staleTimestamp,
|
199
|
-
}
|
200
|
-
|
201
|
-
return limitedEntry
|
202
|
-
}
|
203
|
-
}
|
204
|
-
|
205
|
-
export type CacheConfigurationOptions = CacheConfigurationSection & {
|
206
|
-
local: CacheConfigurationSection
|
207
|
-
}
|
208
|
-
|
209
|
-
export type CacheConfigurationSection = {
|
210
|
-
defaults: CacheDefinition
|
211
|
-
|
212
|
-
/**
|
213
|
-
* These options map from cache name key to configuration. They are a way for the tenant to override the configurations
|
214
|
-
* for specific caches from the cache configuration here.
|
215
|
-
*/
|
216
|
-
caches?: Record<string, Partial<CacheDefinition>>
|
217
|
-
}
|
218
|
-
|
219
|
-
export type CacheDefinition = {
|
220
|
-
options?: CacheOptions
|
221
|
-
providers: Array<CacheProviderConfiguration>
|
222
|
-
}
|
223
|
-
|
224
|
-
export type CacheProviderType = NominalType<string, 'CacheProviderType'>
|
225
|
-
export type CacheProviderConfiguration = CacheOptions & {
|
226
|
-
type: CacheProviderType
|
227
|
-
}
|
228
|
-
|
229
|
-
export type CacheConfiguration = CacheConfigurationSection & {
|
230
|
-
local: CacheConfigurationSection
|
231
|
-
}
|
232
|
-
|
233
|
-
export type CacheProviderRegistry<ContextType extends AbstractApplicationContext> = {
|
234
|
-
type: CacheProviderType
|
235
|
-
construct: <T>(props: CacheProps, context: ContextType) => CacheProvider<T>
|
236
|
-
}
|
package/src/combinable.ts
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
import { Arrays, Sets } from '@bessemer/cornerstone'
|
2
|
-
|
3
|
-
export interface Combinable {
|
4
|
-
combinability: Combinability
|
5
|
-
}
|
6
|
-
|
7
|
-
export type Combinability = {
|
8
|
-
type: CombinabilityType
|
9
|
-
class: CombinabilityClass
|
10
|
-
}
|
11
|
-
|
12
|
-
export enum CombinabilityType {
|
13
|
-
Stackable = 'Stackable',
|
14
|
-
Singleton = 'Singleton',
|
15
|
-
Totalitarian = 'Totalitarian',
|
16
|
-
}
|
17
|
-
|
18
|
-
export type CombinabilityClass = string | null
|
19
|
-
|
20
|
-
export const DefaultCombinability: Combinability = {
|
21
|
-
type: CombinabilityType.Stackable,
|
22
|
-
class: null,
|
23
|
-
}
|
24
|
-
|
25
|
-
export const combinations = <T extends Combinable>(combinables: Array<T>): Array<Array<T>> => {
|
26
|
-
const classMap = Arrays.groupBy(combinables, (it) => it.combinability.class)
|
27
|
-
|
28
|
-
const classCombinations: Array<Array<Array<T>>> = Object.entries(classMap).map(([_, values]) => {
|
29
|
-
const totalitarianCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Totalitarian).map((it) => [it])
|
30
|
-
if (!Arrays.isEmpty(totalitarianCombinations)) {
|
31
|
-
return totalitarianCombinations
|
32
|
-
}
|
33
|
-
|
34
|
-
const singletonCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Singleton).map((it) => [it])
|
35
|
-
const stackableCombination = values.filter((it) => it.combinability.type === CombinabilityType.Stackable)
|
36
|
-
return [stackableCombination, ...singletonCombinations]
|
37
|
-
})
|
38
|
-
|
39
|
-
return Sets.cartesianProduct(...classCombinations).flatMap((it) => it)
|
40
|
-
}
|