@bessemer/cornerstone 0.5.114 → 0.5.116
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.map +1 -1
- package/dist/array.js +28 -28
- package/dist/array.js.map +1 -1
- package/dist/aspect-ratio.d.ts +3 -3
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +13 -12
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/assertion.d.ts.map +1 -1
- package/dist/assertion.js +5 -5
- package/dist/assertion.js.map +1 -1
- package/dist/async-value.js +2 -2
- package/dist/async-value.js.map +1 -1
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +2 -2
- package/dist/async.js.map +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +11 -12
- package/dist/cache.js.map +1 -1
- package/dist/combinable.js +5 -5
- package/dist/combinable.js.map +1 -1
- package/dist/comparator.js +8 -8
- package/dist/comparator.js.map +1 -1
- package/dist/data-size.d.ts +2 -1
- package/dist/data-size.d.ts.map +1 -1
- package/dist/data-size.js +3 -3
- package/dist/data-size.js.map +1 -1
- package/dist/either.js +5 -5
- package/dist/either.js.map +1 -1
- package/dist/equalitor.d.ts.map +1 -1
- package/dist/equalitor.js +2 -2
- package/dist/equalitor.js.map +1 -1
- package/dist/error/error-cause.d.ts.map +1 -1
- package/dist/error/error-cause.js +14 -14
- package/dist/error/error-cause.js.map +1 -1
- package/dist/error/error-code.js +2 -2
- package/dist/error/error-code.js.map +1 -1
- package/dist/error/error-event.d.ts +3 -2
- package/dist/error/error-event.d.ts.map +1 -1
- package/dist/error/error-event.js +28 -28
- package/dist/error/error-event.js.map +1 -1
- package/dist/error/error-type.d.ts +2 -1
- package/dist/error/error-type.d.ts.map +1 -1
- package/dist/error/error-type.js +2 -2
- package/dist/error/error-type.js.map +1 -1
- package/dist/error/error.js +5 -5
- package/dist/error/error.js.map +1 -1
- package/dist/expression/array-expression.js +3 -3
- package/dist/expression/array-expression.js.map +1 -1
- package/dist/expression/core-expression.d.ts.map +1 -1
- package/dist/expression/core-expression.js +19 -19
- package/dist/expression/core-expression.js.map +1 -1
- package/dist/expression/expression-evaluator.js +2 -2
- package/dist/expression/expression-evaluator.js.map +1 -1
- package/dist/expression/expression-mapper.js +4 -4
- package/dist/expression/expression-mapper.js.map +1 -1
- package/dist/expression/internal.js +3 -3
- package/dist/expression/internal.js.map +1 -1
- package/dist/expression/numeric-expression.js +13 -13
- package/dist/expression/numeric-expression.js.map +1 -1
- package/dist/expression/string-expression.js +4 -4
- package/dist/expression/string-expression.js.map +1 -1
- package/dist/glob.d.ts +3 -3
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +11 -12
- package/dist/glob.js.map +1 -1
- package/dist/global-variable.d.ts.map +1 -1
- package/dist/global-variable.js +5 -5
- package/dist/global-variable.js.map +1 -1
- package/dist/hex-code.d.ts +3 -3
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +11 -10
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +3 -3
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +9 -10
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +3 -3
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +13 -11
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +3 -3
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +9 -10
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +3 -3
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +9 -10
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +3 -3
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +18 -19
- package/dist/intl/locale.js.map +1 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +2 -2
- package/dist/json.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +12 -12
- package/dist/logger.js.map +1 -1
- package/dist/map.js +8 -8
- package/dist/map.js.map +1 -1
- package/dist/mime-type.d.ts +3 -3
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +9 -10
- package/dist/mime-type.js.map +1 -1
- package/dist/misc.js +4 -4
- package/dist/misc.js.map +1 -1
- package/dist/monetary-amount.d.ts +3 -2
- package/dist/monetary-amount.d.ts.map +1 -1
- package/dist/monetary-amount.js +16 -16
- package/dist/monetary-amount.js.map +1 -1
- package/dist/net/content-type.d.ts +2 -1
- package/dist/net/content-type.d.ts.map +1 -1
- package/dist/net/content-type.js +2 -2
- package/dist/net/content-type.js.map +1 -1
- package/dist/net/domain-name.d.ts +3 -3
- package/dist/net/domain-name.d.ts.map +1 -1
- package/dist/net/domain-name.js +10 -11
- package/dist/net/domain-name.js.map +1 -1
- package/dist/net/http-method.d.ts.map +1 -1
- package/dist/net/http-method.js +9 -9
- package/dist/net/http-method.js.map +1 -1
- package/dist/net/ipv4-address.d.ts +3 -3
- package/dist/net/ipv4-address.d.ts.map +1 -1
- package/dist/net/ipv4-address.js +10 -11
- package/dist/net/ipv4-address.js.map +1 -1
- package/dist/net/ipv6-address.d.ts +3 -3
- package/dist/net/ipv6-address.d.ts.map +1 -1
- package/dist/net/ipv6-address.js +10 -11
- package/dist/net/ipv6-address.js.map +1 -1
- package/dist/net/uri-host-name.d.ts +3 -3
- package/dist/net/uri-host-name.d.ts.map +1 -1
- package/dist/net/uri-host-name.js +15 -16
- package/dist/net/uri-host-name.js.map +1 -1
- package/dist/net/uri.d.ts +1 -2
- package/dist/net/uri.d.ts.map +1 -1
- package/dist/net/uri.js +5 -3
- package/dist/net/uri.js.map +1 -1
- package/dist/net/url.d.ts.map +1 -1
- package/dist/net/url.js +6 -7
- package/dist/net/url.js.map +1 -1
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js +23 -28
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.js +19 -19
- package/dist/object/type-path.js.map +1 -1
- package/dist/patch.js +4 -4
- package/dist/patch.js.map +1 -1
- package/dist/promise.js +2 -2
- package/dist/promise.js.map +1 -1
- package/dist/property.d.ts.map +1 -1
- package/dist/property.js +7 -7
- package/dist/property.js.map +1 -1
- package/dist/proxy.js +2 -2
- package/dist/proxy.js.map +1 -1
- package/dist/range.js +2 -2
- package/dist/range.js.map +1 -1
- package/dist/reference.d.ts +2 -1
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +13 -13
- package/dist/reference.js.map +1 -1
- package/dist/resource-key.js +2 -2
- package/dist/resource-key.js.map +1 -1
- package/dist/result.js +5 -5
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +12 -12
- package/dist/retry.js.map +1 -1
- package/dist/rich-text.js +2 -2
- package/dist/rich-text.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +9 -9
- package/dist/signature.js.map +1 -1
- package/dist/sql/sql-expression-parser.js +2 -2
- package/dist/sql/sql-expression-parser.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +9 -9
- package/dist/store.js.map +1 -1
- package/dist/string.js +4 -4
- package/dist/string.js.map +1 -1
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +10 -10
- package/dist/tag.js.map +1 -1
- package/dist/temporal/clock.d.ts +13 -13
- package/dist/temporal/clock.d.ts.map +1 -1
- package/dist/temporal/clock.js +10 -10
- package/dist/temporal/clock.js.map +1 -1
- package/dist/temporal/duration.d.ts +15 -9
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +30 -31
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts +18 -15
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +42 -43
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts +16 -13
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +36 -38
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts +16 -13
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +35 -37
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-month-day.d.ts +37 -0
- package/dist/temporal/plain-month-day.d.ts.map +1 -0
- package/dist/temporal/plain-month-day.js +84 -0
- package/dist/temporal/plain-month-day.js.map +1 -0
- package/dist/temporal/plain-time.d.ts +19 -17
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +43 -42
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/plain-year-month.d.ts +57 -0
- package/dist/temporal/plain-year-month.d.ts.map +1 -0
- package/dist/temporal/plain-year-month.js +109 -0
- package/dist/temporal/plain-year-month.js.map +1 -0
- package/dist/temporal/time-zone-id.d.ts +5 -4
- package/dist/temporal/time-zone-id.d.ts.map +1 -1
- package/dist/temporal/time-zone-id.js +11 -11
- package/dist/temporal/time-zone-id.js.map +1 -1
- package/dist/temporal/time-zone-offset.d.ts +12 -11
- package/dist/temporal/time-zone-offset.d.ts.map +1 -1
- package/dist/temporal/time-zone-offset.js +42 -50
- package/dist/temporal/time-zone-offset.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts +16 -13
- package/dist/temporal/zoned-date-time.d.ts.map +1 -1
- package/dist/temporal/zoned-date-time.js +35 -36
- package/dist/temporal/zoned-date-time.js.map +1 -1
- package/dist/uuid/ulid.d.ts +3 -3
- package/dist/uuid/ulid.d.ts.map +1 -1
- package/dist/uuid/ulid.js +9 -10
- package/dist/uuid/ulid.js.map +1 -1
- package/dist/uuid/uuid-v4.d.ts +3 -3
- package/dist/uuid/uuid-v4.d.ts.map +1 -1
- package/dist/uuid/uuid-v4.js +13 -14
- package/dist/uuid/uuid-v4.js.map +1 -1
- package/dist/uuid/uuid-v7.d.ts +1 -2
- package/dist/uuid/uuid-v7.d.ts.map +1 -1
- package/dist/uuid/uuid-v7.js +1 -2
- package/dist/uuid/uuid-v7.js.map +1 -1
- package/dist/zod-util.d.ts +4 -21
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +21 -11
- package/dist/zod-util.js.map +1 -1
- package/package.json +2 -2
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 } 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.namespaceKeys(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,eAAe;AAO1C,OAAO,SAAsB;AAC7B,SAAS,WAAW,aAAa;AACjC,SAAS,eAAe;AACxB,SAAS,QAAQ,SAAS,oBAAoB;AAC9C,YAAY,cAAc;AAWnB,IAAU;AAAA,CAAV,CAAUA,gBAAV;AACL,QAAM,oBAAoB;AAAA,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AAA,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 } from '@bessemer/cornerstone/temporal/duration'\nimport * as Durations 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 * as Objects from '@bessemer/cornerstone/object'\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: Durations.OneDay,\n timeToStale: Durations.OneHour,\n }\n\n export const buildCacheProps = (options?: CacheOptions): CacheProps => {\n options = options ?? {}\n\n const props = Objects.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: Arrays.toArray(globs) }\n }\n\n export const namespace = (namespace: ResourceNamespace, sector: CacheSector): CacheSector => {\n return { globs: ResourceKeys.namespaceKeys(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 (Objects.isNil(entry)) {\n return true\n }\n\n if (Objects.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 (Objects.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 (!Objects.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 (!Objects.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;AAEjH,YAAY,eAAe;AAO3B,OAAO,SAAsB;AAC7B,YAAY,aAAa;AACzB,SAAS,QAAQ,SAAS,oBAAoB;AAC9C,YAAY,cAAc;AAWnB,IAAU;AAAA,CAAV,CAAUA,gBAAV;AACL,QAAM,oBAAoB;AAAA,IACxB,SAAS;AAAA,IACT,YAAsB;AAAA,IACtB,aAAuB;AAAA,EACzB;AAEO,EAAMA,YAAA,kBAAkB,CAAC,YAAuC;AACrE,cAAU,WAAW,CAAC;AAEtB,UAAM,QAAgB,kBAAU,mBAAmB,OAAO;AAE1D,QAAI,MAAM,YAAY,QAAQ,MAAM,eAAe,MAAM;AACvD,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACrF;AAEA,WAAO;AAAA,EACT;AAAA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,kBAAS,MAAM,eAAwB,aAAI,CAAC;AAAA,EAC9D;AAEO,EAAMA,YAAA,UAAU,CAAI,UAA8C,KAACA,YAAA,QAAO,KAAK;AAE/E,EAAMA,YAAA,UAAU,CAAI,UAAkC;AAC3D,QAAY,cAAM,MAAM,cAAc,GAAG;AACvC,aAAO;AAAA,IACT;AAEA,WAAgB,kBAAS,MAAM,gBAAyB,aAAI,CAAC;AAAA,EAC/D;AAEO,EAAMA,YAAA,KAAK,CAAI,UAAa;AACjC,UAAM,QAAuB;AAAA,MAC3B;AAAA,MACA,eAAe;AAAA,MACf,gBAAgB;AAAA,IAClB;AAEA,WAAO;AAAA,EACT;AAGO,EAAMA,YAAA,aAAa,CAAI,eAA8B,UAAqC;AAC/F,QAAI,gBAAuC,cAAc;AACzD,QAAI,CAAS,cAAM,MAAM,UAAU,GAAG;AACpC,YAAM,QAAiB,aAAa,aAAI,GAAG,MAAM,UAAU;AAC3D,UAAa,kBAAS,OAAO,iBAAiB,KAAK,GAAG;AACpD,wBAAyB,mBAAU,KAAK;AAAA,MAC1C;AAAA,IACF;AAEA,QAAI,iBAAwC,cAAc;AAC1D,QAAI,CAAS,cAAM,MAAM,WAAW,GAAG;AACrC,YAAM,QAAiB,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/combinable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/combinable.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as Arrays from "@bessemer/cornerstone/array";
|
|
3
|
+
import * as Sets from "@bessemer/cornerstone/set";
|
|
4
4
|
var CombinabilityType = /* @__PURE__ */ ((CombinabilityType2) => {
|
|
5
5
|
CombinabilityType2["Stackable"] = "Stackable";
|
|
6
6
|
CombinabilityType2["Singleton"] = "Singleton";
|
|
@@ -12,17 +12,17 @@ var DefaultCombinability = {
|
|
|
12
12
|
class: null
|
|
13
13
|
};
|
|
14
14
|
var combinations = (combinables) => {
|
|
15
|
-
const classMap = groupBy(combinables, (it) => it.combinability.class ?? "");
|
|
15
|
+
const classMap = Arrays.groupBy(combinables, (it) => it.combinability.class ?? "");
|
|
16
16
|
const classCombinations = Object.entries(classMap).map(([_, values]) => {
|
|
17
17
|
const totalitarianCombinations = values.filter((it) => it.combinability.type === "Totalitarian" /* Totalitarian */).map((it) => [it]);
|
|
18
|
-
if (!isEmpty(totalitarianCombinations)) {
|
|
18
|
+
if (!Arrays.isEmpty(totalitarianCombinations)) {
|
|
19
19
|
return totalitarianCombinations;
|
|
20
20
|
}
|
|
21
21
|
const singletonCombinations = values.filter((it) => it.combinability.type === "Singleton" /* Singleton */).map((it) => [it]);
|
|
22
22
|
const stackableCombination = values.filter((it) => it.combinability.type === "Stackable" /* Stackable */);
|
|
23
23
|
return [stackableCombination, ...singletonCombinations];
|
|
24
24
|
});
|
|
25
|
-
return cartesianProduct(...classCombinations).flatMap((it) => it);
|
|
25
|
+
return Sets.cartesianProduct(...classCombinations).flatMap((it) => it);
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
28
|
CombinabilityType,
|
package/dist/combinable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/combinable.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/combinable.ts"],"sourcesContent":["import * as Arrays from '@bessemer/cornerstone/array'\nimport * as Sets from '@bessemer/cornerstone/set'\n\nexport interface Combinable {\n combinability: Combinability\n}\n\nexport type Combinability = {\n type: CombinabilityType\n class: CombinabilityClass\n}\n\nexport enum CombinabilityType {\n Stackable = 'Stackable',\n Singleton = 'Singleton',\n Totalitarian = 'Totalitarian',\n}\n\nexport type CombinabilityClass = string | null\n\nexport const DefaultCombinability: Combinability = {\n type: CombinabilityType.Stackable,\n class: null,\n}\n\nexport const combinations = <T extends Combinable>(combinables: Array<T>): Array<Array<T>> => {\n // JOHN this is wrong\n const classMap = Arrays.groupBy(combinables, (it) => it.combinability.class ?? '')\n\n const classCombinations: Array<Array<Array<T>>> = Object.entries(classMap).map(([_, values]) => {\n const totalitarianCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Totalitarian).map((it) => [it])\n if (!Arrays.isEmpty(totalitarianCombinations)) {\n return totalitarianCombinations\n }\n\n const singletonCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Singleton).map((it) => [it])\n const stackableCombination = values.filter((it) => it.combinability.type === CombinabilityType.Stackable)\n return [stackableCombination, ...singletonCombinations]\n })\n\n return Sets.cartesianProduct(...classCombinations).flatMap((it) => it)\n}\n"],"mappings":";AAAA,YAAY,YAAY;AACxB,YAAY,UAAU;AAWf,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,kBAAe;AAHL,SAAAA;AAAA,GAAA;AAQL,IAAM,uBAAsC;AAAA,EACjD,MAAM;AAAA,EACN,OAAO;AACT;AAEO,IAAM,eAAe,CAAuB,gBAA2C;AAE5F,QAAM,WAAkB,eAAQ,aAAa,CAAC,OAAO,GAAG,cAAc,SAAS,EAAE;AAEjF,QAAM,oBAA4C,OAAO,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,MAAM;AAC9F,UAAM,2BAA2B,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,iCAA8B,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AACjI,QAAI,CAAQ,eAAQ,wBAAwB,GAAG;AAC7C,aAAO;AAAA,IACT;AAEA,UAAM,wBAAwB,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,2BAA2B,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AAC3H,UAAM,uBAAuB,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,2BAA2B;AACxG,WAAO,CAAC,sBAAsB,GAAG,qBAAqB;AAAA,EACxD,CAAC;AAED,SAAY,sBAAiB,GAAG,iBAAiB,EAAE,QAAQ,CAAC,OAAO,EAAE;AACvE;","names":["CombinabilityType"]}
|
package/dist/comparator.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/comparator.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import * as Strings from "@bessemer/cornerstone/string";
|
|
3
|
+
import * as Maths from "@bessemer/cornerstone/math";
|
|
4
|
+
import * as Dates from "@bessemer/cornerstone/temporal/date";
|
|
5
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
6
6
|
var aggregate = (comparators) => {
|
|
7
7
|
return (first, second) => {
|
|
8
8
|
if (first === second) {
|
|
@@ -30,13 +30,13 @@ var natural = () => {
|
|
|
30
30
|
return aggregate([
|
|
31
31
|
nullsLast(),
|
|
32
32
|
(first, second) => {
|
|
33
|
-
if (isString(first) && isString(second)) {
|
|
33
|
+
if (Strings.isString(first) && Strings.isString(second)) {
|
|
34
34
|
return first.localeCompare(second);
|
|
35
|
-
} else if (isNumber(first) && isNumber(second)) {
|
|
35
|
+
} else if (Maths.isNumber(first) && Maths.isNumber(second)) {
|
|
36
36
|
return first - second;
|
|
37
|
-
} else if (isDate(first) && isDate(second)) {
|
|
37
|
+
} else if (Dates.isDate(first) && Dates.isDate(second)) {
|
|
38
38
|
return first.getTime() - second.getTime();
|
|
39
|
-
} else if (isBoolean(first) && isBoolean(second)) {
|
|
39
|
+
} else if (Objects.isBoolean(first) && Objects.isBoolean(second)) {
|
|
40
40
|
if (first !== second) {
|
|
41
41
|
return second ? 1 : 0;
|
|
42
42
|
} else {
|
package/dist/comparator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { BasicType } from '@bessemer/cornerstone/types'\nimport
|
|
1
|
+
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { BasicType } from '@bessemer/cornerstone/types'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Maths from '@bessemer/cornerstone/math'\nimport * as Dates from '@bessemer/cornerstone/temporal/date'\nimport * as Objects 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 (Strings.isString(first) && Strings.isString(second)) {\n return first.localeCompare(second)\n } else if (Maths.isNumber(first) && Maths.isNumber(second)) {\n return first! - second!\n } else if (Dates.isDate(first) && Dates.isDate(second)) {\n return first.getTime() - second.getTime()\n } else if (Objects.isBoolean(first) && Objects.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,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,YAAY,WAAW;AACvB,YAAY,aAAa;AAIlB,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,UAAY,iBAAS,KAAK,KAAa,iBAAS,MAAM,GAAG;AACvD,eAAO,MAAM,cAAc,MAAM;AAAA,MACnC,WAAiB,eAAS,KAAK,KAAW,eAAS,MAAM,GAAG;AAC1D,eAAO,QAAS;AAAA,MAClB,WAAiB,aAAO,KAAK,KAAW,aAAO,MAAM,GAAG;AACtD,eAAO,MAAM,QAAQ,IAAI,OAAO,QAAQ;AAAA,MAC1C,WAAmB,kBAAU,KAAK,KAAa,kBAAU,MAAM,GAAG;AAChE,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":[]}
|
package/dist/data-size.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NominalType } from '@bessemer/cornerstone/types';
|
|
2
2
|
import Zod from 'zod';
|
|
3
|
-
|
|
3
|
+
import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
|
|
4
|
+
export declare const Namespace: ResourceKeys.ResourceNamespace<"data-size">;
|
|
4
5
|
export type DataSize = NominalType<number, typeof Namespace>;
|
|
5
6
|
export declare const fromBytes: (value: number) => DataSize;
|
|
6
7
|
export declare const Schema: Zod.ZodPipe<Zod.ZodNumber, Zod.ZodTransform<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,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;
|
|
1
|
+
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|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/data-size.ts
|
|
2
2
|
import Zod from "zod";
|
|
3
|
-
import
|
|
4
|
-
var Namespace = createNamespace("data-size");
|
|
3
|
+
import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
|
|
4
|
+
var Namespace = ResourceKeys.createNamespace("data-size");
|
|
5
5
|
var fromBytes = (value) => {
|
|
6
6
|
return value;
|
|
7
7
|
};
|
|
8
|
-
var Schema = Zod.number().transform(fromBytes).meta({
|
|
8
|
+
var Schema = Zod.number().int().transform(fromBytes).meta({
|
|
9
9
|
type: "number",
|
|
10
10
|
format: Namespace
|
|
11
11
|
});
|
package/dist/data-size.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data-size.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport
|
|
1
|
+
{"version":3,"sources":["../src/data-size.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\n\nexport const Namespace = ResourceKeys.createNamespace('data-size')\nexport type DataSize = NominalType<number, typeof Namespace>\n\nexport const fromBytes = (value: number): DataSize => {\n return value as DataSize\n}\n\nexport const Schema = Zod.number().int().transform(fromBytes).meta({\n type: 'number',\n format: Namespace,\n})\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;AAChB,YAAY,kBAAkB;AAEvB,IAAM,YAAyB,6BAAgB,WAAW;AAG1D,IAAM,YAAY,CAAC,UAA4B;AACpD,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,OAAO,EAAE,IAAI,EAAE,UAAU,SAAS,EAAE,KAAK;AAAA,EACjE,MAAM;AAAA,EACN,QAAQ;AACV,CAAC;AAEM,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":[]}
|
package/dist/either.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/either.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
3
|
+
import * as Assertions from "@bessemer/cornerstone/assertion";
|
|
4
4
|
import * as Promises from "@bessemer/cornerstone/promise";
|
|
5
5
|
var TypeToken = "__Either.type";
|
|
6
6
|
var EitherType = /* @__PURE__ */ ((EitherType2) => {
|
|
@@ -16,13 +16,13 @@ var isLeft = (value) => {
|
|
|
16
16
|
return !isRight(value);
|
|
17
17
|
};
|
|
18
18
|
var isRight = (value) => {
|
|
19
|
-
return isObject(value) && value[TypeToken] === "Right" /* Right */;
|
|
19
|
+
return Objects.isObject(value) && value[TypeToken] === "Right" /* Right */;
|
|
20
20
|
};
|
|
21
21
|
function assertLeft(value) {
|
|
22
|
-
assert(isLeft(value));
|
|
22
|
+
Assertions.assert(isLeft(value));
|
|
23
23
|
}
|
|
24
24
|
function assertRight(value) {
|
|
25
|
-
assert(isRight(value));
|
|
25
|
+
Assertions.assert(isRight(value));
|
|
26
26
|
}
|
|
27
27
|
function map2(value, mapper) {
|
|
28
28
|
if (isRight(value)) {
|
package/dist/either.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["import * as Objects from '@bessemer/cornerstone/object'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport * as Promises from '@bessemer/cornerstone/promise'\nimport { Promisable } from 'type-fest'\n\nconst TypeToken = '__Either.type'\n\nexport enum EitherType {\n Left = 'Left',\n Right = 'Right',\n}\n\ndeclare const __types: unique symbol\nexport type NominalTyping2<NominalType> = { [__types]: NominalType }\nexport type NominalType2<ConcreteType, NominalType> = ConcreteType & NominalTyping2<NominalType>\n\nexport type Left<LeftType> = NominalType2<LeftType, 'Left'>\nexport type Right<RightType> = {\n [TypeToken]: EitherType.Right\n value: RightType\n}\nexport type Either<LeftType, RightType> = Left<LeftType> | Right<RightType>\n\nexport const left = <LeftType>(value: LeftType): Left<LeftType> => value as Left<LeftType>\nexport const right = <RightType>(value: RightType): Right<RightType> => {\n return { [TypeToken]: EitherType.Right, value }\n}\n\nexport const isLeft = <LeftType, RightType>(value: Either<LeftType, RightType>): value is Left<LeftType> => {\n return !isRight(value)\n}\nexport const isRight = <LeftType, RightType>(value: Either<LeftType, RightType>): value is Right<RightType> => {\n return Objects.isObject(value) && (value as any)[TypeToken] === EitherType.Right\n}\n\nexport function assertLeft<LeftType, RightType>(value: Either<LeftType, RightType>): asserts value is Left<LeftType> {\n Assertions.assert(isLeft(value))\n}\nexport function assertRight<LeftType, RightType>(value: Either<LeftType, RightType>): asserts value is Right<RightType> {\n Assertions.assert(isRight(value))\n}\n\nexport function map<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => Promise<MappedType>\n): Promise<Either<MappedType, RightType>>\nexport function map<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => MappedType\n): Either<MappedType, RightType>\nexport function map<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => MappedType\n): Promisable<Either<MappedType, RightType>> {\n if (isRight(value)) {\n return value\n }\n\n return Promises.map(mapper(value), left)\n}\n\nexport function flatMap<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => Promise<Either<MappedLeftType, MappedRightType>>\n): Promise<Either<MappedLeftType, RightType | MappedRightType>>\nexport function flatMap<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => Either<MappedLeftType, MappedRightType>\n): Either<MappedLeftType, RightType | MappedRightType>\nexport function flatMap<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: LeftType) => Either<MappedLeftType, MappedRightType>\n): Promisable<Either<MappedLeftType, RightType | MappedRightType>> {\n if (isRight(value)) {\n return value\n }\n\n return mapper(value)\n}\n\nexport function mapRight<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => Promise<MappedType>\n): Promise<Either<LeftType, MappedType>>\nexport function mapRight<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => MappedType\n): Either<LeftType, MappedType>\nexport function mapRight<LeftType, RightType, MappedType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => MappedType\n): Promisable<Either<LeftType, MappedType>> {\n if (isLeft(value)) {\n return value\n }\n\n return Promises.map(mapper(value.value), right)\n}\n\nexport function flatMapRight<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => Promise<Either<MappedLeftType, MappedRightType>>\n): Promise<Either<LeftType | MappedLeftType, MappedRightType>>\nexport function flatMapRight<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => Either<MappedLeftType, MappedRightType>\n): Either<LeftType | MappedLeftType, MappedRightType>\nexport function flatMapRight<LeftType, RightType, MappedLeftType, MappedRightType>(\n value: Either<LeftType, RightType>,\n mapper: (value: RightType) => Either<MappedLeftType, MappedRightType>\n): Promisable<Either<LeftType | MappedLeftType, MappedRightType>> {\n if (isLeft(value)) {\n return value\n }\n\n return mapper(value.value)\n}\n\nexport const split = <LeftType, RightType>(array: Array<Either<LeftType, RightType>>): [Array<LeftType>, Array<RightType>] => {\n const lefts = array.filter((it) => isLeft(it)).map((it) => it)\n const rights = array.filter((it) => isRight(it)).map((it) => it.value)\n return [lefts, rights]\n}\n\n// export const buildGenerator = <EitherType extends Either<any, any>, TGen extends () => Generator<EitherType> | AsyncGenerator<EitherType>>(\n// lift: (val: any) => EitherType\n// ): ((\n// generatorFn: TGen\n// ) => TGen extends () => Generator<EitherType, infer R>\n// ? EitherType\n// : TGen extends () => AsyncGenerator<EitherType, infer R>\n// ? Promise<EitherType>\n// : never) => {\n// return (generatorFn) => {\n// const generator = generatorFn()\n// const firstNext = generator.next()\n// if (isPromise(firstNext)) {\n// return (async () => {\n// let current = await firstNext\n// while (!current.done) {\n// const result = current.value\n// if (result.isLeft) {\n// return result\n// }\n// current = await generator.next(result.value)\n// }\n// return lift(current.value)\n// })() as any\n// } else {\n// let current = firstNext\n// while (!current.done) {\n// const result = current.value\n// if (result.isLeft) {\n// return result\n// }\n//\n// current = generator.next(result.value) as IteratorResult<EitherType>\n// }\n//\n// return lift(current.value)\n// }\n// }\n// }\n//\n// const generator = buildGenerator((it) => right(it) as Either<any, any>)\n//\n// export function gen<TGen extends () => Generator<Either<any, any>>>(\n// generatorFn: TGen\n// ): TGen extends () => Generator<Either<any, infer L>, infer R> ? Either<R, L> : never\n// export function gen<TGen extends () => AsyncGenerator<Either<any, any>>>(\n// generatorFn: TGen\n// ): Promise<TGen extends () => AsyncGenerator<Either<any, infer L>, infer R> ? Either<R, L> : never>\n// export function gen<TGen extends () => Generator<Either<any, any>> | AsyncGenerator<Either<any, any>>>(\n// generatorFn: TGen\n// ): TGen extends () => Generator<Either<any, infer L>, infer R>\n// ? Either<R, L>\n// : TGen extends () => AsyncGenerator<Either<any, infer L>, infer R>\n// ? Promise<Either<R, L>>\n// : never {\n// return generator(generatorFn)\n// }\n"],"mappings":";AAAA,YAAY,aAAa;AACzB,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAG1B,IAAM,YAAY;AAEX,IAAK,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GAAG,KAAK;AACrE,SAAO,CAAC,OAAO,MAAM;AACvB;","names":["EitherType","map"]}
|
package/dist/equalitor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equalitor.d.ts","sourceRoot":"","sources":["../src/equalitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAG7D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAA;AAE3D,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,YAAY,UAAU,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,CAExE,CAAA;AAED,eAAO,MAAM,OAAO,GACjB,CAAC,OAAK,SAAS,CAAC,CAAC,CAEA,CAAA;AAEpB,eAAO,MAAM,WAAW,GACrB,CAAC,OAAK,SAAS,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"equalitor.d.ts","sourceRoot":"","sources":["../src/equalitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAG7D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAA;AAE3D,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,YAAY,UAAU,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,CAExE,CAAA;AAED,eAAO,MAAM,OAAO,GACjB,CAAC,OAAK,SAAS,CAAC,CAAC,CAEA,CAAA;AAEpB,eAAO,MAAM,WAAW,GACrB,CAAC,OAAK,SAAS,CAAC,CAAC,CAEgB,CAAA;AAEpC,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,WAAW,SAAS,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,CAE7F,CAAA"}
|
package/dist/equalitor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/equalitor.ts
|
|
2
|
-
import
|
|
2
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
3
3
|
var fromComparator = (comparator) => {
|
|
4
4
|
return (first, second) => comparator(first, second) === 0;
|
|
5
5
|
};
|
|
6
6
|
var natural = () => (first, second) => first === second;
|
|
7
|
-
var deepNatural = () => (first, second) => deepEqual(first, second);
|
|
7
|
+
var deepNatural = () => (first, second) => Objects.deepEqual(first, second);
|
|
8
8
|
var equalBy = (mapper, equalitor) => {
|
|
9
9
|
return (first, second) => equalitor(mapper(first), mapper(second));
|
|
10
10
|
};
|
package/dist/equalitor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/equalitor.ts"],"sourcesContent":["import { Comparator } from '@bessemer/cornerstone/comparator'\nimport
|
|
1
|
+
{"version":3,"sources":["../src/equalitor.ts"],"sourcesContent":["import { Comparator } from '@bessemer/cornerstone/comparator'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport type Equalitor<T> = (first: T, second: T) => boolean\n\nexport const fromComparator = <T>(comparator: Comparator<T>): Equalitor<T> => {\n return (first, second) => comparator(first, second) === 0\n}\n\nexport const natural =\n <T>(): Equalitor<T> =>\n (first, second) =>\n first === second\n\nexport const deepNatural =\n <T>(): Equalitor<T> =>\n (first, second) =>\n Objects.deepEqual(first, second)\n\nexport const equalBy = <T, N>(mapper: (element: T) => N, equalitor: Equalitor<N>): Equalitor<T> => {\n return (first, second) => equalitor(mapper(first), mapper(second))\n}\n"],"mappings":";AACA,YAAY,aAAa;AAIlB,IAAM,iBAAiB,CAAI,eAA4C;AAC5E,SAAO,CAAC,OAAO,WAAW,WAAW,OAAO,MAAM,MAAM;AAC1D;AAEO,IAAM,UACX,MACA,CAAC,OAAO,WACN,UAAU;AAEP,IAAM,cACX,MACA,CAAC,OAAO,WACE,kBAAU,OAAO,MAAM;AAE5B,IAAM,UAAU,CAAO,QAA2B,cAA0C;AACjG,SAAO,CAAC,OAAO,WAAW,UAAU,OAAO,KAAK,GAAG,OAAO,MAAM,CAAC;AACnE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-cause.d.ts","sourceRoot":"","sources":["../../src/error/error-cause.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"error-cause.d.ts","sourceRoot":"","sources":["../../src/error/error-cause.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAEjF,MAAM,MAAM,cAAc,CAAC,IAAI,GAAG,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAA;AACpF,eAAO,MAAM,cAAc,EAAE,cAAwB,CAAA;AACrD,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAAC,MAAM,CAAoB,CAAA;AAQ/E,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC/B,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,UAAU,CAErC,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,aAAa,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,SAAS,iBAAiB,KAAG,UASjD,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,KAAG,UAUpD,CAAA;AAEJ,eAAO,MAAM,QAAQ,GAAI,UAAU,iBAAiB,KAAG,UAUnD,CAAA;AAEJ,eAAO,MAAM,YAAY,GAAI,UAAU,iBAAiB,KAAG,UAUvD,CAAA;AAEJ,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,KAAG,UAUpD,CAAA;AAEJ,eAAO,MAAM,UAAU,GAAI,UAAU,iBAAiB,KAAG,UAUrD,CAAA;AAEJ,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,EAAE,UAAU,iBAAiB,KAAG,UAUvE,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/error/error-cause.ts
|
|
2
2
|
import Zod from "zod";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import * as ErrorTypes from "@bessemer/cornerstone/error/error-type";
|
|
4
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
5
5
|
import * as ErrorCodes from "@bessemer/cornerstone/error/error-code";
|
|
6
6
|
var ValueAttribute = "value";
|
|
7
7
|
var HttpStatusCodeAttribute = "httpStatusCode";
|
|
@@ -23,8 +23,8 @@ var from2 = (builder) => {
|
|
|
23
23
|
return cause;
|
|
24
24
|
};
|
|
25
25
|
var unhandled = (builder) => from2({
|
|
26
|
-
code: ErrorCodes.from({ type: Unhandled, namespace: builder?.namespace }),
|
|
27
|
-
...deepMerge(
|
|
26
|
+
code: ErrorCodes.from({ type: ErrorTypes.Unhandled, namespace: builder?.namespace }),
|
|
27
|
+
...Objects.deepMerge(
|
|
28
28
|
{
|
|
29
29
|
message: "An Unhandled Error has occurred.",
|
|
30
30
|
attributes: { [HttpStatusCodeAttribute]: 500 }
|
|
@@ -33,8 +33,8 @@ var unhandled = (builder) => from2({
|
|
|
33
33
|
)
|
|
34
34
|
});
|
|
35
35
|
var required = (builder) => from2({
|
|
36
|
-
code: ErrorCodes.from({ type: Required, namespace: builder?.namespace }),
|
|
37
|
-
...deepMerge(
|
|
36
|
+
code: ErrorCodes.from({ type: ErrorTypes.Required, namespace: builder?.namespace }),
|
|
37
|
+
...Objects.deepMerge(
|
|
38
38
|
{
|
|
39
39
|
message: "The resource is required.",
|
|
40
40
|
attributes: { [HttpStatusCodeAttribute]: 404 }
|
|
@@ -43,8 +43,8 @@ var required = (builder) => from2({
|
|
|
43
43
|
)
|
|
44
44
|
});
|
|
45
45
|
var unauthorized = (builder) => from2({
|
|
46
|
-
code: ErrorCodes.from({ type: Unauthorized, namespace: builder?.namespace }),
|
|
47
|
-
...deepMerge(
|
|
46
|
+
code: ErrorCodes.from({ type: ErrorTypes.Unauthorized, namespace: builder?.namespace }),
|
|
47
|
+
...Objects.deepMerge(
|
|
48
48
|
{
|
|
49
49
|
message: "The requested Resource requires authentication.",
|
|
50
50
|
attributes: { [HttpStatusCodeAttribute]: 401 }
|
|
@@ -53,8 +53,8 @@ var unauthorized = (builder) => from2({
|
|
|
53
53
|
)
|
|
54
54
|
});
|
|
55
55
|
var forbidden = (builder) => from2({
|
|
56
|
-
code: ErrorCodes.from({ type: Forbidden, namespace: builder?.namespace }),
|
|
57
|
-
...deepMerge(
|
|
56
|
+
code: ErrorCodes.from({ type: ErrorTypes.Forbidden, namespace: builder?.namespace }),
|
|
57
|
+
...Objects.deepMerge(
|
|
58
58
|
{
|
|
59
59
|
message: "The requested Resource requires additional permissions to access.",
|
|
60
60
|
attributes: { [HttpStatusCodeAttribute]: 403 }
|
|
@@ -63,8 +63,8 @@ var forbidden = (builder) => from2({
|
|
|
63
63
|
)
|
|
64
64
|
});
|
|
65
65
|
var badRequest = (builder) => from2({
|
|
66
|
-
code: ErrorCodes.from({ type: BadRequest, namespace: builder?.namespace }),
|
|
67
|
-
...deepMerge(
|
|
66
|
+
code: ErrorCodes.from({ type: ErrorTypes.BadRequest, namespace: builder?.namespace }),
|
|
67
|
+
...Objects.deepMerge(
|
|
68
68
|
{
|
|
69
69
|
message: "The format is invalid and cannot be processed.",
|
|
70
70
|
attributes: { [HttpStatusCodeAttribute]: 400 }
|
|
@@ -73,8 +73,8 @@ var badRequest = (builder) => from2({
|
|
|
73
73
|
)
|
|
74
74
|
});
|
|
75
75
|
var invalidValue = (value, builder) => from2({
|
|
76
|
-
code: ErrorCodes.from({ type: InvalidValue, namespace: builder?.namespace }),
|
|
77
|
-
...deepMerge(
|
|
76
|
+
code: ErrorCodes.from({ type: ErrorTypes.InvalidValue, namespace: builder?.namespace }),
|
|
77
|
+
...Objects.deepMerge(
|
|
78
78
|
{
|
|
79
79
|
message: "The format is invalid and cannot be processed.",
|
|
80
80
|
attributes: { [ValueAttribute]: value }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/error/error-cause.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/error/error-cause.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport * as ErrorTypes from '@bessemer/cornerstone/error/error-type'\nimport { Dictionary } from '@bessemer/cornerstone/types'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport { RecordAttribute } from '@bessemer/cornerstone/object'\nimport * as ErrorCodes from '@bessemer/cornerstone/error/error-code'\nimport { ErrorCode, ErrorCodeLike } from '@bessemer/cornerstone/error/error-code'\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ValueAttribute: ErrorAttribute = 'value'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nconst BaseErrorCauseSchema = Zod.object({\n code: ErrorCodes.Schema,\n message: Zod.string(),\n attributes: Zod.record(Zod.string(), Zod.unknown()),\n})\n\nexport type ErrorCause = {\n code: ErrorCode\n message: string\n attributes: Dictionary<unknown>\n causes: Array<ErrorCause>\n}\n\nexport const Schema: ZodType<ErrorCause> = BaseErrorCauseSchema.extend({\n causes: Zod.lazy(() => Zod.array(Schema)),\n})\n\nexport type ErrorCauseBuilder = {\n code: ErrorCodeLike\n message: string\n attributes?: Dictionary<unknown>\n causes?: Array<ErrorCauseBuilder>\n}\n\nexport type ErrorCauseAugment = {\n namespace?: ResourceNamespace\n message?: string\n attributes?: Dictionary<unknown>\n causes?: Array<ErrorCauseBuilder>\n}\n\nexport const from = (builder: ErrorCauseBuilder): ErrorCause => {\n const cause: ErrorCause = {\n code: ErrorCodes.from(builder.code),\n message: builder.message,\n attributes: builder.attributes ?? {},\n causes: builder.causes?.map(from) ?? [],\n }\n\n return cause\n}\n\nexport const unhandled = (builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.Unhandled, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n },\n builder\n ),\n })\n\nexport const required = (builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.Required, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'The resource is required.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n },\n builder\n ),\n })\n\nexport const unauthorized = (builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.Unauthorized, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n },\n builder\n ),\n })\n\nexport const forbidden = (builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.Forbidden, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'The requested Resource requires additional permissions to access.',\n attributes: { [HttpStatusCodeAttribute]: 403 },\n },\n builder\n ),\n })\n\nexport const badRequest = (builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.BadRequest, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'The format is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400 },\n },\n builder\n ),\n })\n\nexport const invalidValue = (value: unknown, builder?: ErrorCauseAugment): ErrorCause =>\n from({\n code: ErrorCodes.from({ type: ErrorTypes.InvalidValue, namespace: builder?.namespace }),\n ...Objects.deepMerge(\n {\n message: 'The format is invalid and cannot be processed.',\n attributes: { [ValueAttribute]: value },\n },\n builder\n ),\n })\n"],"mappings":";AAAA,OAAO,SAAsB;AAE7B,YAAY,gBAAgB;AAE5B,YAAY,aAAa;AAEzB,YAAY,gBAAgB;AAIrB,IAAM,iBAAiC;AACvC,IAAM,0BAAkD;AAE/D,IAAM,uBAAuB,IAAI,OAAO;AAAA,EACtC,MAAiB;AAAA,EACjB,SAAS,IAAI,OAAO;AAAA,EACpB,YAAY,IAAI,OAAO,IAAI,OAAO,GAAG,IAAI,QAAQ,CAAC;AACpD,CAAC;AASM,IAAMA,UAA8B,qBAAqB,OAAO;AAAA,EACrE,QAAQ,IAAI,KAAK,MAAM,IAAI,MAAMA,OAAM,CAAC;AAC1C,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AACF,CAAC;AAEI,IAAM,aAAa,CAAC,YACzBA,MAAK;AAAA,EACH,MAAiB,gBAAK,EAAE,MAAiB,uBAAY,WAAW,SAAS,UAAU,CAAC;AAAA,EACpF,GAAW;AAAA,IACT;AAAA,MACE,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAEI,IAAM,eAAe,CAAC,OAAgB,YAC3CA,MAAK;AAAA,EACH,MAAiB,gBAAK,EAAE,MAAiB,yBAAc,WAAW,SAAS,UAAU,CAAC;AAAA,EACtF,GAAW;AAAA,IACT;AAAA,MACE,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,cAAc,GAAG,MAAM;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AACF,CAAC;","names":["Schema","from"]}
|
package/dist/error/error-code.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/error/error-code.ts
|
|
2
2
|
import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
|
|
3
3
|
import Zod from "zod";
|
|
4
|
-
import
|
|
4
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
5
5
|
var Schema = Zod.string().transform((it) => it);
|
|
6
6
|
var from = (code) => {
|
|
7
|
-
if (isObject(code)) {
|
|
7
|
+
if (Objects.isObject(code)) {
|
|
8
8
|
return ResourceKeys.namespaceKey(code.type, code.namespace ?? ResourceKeys.emptyNamespace());
|
|
9
9
|
}
|
|
10
10
|
return code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/error/error-code.ts"],"sourcesContent":["import * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport { NamespacedKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorType } from '@bessemer/cornerstone/error/error-type'\nimport Zod from 'zod'\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/error/error-code.ts"],"sourcesContent":["import * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport { NamespacedKey, ResourceNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorType } from '@bessemer/cornerstone/error/error-type'\nimport Zod from 'zod'\nimport * as Objects from '@bessemer/cornerstone/object'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NamespacedKey<ErrorType>\nexport const Schema = Zod.string().transform((it) => it as NamespacedKey<ErrorType>)\n\nexport type ErrorCodeBuilder = { type: ErrorType; namespace?: ResourceNamespace }\nexport type ErrorCodeLike = ErrorCode | ErrorCodeBuilder\n\nexport const from = (code: ErrorCodeLike): ErrorCode => {\n if (Objects.isObject(code)) {\n return ResourceKeys.namespaceKey(code.type, code.namespace ?? ResourceKeys.emptyNamespace())\n }\n\n return code\n}\n\nexport const extendNamespace = (code: ErrorCode, additionalNamespace: ResourceNamespace): ErrorCode => {\n return ResourceKeys.extendNamespace(code, additionalNamespace)\n}\n\nexport const destructure = (code: ErrorCode): [ErrorType, ResourceNamespace] => {\n return ResourceKeys.destructureKey(code)\n}\n\nexport const getErrorType = (code: ErrorCode): ErrorType => {\n return ResourceKeys.getKey(code)\n}\n\nexport const getNamespace = (code: ErrorCode): ResourceNamespace => {\n return ResourceKeys.getNamespace(code)\n}\n"],"mappings":";AAAA,YAAY,kBAAkB;AAG9B,OAAO,SAAS;AAChB,YAAY,aAAa;AAQlB,IAAM,SAAS,IAAI,OAAO,EAAE,UAAU,CAAC,OAAO,EAA8B;AAK5E,IAAM,OAAO,CAAC,SAAmC;AACtD,MAAY,iBAAS,IAAI,GAAG;AAC1B,WAAoB,0BAAa,KAAK,MAAM,KAAK,aAA0B,4BAAe,CAAC;AAAA,EAC7F;AAEA,SAAO;AACT;AAEO,IAAMA,mBAAkB,CAAC,MAAiB,wBAAsD;AACrG,SAAoB,6BAAgB,MAAM,mBAAmB;AAC/D;AAEO,IAAM,cAAc,CAAC,SAAoD;AAC9E,SAAoB,4BAAe,IAAI;AACzC;AAEO,IAAM,eAAe,CAAC,SAA+B;AAC1D,SAAoB,oBAAO,IAAI;AACjC;AAEO,IAAMC,gBAAe,CAAC,SAAuC;AAClE,SAAoB,0BAAa,IAAI;AACvC;","names":["extendNamespace","getNamespace"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Dictionary, Throwable } from '@bessemer/cornerstone/types';
|
|
2
2
|
import Zod from 'zod';
|
|
3
3
|
import { LazyValue } from '@bessemer/cornerstone/lazy';
|
|
4
|
+
import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
|
|
4
5
|
import { Result } from '@bessemer/cornerstone/result';
|
|
5
6
|
import * as ErrorCauses from '@bessemer/cornerstone/error/error-cause';
|
|
6
7
|
import { ErrorCause, ErrorCauseAugment, ErrorCauseBuilder } from '@bessemer/cornerstone/error/error-cause';
|
|
7
8
|
import { MergeExclusive } from 'type-fest';
|
|
8
|
-
export declare const Namespace:
|
|
9
|
+
export declare const Namespace: ResourceKeys.ResourceNamespace<"error-event">;
|
|
9
10
|
export declare const Schema: Zod.ZodObject<{
|
|
10
|
-
_type:
|
|
11
|
+
_type: ResourceKeys.ResourceNamespace<"error-event">;
|
|
11
12
|
message: Zod.ZodString;
|
|
12
13
|
causes: Zod.ZodArray<Zod.ZodType<ErrorCauses.ErrorCause, unknown, Zod.core.$ZodTypeInternals<ErrorCauses.ErrorCause, unknown>>>;
|
|
13
14
|
context: Zod.ZodRecord<Zod.ZodString, Zod.ZodUnknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../../src/error/error-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,GAAG,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../../src/error/error-event.ts"],"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