@bessemer/cornerstone 0.5.109 → 0.5.110
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 +2 -1
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js +11 -0
- package/dist/array.js.map +1 -1
- package/dist/either.d.ts +23 -40
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +50 -88
- package/dist/either.js.map +1 -1
- package/dist/error/error-event.d.ts.map +1 -1
- package/dist/error/error-event.js +3 -2
- package/dist/error/error-event.js.map +1 -1
- package/dist/error/error.d.ts +10 -0
- package/dist/error/error.d.ts.map +1 -1
- package/dist/error/error.js +21 -2
- package/dist/error/error.js.map +1 -1
- package/dist/generators.d.ts +2 -0
- package/dist/generators.d.ts.map +1 -0
- package/dist/generators.js +14 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +2 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js.map +1 -1
- package/dist/math.d.ts +2 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +9 -1
- package/dist/math.js.map +1 -1
- package/dist/mime-type.d.ts +4 -3
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +9 -6
- package/dist/mime-type.js.map +1 -1
- package/dist/net/content-type.d.ts +21 -0
- package/dist/net/content-type.d.ts.map +1 -0
- package/dist/net/content-type.js +120 -0
- package/dist/net/content-type.js.map +1 -0
- package/dist/net/fetch.d.ts +18 -0
- package/dist/net/fetch.d.ts.map +1 -0
- package/dist/net/fetch.js +65 -0
- package/dist/net/fetch.js.map +1 -0
- package/dist/net/http-method.d.ts +18 -0
- package/dist/net/http-method.d.ts.map +1 -0
- package/dist/net/http-method.js +37 -0
- package/dist/net/http-method.js.map +1 -0
- package/dist/net/http-request.d.ts +12 -0
- package/dist/net/http-request.d.ts.map +1 -0
- package/dist/net/http-request.js +1 -0
- package/dist/net/http-request.js.map +1 -0
- package/dist/net/uri-host-name.d.ts +1 -1
- package/dist/net/uri-host-name.d.ts.map +1 -1
- package/dist/net/uri-host-name.js +6 -6
- package/dist/net/uri-host-name.js.map +1 -1
- package/dist/net/uri.d.ts +12 -4
- package/dist/net/uri.d.ts.map +1 -1
- package/dist/net/uri.js +87 -36
- package/dist/net/uri.js.map +1 -1
- package/dist/net/url.d.ts +9 -6
- package/dist/net/url.d.ts.map +1 -1
- package/dist/net/url.js +58 -21
- package/dist/net/url.js.map +1 -1
- package/dist/object/object-diff.d.ts.map +1 -1
- package/dist/object/object-diff.js.map +1 -1
- package/dist/object/type-path.d.ts.map +1 -1
- package/dist/object/type-path.js +12 -14
- package/dist/object/type-path.js.map +1 -1
- package/dist/object.d.ts +2 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +17 -1
- package/dist/object.js.map +1 -1
- package/dist/promise.d.ts +3 -1
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +9 -0
- package/dist/promise.js.map +1 -1
- package/dist/proxy.d.ts +2 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +20 -0
- package/dist/proxy.js.map +1 -0
- package/dist/result.d.ts +18 -20
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +41 -61
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +3 -3
- package/dist/retry.js.map +1 -1
- package/dist/sql/sql-expression-parser.d.ts.map +1 -1
- package/dist/sql/sql-expression-parser.js +5 -5
- package/dist/sql/sql-expression-parser.js.map +1 -1
- package/dist/string.d.ts +1 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +4 -0
- package/dist/string.js.map +1 -1
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +2 -1
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +2 -1
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +2 -1
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +2 -1
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +2 -1
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts.map +1 -1
- package/dist/temporal/zoned-date-time.js +2 -1
- package/dist/temporal/zoned-date-time.js.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -1
- package/dist/zod-util.d.ts +55 -6
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +99 -11
- package/dist/zod-util.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/sql/sql-expression-parser.ts
|
|
2
2
|
import { ExpressionMapper } from "@bessemer/cornerstone/expression/expression-mapper";
|
|
3
|
-
import { Arrays, Eithers, Entries, Objects, Ulids } from "@bessemer/cornerstone";
|
|
3
|
+
import { Arrays, Eithers, Entries, Objects, Results, Ulids } from "@bessemer/cornerstone";
|
|
4
4
|
import {
|
|
5
5
|
AndExpression,
|
|
6
6
|
ContainsExpression,
|
|
@@ -21,10 +21,10 @@ var SqlExpressionParser = class extends ExpressionMapper {
|
|
|
21
21
|
var resolveContainsExpression = (expression, map, context, invert = false) => {
|
|
22
22
|
const collection = expression.collection;
|
|
23
23
|
const parsedValue = getValue(collection);
|
|
24
|
-
if (
|
|
24
|
+
if (Results.isFailure(parsedValue)) {
|
|
25
25
|
throw new Error(`SqlExpressionParser - Unable to resolve ContainsExpression with non-value collection: ${JSON.stringify(collection)}`);
|
|
26
26
|
}
|
|
27
|
-
const value = parsedValue
|
|
27
|
+
const value = parsedValue;
|
|
28
28
|
if (Arrays.isEmpty(value)) {
|
|
29
29
|
return invert ? "(1 = 1)" : "(1 = 0)";
|
|
30
30
|
}
|
|
@@ -88,8 +88,8 @@ DefaultSqlExpressionParser.register(EqualsExpression, (expression, map) => {
|
|
|
88
88
|
const mappedFirst = map(first);
|
|
89
89
|
const equalsExpressions = rest.map((it) => {
|
|
90
90
|
const parsedValue = getValue(it);
|
|
91
|
-
if (
|
|
92
|
-
if (parsedValue
|
|
91
|
+
if (Results.isSuccess(parsedValue)) {
|
|
92
|
+
if (parsedValue === null) {
|
|
93
93
|
return `(${mappedFirst} IS NULL)`;
|
|
94
94
|
} else {
|
|
95
95
|
return `(${mappedFirst} = ${map(it)})`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sql/sql-expression-parser.ts"],"sourcesContent":["import { ExpressionMapper } from '@bessemer/cornerstone/expression/expression-mapper'\nimport { Arrays, Eithers, Entries, Objects, Ulids } from '@bessemer/cornerstone'\nimport { BasicType, Dictionary } from '@bessemer/cornerstone/types'\nimport {\n AndExpression,\n ContainsExpression,\n EqualsExpression,\n getValue,\n GreaterThanExpression,\n GreaterThanOrEqualExpression,\n LessThanExpression,\n LessThanOrEqualExpression,\n NotExpression,\n OrExpression,\n ValueExpression,\n VariableExpression,\n} from '@bessemer/cornerstone/expression/core-expression'\nimport { isType } from '@bessemer/cornerstone/expression/internal'\nimport { SqlFragment, SqlParameterMap } from '@bessemer/cornerstone/sql'\nimport { Expression } from '@bessemer/cornerstone/expression'\n\nexport type SqlExpressionParserContext = {\n variables: Dictionary<string>\n parameters: SqlParameterMap\n}\nexport class SqlExpressionParser extends ExpressionMapper<SqlFragment, SqlExpressionParserContext> {}\n\nconst resolveContainsExpression = (\n // JOHN should be easier to define this type\n expression: ReturnType<typeof ContainsExpression.builder>,\n map: (expression: Expression<unknown>) => SqlFragment,\n context: SqlExpressionParserContext,\n invert = false\n) => {\n const collection = expression.collection\n\n const parsedValue = getValue(collection)\n if (
|
|
1
|
+
{"version":3,"sources":["../../src/sql/sql-expression-parser.ts"],"sourcesContent":["import { ExpressionMapper } from '@bessemer/cornerstone/expression/expression-mapper'\nimport { Arrays, Eithers, Entries, Objects, Results, Ulids } from '@bessemer/cornerstone'\nimport { BasicType, Dictionary } from '@bessemer/cornerstone/types'\nimport {\n AndExpression,\n ContainsExpression,\n EqualsExpression,\n getValue,\n GreaterThanExpression,\n GreaterThanOrEqualExpression,\n LessThanExpression,\n LessThanOrEqualExpression,\n NotExpression,\n OrExpression,\n ValueExpression,\n VariableExpression,\n} from '@bessemer/cornerstone/expression/core-expression'\nimport { isType } from '@bessemer/cornerstone/expression/internal'\nimport { SqlFragment, SqlParameterMap } from '@bessemer/cornerstone/sql'\nimport { Expression } from '@bessemer/cornerstone/expression'\n\nexport type SqlExpressionParserContext = {\n variables: Dictionary<string>\n parameters: SqlParameterMap\n}\nexport class SqlExpressionParser extends ExpressionMapper<SqlFragment, SqlExpressionParserContext> {}\n\nconst resolveContainsExpression = (\n // JOHN should be easier to define this type\n expression: ReturnType<typeof ContainsExpression.builder>,\n map: (expression: Expression<unknown>) => SqlFragment,\n context: SqlExpressionParserContext,\n invert = false\n) => {\n const collection = expression.collection\n\n const parsedValue = getValue(collection)\n if (Results.isFailure(parsedValue)) {\n throw new Error(`SqlExpressionParser - Unable to resolve ContainsExpression with non-value collection: ${JSON.stringify(collection)}`)\n }\n\n const value = parsedValue as Array<BasicType | null>\n if (Arrays.isEmpty(value)) {\n return invert ? '(1 = 1)' : '(1 = 0)'\n }\n\n value.forEach((it) => {\n if (it !== null && !Objects.isBasic(it)) {\n throw new Error(`SqlExpressionParser - Unable to resolve complex ValueExpression as Sql: ${JSON.stringify(it)}`)\n }\n })\n\n const [nonNullValues, nullValues] = Arrays.bisect(value, (it) => (it !== null ? Eithers.left(it) : Eithers.right(null)))\n const parameters = nonNullValues.map((it) => Entries.of(`_${Ulids.generate()}`, it))\n parameters.forEach(([key, value]) => {\n context.parameters[key] = value\n })\n\n const containsExpression = expression.operands\n .map(map)\n .map((sql) => {\n const conditions = []\n\n if (!Arrays.isEmpty(parameters)) {\n conditions.push(\n `(${sql} ${invert ? 'NOT IN' : 'IN'} (${Entries.keys(parameters)\n .map((it) => `:${it}`)\n .join(',')}))`\n )\n }\n\n if (!Arrays.isEmpty(nullValues)) {\n conditions.push(`(${sql} ${invert ? 'IS NOT' : 'IS'} NULL)`)\n }\n\n return `(${conditions.join(' OR ')})`\n })\n .join(' AND ')\n\n return `(${containsExpression})`\n}\n\nexport const DefaultSqlExpressionParser = new SqlExpressionParser()\nDefaultSqlExpressionParser.register(ValueExpression, (expression, _, context) => {\n const value = expression.value\n const parameterName = `_${Ulids.generate()}`\n if (value === null) {\n throw new Error(`SqlExpressionParser - Unable to resolve null ValueExpression as Sql`)\n }\n if (!Objects.isBasic(value)) {\n throw new Error(`SqlExpressionParser - Unable to resolve complex ValueExpression as Sql: ${JSON.stringify(value)}`)\n }\n\n context.parameters[parameterName] = value\n return `:${parameterName}`\n})\nDefaultSqlExpressionParser.register(VariableExpression, (expression, _, context) => {\n const variableName = context.variables[expression.name]\n return variableName ?? expression.name\n})\nDefaultSqlExpressionParser.register(NotExpression, (expression, map, context) => {\n if (isType(expression.value, ContainsExpression)) {\n return resolveContainsExpression(expression.value, map, context, true)\n } else {\n return `(NOT ${map(expression.value)})`\n }\n})\nDefaultSqlExpressionParser.register(AndExpression, (expression, map) => {\n return `(${expression.operands.map(map).join(' AND ')})`\n})\nDefaultSqlExpressionParser.register(OrExpression, (expression, map) => {\n return `(${expression.operands.map(map).join(' OR ')})`\n})\nDefaultSqlExpressionParser.register(EqualsExpression, (expression, map) => {\n const first = Arrays.first(expression.operands)!\n const rest = Arrays.rest(expression.operands)\n\n const mappedFirst = map(first)\n const equalsExpressions = rest\n .map((it) => {\n const parsedValue = getValue(it)\n if (Results.isSuccess(parsedValue)) {\n if (parsedValue === null) {\n return `(${mappedFirst} IS NULL)`\n } else {\n return `(${mappedFirst} = ${map(it)})`\n }\n } else {\n return `(${mappedFirst} = ${map(it)})`\n }\n })\n .join(' AND ')\n return `(${equalsExpressions})`\n})\nDefaultSqlExpressionParser.register(ContainsExpression, resolveContainsExpression)\nDefaultSqlExpressionParser.register(LessThanExpression, (expression, map) => {\n return `(${map(expression.left)} < ${map(expression.right)})`\n})\nDefaultSqlExpressionParser.register(LessThanOrEqualExpression, (expression, map) => {\n return `(${map(expression.left)} <= ${map(expression.right)})`\n})\nDefaultSqlExpressionParser.register(GreaterThanExpression, (expression, map) => {\n return `(${map(expression.left)} > ${map(expression.right)})`\n})\nDefaultSqlExpressionParser.register(GreaterThanOrEqualExpression, (expression, map) => {\n return `(${map(expression.left)} >= ${map(expression.right)})`\n})\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,QAAQ,SAAS,SAAS,SAAS,SAAS,aAAa;AAElE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AAQhB,IAAM,sBAAN,cAAkC,iBAA0D;AAAC;AAEpG,IAAM,4BAA4B,CAEhC,YACA,KACA,SACA,SAAS,UACN;AACH,QAAM,aAAa,WAAW;AAE9B,QAAM,cAAc,SAAS,UAAU;AACvC,MAAI,QAAQ,UAAU,WAAW,GAAG;AAClC,UAAM,IAAI,MAAM,yFAAyF,KAAK,UAAU,UAAU,CAAC,EAAE;AAAA,EACvI;AAEA,QAAM,QAAQ;AACd,MAAI,OAAO,QAAQ,KAAK,GAAG;AACzB,WAAO,SAAS,YAAY;AAAA,EAC9B;AAEA,QAAM,QAAQ,CAAC,OAAO;AACpB,QAAI,OAAO,QAAQ,CAAC,QAAQ,QAAQ,EAAE,GAAG;AACvC,YAAM,IAAI,MAAM,2EAA2E,KAAK,UAAU,EAAE,CAAC,EAAE;AAAA,IACjH;AAAA,EACF,CA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2B,SAAS,oBAAoB,yBAAyB;AACjF,2BAA2B,SAAS,oBAAoB,CAAC,YAAY,QAAQ;AAC3E,SAAO,IAAI,IAAI,WAAW,IAAI,CAAC,MAAM,IAAI,WAAW,KAAK,CAAC;AAC5D,CAAC;AACD,2BAA2B,SAAS,2BAA2B,CAAC,YAAY,QAAQ;AAClF,SAAO,IAAI,IAAI,WAAW,IAAI,CAAC,OAAO,IAAI,WAAW,KAAK,CAAC;AAC7D,CAAC;AACD,2BAA2B,SAAS,uBAAuB,CAAC,YAAY,QAAQ;AAC9E,SAAO,IAAI,IAAI,WAAW,IAAI,CAAC,MAAM,IAAI,WAAW,KAAK,CAAC;AAC5D,CAAC;AACD,2BAA2B,SAAS,8BAA8B,CAAC,YAAY,QAAQ;AACrF,SAAO,IAAI,IAAI,WAAW,IAAI,CAAC,OAAO,IAAI,WAAW,KAAK,CAAC;AAC7D,CAAC;","names":["value"]}
|
package/dist/string.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare const replacePlaceholders: (string: string, parameters: UnknownRe
|
|
|
24
24
|
export declare const padStart: (str: string, length: number, chars: string) => string;
|
|
25
25
|
export declare const padEnd: (str: string, length: number, chars: string) => string;
|
|
26
26
|
export declare const isNumber: (value: string) => boolean;
|
|
27
|
+
export declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
|
|
27
28
|
export declare namespace Schema {
|
|
28
29
|
}
|
|
29
30
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAKzC,eAAO,MAAM,QAAQ,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,MAE9C,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,KAAG,OAEvC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI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OAAO,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAEnE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAM/D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAM7D,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,GAAG,IA2B5E,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,YAAY,aAAa,EAAE,uBAAuB,WAAW,MAAM,WAAuB,WAK7I,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MASrE,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MASnE,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAOxC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,EAAE,KAAK,CAAC,KAAG,UAAU,CAAC,CAAC,CAEjE,CAAA;AAED,yBAAiB,MAAM,CAAC;CAMvB"}
|
package/dist/string.js
CHANGED
|
@@ -155,6 +155,9 @@ var isNumber = (value) => {
|
|
|
155
155
|
const num = Number(value);
|
|
156
156
|
return !isNaN(num) && isFinite(num);
|
|
157
157
|
};
|
|
158
|
+
var capitalize = (str) => {
|
|
159
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
160
|
+
};
|
|
158
161
|
var Schema;
|
|
159
162
|
((Schema2) => {
|
|
160
163
|
const Text = Zod.string().trim().min(1);
|
|
@@ -162,6 +165,7 @@ var Schema;
|
|
|
162
165
|
})(Schema || (Schema = {}));
|
|
163
166
|
export {
|
|
164
167
|
Schema,
|
|
168
|
+
capitalize,
|
|
165
169
|
emptyToNull,
|
|
166
170
|
isBlank,
|
|
167
171
|
isEmpty,
|
package/dist/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["import { UnknownRecord } from 'type-fest'\nimport { rest } from '@bessemer/cornerstone/array'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport Zod from 'zod'\n\nexport const isString = (value: any): value is string => {\n return typeof value === 'string'\n}\n\nexport const isEmpty = (value: string): boolean => {\n return value.length === 0\n}\n\nexport const isEmptyOrNil = (value: string | null | undefined): boolean => {\n if (isNil(value)) {\n return true\n }\n\n return isEmpty(value)\n}\n\nexport const emptyToNull = (value: string): string | null => {\n if (isEmptyOrNil(value)) {\n return null\n }\n\n return value\n}\n\nexport const isBlank = (str?: string | null): boolean => {\n const testStr = str ?? ''\n return /^\\s*$/.test(testStr)\n}\n\nexport type StringSplitResult = { selection: string; separator: string; rest: string } | { selection: null; separator: null; rest: string }\n\nexport const splitFirst = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[0]!, separator: splitter, rest: rest(results).join(splitter) }\n } else {\n const match = splitter.exec(str)\n\n if (!match) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = match.index\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + match[0].length)\n const separator = match[0]\n return { selection: beforeMatch, separator, rest: afterMatch }\n }\n}\n\nexport const splitLast = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[results.length - 1]!, separator: splitter, rest: results.slice(0, results.length - 1).join(splitter) }\n } else {\n if (!splitter.global) {\n splitter = new RegExp(splitter.source, splitter.flags + 'g')\n }\n\n const matches = Array.from(str.matchAll(splitter))\n\n if (matches.length === 0) {\n return { selection: null, separator: null, rest: str }\n }\n\n // Use the last match\n const lastMatch = matches[matches.length - 1]!\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]!\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator: separator,\n rest: beforeMatch,\n }\n }\n}\n\nexport const splitLastRegex = (str: string, regex: RegExp): StringSplitResult => {\n // Find the last match using regex lastIndex\n let lastMatch: RegExpExecArray | null = null\n let match\n\n while ((match = regex.exec(str)) !== null) {\n lastMatch = match\n }\n\n if (!lastMatch) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator,\n rest: beforeMatch,\n }\n}\n\nexport const splitAt = (str: string, index: number): [string, string] => {\n return [str.slice(0, index), str.slice(index)] as const\n}\n\nexport const removeStart = (string: string, substring: string): string => {\n if (!string.startsWith(substring)) {\n return string\n }\n\n return string.slice(substring.length)\n}\n\nexport const removeEnd = (string: string, substring: string): string => {\n if (!string.endsWith(substring)) {\n return string\n }\n\n return string.slice(0, -substring.length)\n}\n\nexport const mostCentralOccurrence = (str: string, substr: string): number | null => {\n const occurrences: number[] = []\n let index = str.indexOf(substr)\n\n while (index !== -1) {\n occurrences.push(index)\n index = str.indexOf(substr, index + 1)\n }\n\n if (occurrences.length === 0) {\n return null\n }\n\n const center = str.length / 2\n\n let closestIndex = occurrences[0]!\n let minDistance = Math.abs(center - closestIndex)\n\n for (let i = 1; i < occurrences.length; i++) {\n const distance = Math.abs(center - occurrences[i]!)\n if (distance < minDistance) {\n minDistance = distance\n closestIndex = occurrences[i]!\n }\n }\n\n return closestIndex\n}\n\nexport const replacePlaceholders = (string: string, parameters: UnknownRecord, getParamPlaceholder = (paramName: string) => `{{${paramName}}}`) => {\n return Object.entries(parameters).reduce(\n (intermediateString, [paramName, paramValue]) => intermediateString.replaceAll(getParamPlaceholder(paramName), `${paramValue}`),\n string\n )\n}\n\nexport const padStart = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return padString.slice(0, padLength) + str\n}\n\nexport const padEnd = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return str + padString.slice(0, padLength)\n}\n\nexport const isNumber = (value: string): boolean => {\n if (value.trim() === '') {\n return false\n }\n\n const num = Number(value)\n return !isNaN(num) && isFinite(num)\n}\n\nexport namespace Schema {\n const Text = Zod.string().trim().min(1)\n\n const TextNullable = Zod.string()\n .trim()\n .transform((val) => (isEmpty(val) ? null : val))\n}\n"],"mappings":";AACA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,OAAO,SAAS;AAET,IAAM,WAAW,CAAC,UAAgC;AACvD,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,UAAU,CAAC,UAA2B;AACjD,SAAO,MAAM,WAAW;AAC1B;AAEO,IAAM,eAAe,CAAC,UAA8C;AACzE,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,KAAK;AACtB;AAEO,IAAM,cAAc,CAAC,UAAiC;AAC3D,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,UAAU,CAAC,QAAiC;AACvD,QAAM,UAAU,OAAO;AACvB,SAAO,QAAQ,KAAK,OAAO;AAC7B;AAIO,IAAM,aAAa,CAAC,KAAa,aAAiD;AACvF,MAAI,SAAS,QAAQ,GAAG;AACtB,UAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,QAAI,QAAQ,WAAW,GAAG;AACxB,aAAO,EAAE,WAAW,MAAM,WAAW,MAAM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AM,OAAO,KAAK;AACxB,SAAO,CAAC,MAAM,GAAG,KAAK,SAAS,GAAG;AACpC;AAEO,IAAU;AAAA,CAAV,CAAUA,YAAV;AACL,QAAM,OAAO,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;AAEtC,QAAM,eAAe,IAAI,OAAO,EAC7B,KAAK,EACL,UAAU,CAAC,QAAS,QAAQ,GAAG,IAAI,OAAO,GAAI;AAAA,GALlC;","names":["Schema"]}
|
|
1
|
+
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["import { UnknownRecord } from 'type-fest'\nimport { rest } from '@bessemer/cornerstone/array'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport Zod from 'zod'\n\nexport const isString = (value: any): value is string => {\n return typeof value === 'string'\n}\n\nexport const isEmpty = (value: string): boolean => {\n return value.length === 0\n}\n\nexport const isEmptyOrNil = (value: string | null | undefined): boolean => {\n if (isNil(value)) {\n return true\n }\n\n return isEmpty(value)\n}\n\nexport const emptyToNull = (value: string): string | null => {\n if (isEmptyOrNil(value)) {\n return null\n }\n\n return value\n}\n\nexport const isBlank = (str?: string | null): boolean => {\n const testStr = str ?? ''\n return /^\\s*$/.test(testStr)\n}\n\nexport type StringSplitResult = { selection: string; separator: string; rest: string } | { selection: null; separator: null; rest: string }\n\nexport const splitFirst = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[0]!, separator: splitter, rest: rest(results).join(splitter) }\n } else {\n const match = splitter.exec(str)\n\n if (!match) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = match.index\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + match[0].length)\n const separator = match[0]\n return { selection: beforeMatch, separator, rest: afterMatch }\n }\n}\n\nexport const splitLast = (str: string, splitter: string | RegExp): StringSplitResult => {\n if (isString(splitter)) {\n const results = str.split(splitter)\n if (results.length === 1) {\n return { selection: null, separator: null, rest: str }\n }\n\n return { selection: results[results.length - 1]!, separator: splitter, rest: results.slice(0, results.length - 1).join(splitter) }\n } else {\n if (!splitter.global) {\n splitter = new RegExp(splitter.source, splitter.flags + 'g')\n }\n\n const matches = Array.from(str.matchAll(splitter))\n\n if (matches.length === 0) {\n return { selection: null, separator: null, rest: str }\n }\n\n // Use the last match\n const lastMatch = matches[matches.length - 1]!\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]!\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator: separator,\n rest: beforeMatch,\n }\n }\n}\n\nexport const splitLastRegex = (str: string, regex: RegExp): StringSplitResult => {\n // Find the last match using regex lastIndex\n let lastMatch: RegExpExecArray | null = null\n let match\n\n while ((match = regex.exec(str)) !== null) {\n lastMatch = match\n }\n\n if (!lastMatch) {\n return { selection: null, separator: null, rest: str }\n }\n\n const matchIndex = lastMatch.index!\n const separator = lastMatch[0]\n const beforeMatch = str.slice(0, matchIndex)\n const afterMatch = str.slice(matchIndex + separator.length)\n\n return {\n selection: afterMatch,\n separator,\n rest: beforeMatch,\n }\n}\n\nexport const splitAt = (str: string, index: number): [string, string] => {\n return [str.slice(0, index), str.slice(index)] as const\n}\n\nexport const removeStart = (string: string, substring: string): string => {\n if (!string.startsWith(substring)) {\n return string\n }\n\n return string.slice(substring.length)\n}\n\nexport const removeEnd = (string: string, substring: string): string => {\n if (!string.endsWith(substring)) {\n return string\n }\n\n return string.slice(0, -substring.length)\n}\n\nexport const mostCentralOccurrence = (str: string, substr: string): number | null => {\n const occurrences: number[] = []\n let index = str.indexOf(substr)\n\n while (index !== -1) {\n occurrences.push(index)\n index = str.indexOf(substr, index + 1)\n }\n\n if (occurrences.length === 0) {\n return null\n }\n\n const center = str.length / 2\n\n let closestIndex = occurrences[0]!\n let minDistance = Math.abs(center - closestIndex)\n\n for (let i = 1; i < occurrences.length; i++) {\n const distance = Math.abs(center - occurrences[i]!)\n if (distance < minDistance) {\n minDistance = distance\n closestIndex = occurrences[i]!\n }\n }\n\n return closestIndex\n}\n\nexport const replacePlaceholders = (string: string, parameters: UnknownRecord, getParamPlaceholder = (paramName: string) => `{{${paramName}}}`) => {\n return Object.entries(parameters).reduce(\n (intermediateString, [paramName, paramValue]) => intermediateString.replaceAll(getParamPlaceholder(paramName), `${paramValue}`),\n string\n )\n}\n\nexport const padStart = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return padString.slice(0, padLength) + str\n}\n\nexport const padEnd = (str: string, length: number, chars: string): string => {\n if (str.length >= length) {\n return str\n }\n\n const padLength = length - str.length\n const padString = chars.repeat(Math.ceil(padLength / chars.length))\n\n return str + padString.slice(0, padLength)\n}\n\nexport const isNumber = (value: string): boolean => {\n if (value.trim() === '') {\n return false\n }\n\n const num = Number(value)\n return !isNaN(num) && isFinite(num)\n}\n\nexport const capitalize = <T extends string>(str: T): Capitalize<T> => {\n return (str.charAt(0).toUpperCase() + str.slice(1)) as Capitalize<T>\n}\n\nexport namespace Schema {\n const Text = Zod.string().trim().min(1)\n\n const TextNullable = Zod.string()\n .trim()\n .transform((val) => (isEmpty(val) ? null : val))\n}\n"],"mappings":";AACA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,OAAO,SAAS;AAET,IAAM,WAAW,CAAC,UAAgC;AACvD,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,UAAU,CAAC,UAA2B;AACjD,SAAO,MAAM,WAAW;AAC1B;AAEO,IAAM,eAAe,CAAC,UAA8C;AACzE,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,KAAK;AACtB;AAEO,IAAM,cAAc,CAAC,UAAiC;AAC3D,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,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AA,EACT;AAEA,QAAM,YAAY,SAAS,IAAI;AAC/B,QAAM,YAAY,MAAM,OAAO,KAAK,KAAK,YAAY,MAAM,MAAM,CAAC;AAElE,SAAO,MAAM,UAAU,MAAM,GAAG,SAAS;AAC3C;AAEO,IAAM,WAAW,CAAC,UAA2B;AAClD,MAAI,MAAM,KAAK,MAAM,IAAI;AACvB,WAAO;AAAA,EACT;AAEA,QAAM,MAAM,OAAO,KAAK;AACxB,SAAO,CAAC,MAAM,GAAG,KAAK,SAAS,GAAG;AACpC;AAEO,IAAM,aAAa,CAAmB,QAA0B;AACrE,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AACnD;AAEO,IAAU;AAAA,CAAV,CAAUA,YAAV;AACL,QAAM,OAAO,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC;AAEtC,QAAM,eAAe,IAAI,OAAO,EAC7B,KAAK,EACL,UAAU,CAAC,QAAS,QAAQ,GAAG,IAAI,OAAO,GAAI;AAAA,GALlC;","names":["Schema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/temporal/duration.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/temporal/duration.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAI7D,OAAO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AAED,eAAO,MAAM,MAAM,GAAI,UAAU,YAAY,KAAG,OAE/C,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,SAAS,YAAY,EAAE,MAAM,QAAQ,KAAG,QAE7D,CAAA;AAED,eAAO,MAAM,GAAG,GAAI,GAAG,WAAW,KAAK,CAAC,YAAY,CAAC,KAAG,QAEvD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,GAAG,WAAW,KAAK,CAAC,YAAY,CAAC,KAAG,QAO5D,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,KAAG,QAE9C,CAAA;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAA;AAC5E,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAA;AAC1F,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,EAAE,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAAA;AASpG,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,EAAE,OAAO,YAAY,KAAG,OAEnE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,YAAY,EAAE,OAAO,YAAY,KAAG,OAEtE,CAAA;AAED,eAAO,MAAM,IAAI,mBAA2B,CAAA;AAC5C,eAAO,MAAM,cAAc,mBAAsB,CAAA;AACjD,eAAO,MAAM,SAAS,mBAAiB,CAAA;AACvC,eAAO,MAAM,SAAS,mBAAiB,CAAA;AACvC,eAAO,MAAM,OAAO,mBAAe,CAAA;AACnC,eAAO,MAAM,MAAM,mBAAgB,CAAA"}
|
|
@@ -4,6 +4,7 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
4
4
|
import { createNamespace } from "@bessemer/cornerstone/resource-key";
|
|
5
5
|
import { fromComparator } from "@bessemer/cornerstone/equalitor";
|
|
6
6
|
import { structuredTransform } from "@bessemer/cornerstone/zod-util";
|
|
7
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
7
8
|
import { failure, success } from "@bessemer/cornerstone/result";
|
|
8
9
|
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
|
9
10
|
import { isError } from "@bessemer/cornerstone/error/error";
|
|
@@ -41,7 +42,7 @@ function toLiteral(value) {
|
|
|
41
42
|
}
|
|
42
43
|
return from(value).toString();
|
|
43
44
|
}
|
|
44
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString(it)
|
|
45
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString(it), (it2) => toLiteral(it2)));
|
|
45
46
|
var SchemaInstance = structuredTransform(Zod.string(), parseString);
|
|
46
47
|
var isDuration = (value) => {
|
|
47
48
|
return value instanceof Temporal.Duration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/temporal/duration.ts"],"sourcesContent":["import Zod from 'zod'\nimport { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\n\nexport type Duration = Temporal.Duration\nexport const Namespace = createNamespace('duration')\nexport type DurationLiteral = NominalType<string, typeof Namespace>\nexport type DurationBuilder = {\n hours?: number\n minutes?: number\n seconds?: number\n milliseconds?: number\n microseconds?: number\n nanoseconds?: number\n}\nexport type DurationLike = Duration | DurationLiteral | DurationBuilder\n\nexport function from(value: DurationLike | string): Duration\nexport function from(value: DurationLike | string | null): Duration | null\nexport function from(value: DurationLike | string | undefined): Duration | undefined\nexport function from(value: DurationLike | string | null | undefined): Duration | null | undefined\nexport function from(value: DurationLike | string | null | undefined): Duration | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Duration) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.Duration.from(value)\n}\n\nexport const CompareBy: Comparator<Duration> = (first: Duration, second: Duration): number => Temporal.Duration.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Duration, ErrorEvent> => {\n try {\n return success(Temporal.Duration.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport function toLiteral(value: DurationLike): DurationLiteral\nexport function toLiteral(value: DurationLike | null): DurationLiteral | null\nexport function toLiteral(value: DurationLike | undefined): DurationLiteral | undefined\nexport function toLiteral(value: DurationLike | null | undefined): DurationLiteral | null | undefined\nexport function toLiteral(value: DurationLike | null | undefined): DurationLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return from(value).toString() as DurationLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it).map((it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isDuration = (value: unknown): value is Duration => {\n return value instanceof Temporal.Duration\n}\n\nexport const merge = (element: DurationLike, builder: DurationBuilder): Duration => {\n return from(element).with(builder)\n}\n\nexport const fromMilliseconds = (value: number): Duration => {\n return from({ milliseconds: value })\n}\n\nexport const toMilliseconds = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Millisecond)\n}\n\nexport const fromSeconds = (value: number): Duration => {\n return from({ seconds: value })\n}\n\nexport const toSeconds = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Second)\n}\n\nexport const fromMinutes = (value: number): Duration => {\n return from({ minutes: value })\n}\n\nexport const toMinutes = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Minute)\n}\n\nexport const fromHours = (value: number): Duration => {\n return from({ hours: value })\n}\n\nexport const toHours = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Hour)\n}\n\nexport const fromUnit = (value: number, timeUnit: TimeUnit): Duration => {\n switch (timeUnit) {\n case TimeUnit.Nanosecond:\n return from({ nanoseconds: value })\n case TimeUnit.Microsecond:\n return from({ microseconds: value })\n case TimeUnit.Millisecond:\n return from({ milliseconds: value })\n case TimeUnit.Second:\n return from({ seconds: value })\n case TimeUnit.Minute:\n return from({ minutes: value })\n case TimeUnit.Hour:\n return from({ hours: value })\n }\n}\n\nexport const toUnit = (duration: DurationLike, timeUnit: TimeUnit): number => {\n return from(duration).total(timeUnit)\n}\n\nexport const isZero = (duration: DurationLike): boolean => {\n return EqualBy(from(duration), Zero)\n}\n\nexport const round = (element: DurationLike, unit: TimeUnit): Duration => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport const add = (...durations: Array<DurationLike>): Duration => {\n return durations.map((it) => from(it)).reduce((first, second) => first.add(second), Zero)\n}\n\nexport const subtract = (...durations: Array<DurationLike>): Duration => {\n if (durations.length === 0) {\n return Zero\n }\n\n const instances = durations.map((it) => from(it))\n return instances.slice(1).reduce((result, current) => result.subtract(current), instances[0]!)\n}\n\nexport const negate = (element: DurationLike): Duration => {\n return from(element).negated()\n}\n\nexport function isEqual(element: DurationLike, other: DurationLike): boolean\nexport function isEqual(element: DurationLike | null, other: DurationLike | null): boolean\nexport function isEqual(element: DurationLike | undefined, other: DurationLike | undefined): boolean\nexport function isEqual(element: DurationLike | null | undefined, other: DurationLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isLess = (element: DurationLike, other: DurationLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isGreater = (element: DurationLike, other: DurationLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport const Zero = from({ nanoseconds: 0 })\nexport const OneMillisecond = fromMilliseconds(1)\nexport const OneSecond = fromSeconds(1)\nexport const OneMinute = fromMinutes(1)\nexport const OneHour = fromHours(1)\nexport const OneDay = fromHours(24)\n"],"mappings":";AAAA,OAAO,SAAS;AAChB,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAGhC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAGf,IAAM,YAAY,gBAAgB,UAAU;AAgB5C,SAAS,KAAK,OAA8E;AACjG,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,UAAU;AACtC,WAAO;AAAA,EACT;AACA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,aAAa,YAAY,KAAK,CAAC;AAAA,EACxC;AAEA,SAAO,SAAS,SAAS,KAAK,KAAK;AACrC;AAEO,IAAM,YAAkC,CAAC,OAAiB,WAA6B,SAAS,SAAS,QAAQ,OAAO,MAAM;AAC9H,IAAM,UAAU,eAAe,SAAS;AAExC,IAAM,cAAc,CAAC,UAAgD;AAC1E,MAAI;AACF,WAAO,QAAQ,SAAS,SAAS,KAAK,KAAK,CAAC;AAAA,EAC9C,SAAS,GAAG;AACV,QAAI,CAAC,QAAQ,CAAC,GAAG;AACf,YAAM;AAAA,IACR;AAEA,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,EAClF;AACF;AAMO,SAAS,UAAU,OAA4E;AACpG,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,KAAK,EAAE,SAAS;AA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AAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,YAAY,CAAC,SAAuB,UAAiC;AAChF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,OAAO,KAAK,EAAE,aAAa,EAAE,CAAC;AACpC,IAAM,iBAAiB,iBAAiB,CAAC;AACzC,IAAM,YAAY,YAAY,CAAC;AAC/B,IAAM,YAAY,YAAY,CAAC;AAC/B,IAAM,UAAU,UAAU,CAAC;AAC3B,IAAM,SAAS,UAAU,EAAE;","names":["it"]}
|
|
1
|
+
{"version":3,"sources":["../../src/temporal/duration.ts"],"sourcesContent":["import Zod from 'zod'\nimport { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\n\nexport type Duration = Temporal.Duration\nexport const Namespace = createNamespace('duration')\nexport type DurationLiteral = NominalType<string, typeof Namespace>\nexport type DurationBuilder = {\n hours?: number\n minutes?: number\n seconds?: number\n milliseconds?: number\n microseconds?: number\n nanoseconds?: number\n}\nexport type DurationLike = Duration | DurationLiteral | DurationBuilder\n\nexport function from(value: DurationLike | string): Duration\nexport function from(value: DurationLike | string | null): Duration | null\nexport function from(value: DurationLike | string | undefined): Duration | undefined\nexport function from(value: DurationLike | string | null | undefined): Duration | null | undefined\nexport function from(value: DurationLike | string | null | undefined): Duration | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Duration) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.Duration.from(value)\n}\n\nexport const CompareBy: Comparator<Duration> = (first: Duration, second: Duration): number => Temporal.Duration.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Duration, ErrorEvent> => {\n try {\n return success(Temporal.Duration.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport function toLiteral(value: DurationLike): DurationLiteral\nexport function toLiteral(value: DurationLike | null): DurationLiteral | null\nexport function toLiteral(value: DurationLike | undefined): DurationLiteral | undefined\nexport function toLiteral(value: DurationLike | null | undefined): DurationLiteral | null | undefined\nexport function toLiteral(value: DurationLike | null | undefined): DurationLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return from(value).toString() as DurationLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isDuration = (value: unknown): value is Duration => {\n return value instanceof Temporal.Duration\n}\n\nexport const merge = (element: DurationLike, builder: DurationBuilder): Duration => {\n return from(element).with(builder)\n}\n\nexport const fromMilliseconds = (value: number): Duration => {\n return from({ milliseconds: value })\n}\n\nexport const toMilliseconds = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Millisecond)\n}\n\nexport const fromSeconds = (value: number): Duration => {\n return from({ seconds: value })\n}\n\nexport const toSeconds = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Second)\n}\n\nexport const fromMinutes = (value: number): Duration => {\n return from({ minutes: value })\n}\n\nexport const toMinutes = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Minute)\n}\n\nexport const fromHours = (value: number): Duration => {\n return from({ hours: value })\n}\n\nexport const toHours = (duration: DurationLike): number => {\n return from(duration).total(TimeUnit.Hour)\n}\n\nexport const fromUnit = (value: number, timeUnit: TimeUnit): Duration => {\n switch (timeUnit) {\n case TimeUnit.Nanosecond:\n return from({ nanoseconds: value })\n case TimeUnit.Microsecond:\n return from({ microseconds: value })\n case TimeUnit.Millisecond:\n return from({ milliseconds: value })\n case TimeUnit.Second:\n return from({ seconds: value })\n case TimeUnit.Minute:\n return from({ minutes: value })\n case TimeUnit.Hour:\n return from({ hours: value })\n }\n}\n\nexport const toUnit = (duration: DurationLike, timeUnit: TimeUnit): number => {\n return from(duration).total(timeUnit)\n}\n\nexport const isZero = (duration: DurationLike): boolean => {\n return EqualBy(from(duration), Zero)\n}\n\nexport const round = (element: DurationLike, unit: TimeUnit): Duration => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport const add = (...durations: Array<DurationLike>): Duration => {\n return durations.map((it) => from(it)).reduce((first, second) => first.add(second), Zero)\n}\n\nexport const subtract = (...durations: Array<DurationLike>): Duration => {\n if (durations.length === 0) {\n return Zero\n }\n\n const instances = durations.map((it) => from(it))\n return instances.slice(1).reduce((result, current) => result.subtract(current), instances[0]!)\n}\n\nexport const negate = (element: DurationLike): Duration => {\n return from(element).negated()\n}\n\nexport function isEqual(element: DurationLike, other: DurationLike): boolean\nexport function isEqual(element: DurationLike | null, other: DurationLike | null): boolean\nexport function isEqual(element: DurationLike | undefined, other: DurationLike | undefined): boolean\nexport function isEqual(element: DurationLike | null | undefined, other: DurationLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isLess = (element: DurationLike, other: DurationLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isGreater = (element: DurationLike, other: DurationLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport const Zero = from({ nanoseconds: 0 })\nexport const OneMillisecond = fromMilliseconds(1)\nexport const OneSecond = fromS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KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,OAAO,KAAK,EAAE,aAAa,EAAE,CAAC;AACpC,IAAM,iBAAiB,iBAAiB,CAAC;AACzC,IAAM,YAAY,YAAY,CAAC;AAC/B,IAAM,YAAY,YAAY,CAAC;AAC/B,IAAM,UAAU,UAAU,CAAC;AAC3B,IAAM,SAAS,UAAU,EAAE;","names":["it"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instant.d.ts","sourceRoot":"","sources":["../../src/temporal/instant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAwB,MAAM,yCAAyC,CAAA;AACtG,OAAO,EAAgC,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAG9F,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAA8C,MAAM,gDAAgD,CAAA;AAClI,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;
|
|
1
|
+
{"version":3,"file":"instant.d.ts","sourceRoot":"","sources":["../../src/temporal/instant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,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1E,wBAAgB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAA;AACxF,wBAAgB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,CAAA;AASlG,eAAO,MAAM,QAAQ,GAAI,SAAS,WAAW,EAAE,OAAO,WAAW,KAAG,OAEnE,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,WAAW,EAAE,OAAO,WAAW,KAAG,OAElE,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,WAAW,EAAE,UAAU,UAAU,EAAE,QAAQ,MAAM,EAAE,SAAS,qBAAqB,KAAG,MAGnH,CAAA"}
|
package/dist/temporal/instant.js
CHANGED
|
@@ -13,6 +13,7 @@ import { _isInstant, instantToLiteral } from "@bessemer/cornerstone/temporal/chr
|
|
|
13
13
|
import { isString } from "@bessemer/cornerstone/string";
|
|
14
14
|
import { isNil } from "@bessemer/cornerstone/object";
|
|
15
15
|
import { format as formatPlainDateTime, fromInstant } from "@bessemer/cornerstone/temporal/plain-date-time";
|
|
16
|
+
import { Results } from "@bessemer/cornerstone";
|
|
16
17
|
var Namespace = createNamespace("instant");
|
|
17
18
|
function from(value) {
|
|
18
19
|
if (isNil(value)) {
|
|
@@ -50,7 +51,7 @@ function toDate(value) {
|
|
|
50
51
|
}
|
|
51
52
|
return new Date(from(value).epochMilliseconds);
|
|
52
53
|
}
|
|
53
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString(it)
|
|
54
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString(it), (it2) => toLiteral(it2))).meta({
|
|
54
55
|
type: "string",
|
|
55
56
|
format: "date-time"
|
|
56
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/temporal/instant.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { _isInstant, instantToLiteral, TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\nimport { DateTimeFormatOptions, format as formatPlainDateTime, fromInstant } from '@bessemer/cornerstone/temporal/plain-date-time'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\n\nexport type Instant = Temporal.Instant\nexport const Namespace = createNamespace('instant')\nexport type InstantLiteral = NominalType<string, typeof Namespace>\nexport type InstantLike = Instant | Date | InstantLiteral\n\nexport function from(value: InstantLike | string): Instant\nexport function from(value: InstantLike | string | null): Instant | null\nexport function from(value: InstantLike | string | undefined): Instant | undefined\nexport function from(value: InstantLike | string | null | undefined): Instant | null | undefined\nexport function from(value: InstantLike | string | null | undefined): Instant | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Instant) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.Instant.fromEpochMilliseconds(value.getTime())\n}\n\nexport const CompareBy: Comparator<Instant> = (first: Instant, second: Instant): number => Temporal.Instant.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Instant, ErrorEvent> => {\n try {\n return success(Temporal.Instant.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport function toLiteral(value: InstantLike): InstantLiteral\nexport function toLiteral(value: InstantLike | null): InstantLiteral | null\nexport function toLiteral(value: InstantLike | undefined): InstantLiteral | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return instantToLiteral(from(value))\n}\n\nexport function toDate(value: InstantLike): Date\nexport function toDate(value: InstantLike | null): Date | null\nexport function toDate(value: InstantLike | undefined): Date | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return new Date(from(value).epochMilliseconds)\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it)
|
|
1
|
+
{"version":3,"sources":["../../src/temporal/instant.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { _isInstant, instantToLiteral, TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\nimport { DateTimeFormatOptions, format as formatPlainDateTime, fromInstant } from '@bessemer/cornerstone/temporal/plain-date-time'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { Results } from '@bessemer/cornerstone'\n\nexport type Instant = Temporal.Instant\nexport const Namespace = createNamespace('instant')\nexport type InstantLiteral = NominalType<string, typeof Namespace>\nexport type InstantLike = Instant | Date | InstantLiteral\n\nexport function from(value: InstantLike | string): Instant\nexport function from(value: InstantLike | string | null): Instant | null\nexport function from(value: InstantLike | string | undefined): Instant | undefined\nexport function from(value: InstantLike | string | null | undefined): Instant | null | undefined\nexport function from(value: InstantLike | string | null | undefined): Instant | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Instant) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.Instant.fromEpochMilliseconds(value.getTime())\n}\n\nexport const CompareBy: Comparator<Instant> = (first: Instant, second: Instant): number => Temporal.Instant.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Instant, ErrorEvent> => {\n try {\n return success(Temporal.Instant.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport function toLiteral(value: InstantLike): InstantLiteral\nexport function toLiteral(value: InstantLike | null): InstantLiteral | null\nexport function toLiteral(value: InstantLike | undefined): InstantLiteral | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return instantToLiteral(from(value))\n}\n\nexport function toDate(value: InstantLike): Date\nexport function toDate(value: InstantLike | null): Date | null\nexport function toDate(value: InstantLike | undefined): Date | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return new Date(from(value).epochMilliseconds)\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it))).meta({\n type: 'string',\n format: 'date-time',\n})\n\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString).meta({\n type: 'string',\n format: 'date-time',\n})\n\nexport const isInstant = _isInstant\n\nexport const now = (clock = DefaultClock): Instant => {\n return clock.instant()\n}\n\nexport const add = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).add(fromDuration(duration))\n}\n\nexport const subtract = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).subtract(fromDuration(duration))\n}\n\nexport const until = (element: InstantLike, other: InstantLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: InstantLike, unit: TimeUnit): Instant => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: InstantLike, other: InstantLike): boolean\nexport function isEqual(element: InstantLike | null, other: InstantLike | null): boolean\nexport function isEqual(element: InstantLike | undefined, other: InstantLike | undefined): boolean\nexport function isEqual(element: InstantLike | null | undefined, other: InstantLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport const format = (element: InstantLike, timeZone: TimeZoneId, locale: Locale, options: DateTimeFormatOptions): string => {\n const plainDateTime = fromInstant(from(element), timeZone)\n return formatPlainDateTime(plainDateTime, locale, options)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAGhC,SAAS,sBAAsB;AAC/B,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAA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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-date-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-date-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"plain-date-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-date-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAG7D,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAyB,MAAM,yCAAyC,CAAA;AACvG,OAAO,EAAwB,WAAW,EAAE,MAAM,wCAAwC,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAGhE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAA;AAE/F,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAA;AAClD,eAAO,MAAM,SAAS,mFAAqC,CAAA;AAC3D,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,C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B,KAAG,MAgBnG,CAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { createNamespace } from "@bessemer/cornerstone/resource-key";
|
|
4
4
|
import { fromComparator } from "@bessemer/cornerstone/equalitor";
|
|
5
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
5
6
|
import { failure, success } from "@bessemer/cornerstone/result";
|
|
6
7
|
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
|
7
8
|
import { isError } from "@bessemer/cornerstone/error/error";
|
|
@@ -47,7 +48,7 @@ function toLiteral(likeValue) {
|
|
|
47
48
|
const value = from(likeValue);
|
|
48
49
|
return value.toString();
|
|
49
50
|
}
|
|
50
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString(it)
|
|
51
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString(it), (it2) => toLiteral(it2)));
|
|
51
52
|
var SchemaInstance = structuredTransform(Zod.string(), parseString);
|
|
52
53
|
var isPlainDateTime = (value) => {
|
|
53
54
|
return value instanceof Temporal.PlainDateTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/temporal/plain-date-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { PlainTimeBuilder, TimeFormatOptions } from '@bessemer/cornerstone/temporal/plain-time'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\nimport { DateFormatOptions, PlainDateBuilder } from '@bessemer/cornerstone/temporal/plain-date'\n\nexport type PlainDateTime = Temporal.PlainDateTime\nexport const Namespace = createNamespace('plain-date-time')\nexport type PlainDateTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainDateTimeBuilder = PlainDateBuilder & PlainTimeBuilder\n\nexport type PlainDateTimeLike = PlainDateTime | PlainDateTimeLiteral | PlainDateTimeBuilder\n\nexport function from(value: PlainDateTimeLike | string): PlainDateTime\nexport function from(value: PlainDateTimeLike | string | null): PlainDateTime | null\nexport function from(value: PlainDateTimeLike | string | undefined): PlainDateTime | undefined\nexport function from(value: PlainDateTimeLike | string | null | undefined): PlainDateTime | null | undefined\nexport function from(value: PlainDateTimeLike | string | null | undefined): PlainDateTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainDateTime) {\n return value\n }\n\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainDateTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainDateTime> = (first: PlainDateTime, second: PlainDateTime): number =>\n Temporal.PlainDateTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainDateTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainDateTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainDateTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDateTime()\n}\n\nexport function toLiteral(likeValue: PlainDateTimeLike): PlainDateTimeLiteral\nexport function toLiteral(likeValue: PlainDateTimeLike | null): PlainDateTimeLiteral | null\nexport function toLiteral(likeValue: PlainDateTimeLike | undefined): PlainDateTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return value.toString() as PlainDateTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it)
|
|
1
|
+
{"version":3,"sources":["../../src/temporal/plain-date-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { PlainTimeBuilder, TimeFormatOptions } from '@bessemer/cornerstone/temporal/plain-time'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\nimport { DateFormatOptions, PlainDateBuilder } from '@bessemer/cornerstone/temporal/plain-date'\n\nexport type PlainDateTime = Temporal.PlainDateTime\nexport const Namespace = createNamespace('plain-date-time')\nexport type PlainDateTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainDateTimeBuilder = PlainDateBuilder & PlainTimeBuilder\n\nexport type PlainDateTimeLike = PlainDateTime | PlainDateTimeLiteral | PlainDateTimeBuilder\n\nexport function from(value: PlainDateTimeLike | string): PlainDateTime\nexport function from(value: PlainDateTimeLike | string | null): PlainDateTime | null\nexport function from(value: PlainDateTimeLike | string | undefined): PlainDateTime | undefined\nexport function from(value: PlainDateTimeLike | string | null | undefined): PlainDateTime | null | undefined\nexport function from(value: PlainDateTimeLike | string | null | undefined): PlainDateTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainDateTime) {\n return value\n }\n\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainDateTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainDateTime> = (first: PlainDateTime, second: PlainDateTime): number =>\n Temporal.PlainDateTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainDateTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainDateTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainDateTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDateTime()\n}\n\nexport function toLiteral(likeValue: PlainDateTimeLike): PlainDateTimeLiteral\nexport function toLiteral(likeValue: PlainDateTimeLike | null): PlainDateTimeLiteral | null\nexport function toLiteral(likeValue: PlainDateTimeLike | undefined): PlainDateTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return value.toString() as PlainDateTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainDateTime = (value: unknown): value is PlainDateTime => {\n return value instanceof Temporal.PlainDateTime\n}\n\nexport const now = (zone: TimeZoneId, clock = DefaultClock): PlainDateTime => {\n return fromInstant(clock.instant(), zone)\n}\n\nexport const merge = (element: PlainDateTimeLike, builder: PlainDateTimeBuilder): PlainDateTime => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainDateTimeLike, duration: DurationLike): PlainDateTime => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainDateTimeLike, duration: DurationLike): PlainDateTime => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainDateTimeLike, other: PlainDateTimeLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: PlainDateTimeLike, unit: TimeUnit): PlainDateTime => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: PlainDateTimeLike, other: PlainDateTimeLike): boolean\nexport function isEqual(element: PlainDateTimeLike | null, other: PlainDateTimeLike | null): boolean\nexport function isEqual(element: PlainDateTimeLike | undefined, other: PlainDateTimeLike | undefined): boolean\nexport function isEqual(element: PlainDateTimeLike | null | undefined, other: PlainDateTimeLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainDateTimeLike, other: PlainDateTimeLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainDateTimeLike, other: PlainDateTimeLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport type DateTimeFormatOptions = DateFormatOptions & TimeFormatOptions\n\nexport const format = (element: PlainDateTimeLike, locale: Locale, options: DateTimeFormatOptions): string => {\n const plainDateTime = from(element)\n\n // Convert PlainDateTime to Date\n const date = new Date(\n plainDateTime.year,\n plainDateTime.month - 1, // Date months are 0-based\n plainDateTime.day,\n plainDateTime.hour,\n plainDateTime.minute,\n plainDateTime.second,\n plainDateTime.millisecond\n )\n\n const formatter = new Intl.DateTimeFormat(locale, options)\n return formatter.format(date)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAGhC,SAAS,sBAAsB;AAC/B,YAAY,aAAa;AACzB,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,qBAAqB;AAC9D,SAAS,QAAQ,oBAAiC;AAGlD,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAMf,IAAM,YAAY,gBAAgB,iBAAiB;AAUnD,SAAS,KAAK,OAAwF;AAC3G,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,eAAe;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,aAAa,YAAY,KAAK,CAAC;AAAA,EACxC;AAEA,SAAO,SAAS,cAAc,KAAK,KAAK;AAC1C;AAEO,IAAM,YAAuC,CAAC,OAAsB,WACzE,SAAS,cAAc,QAAQ,OAAO,MAAM;AACvC,IAAM,UAAU,eAAe,SAAS;AAExC,IAAM,cAAc,CAAC,UAAqD;AAC/E,MAAI;AACF,WAAO,QAAQ,SAAS,cAAc,KAAK,KAAK,CAAC;AAAA,EACnD,SAAS,GAAG;AACV,QAAI,CAAC,QAAQ,CAAC,GAAG;AACf,YAAM;AAAA,IACR;AAEA,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAA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AAAA,EACrB;AAEA,SAAO,QAAQ,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC;AAC3C;AAEO,IAAM,WAAW,CAAC,SAA4B,UAAsC;AACzF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,UAAU,CAAC,SAA4B,UAAsC;AACxF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAIO,IAAM,SAAS,CAAC,SAA4B,QAAgB,YAA2C;AAC5G,QAAM,gBAAgB,KAAK,OAAO;AAGlC,QAAM,OAAO,IAAI;AAAA,IACf,cAAc;AAAA,IACd,cAAc,QAAQ;AAAA;AAAA,IACtB,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,EAChB;AAEA,QAAM,YAAY,IAAI,KAAK,eAAe,QAAQ,OAAO;AACzD,SAAO,UAAU,OAAO,IAAI;AAC9B;","names":["it"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-date.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"plain-date.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAG7D,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CA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,EAAE,aAAa,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAAA;AAStG,eAAO,MAAM,QAAQ,GAAI,SAAS,aAAa,EAAE,OAAO,SAAS,KAAG,OAEnE,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,aAAa,EAAE,OAAO,SAAS,KAAG,OAElE,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC7C,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACjD,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IACxC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACvE,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,aAAa,EAAE,QAAQ,MAAM,EAAE,SAAS,iBAAiB,KAAG,MAY3F,CAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { createNamespace } from "@bessemer/cornerstone/resource-key";
|
|
4
4
|
import { fromComparator } from "@bessemer/cornerstone/equalitor";
|
|
5
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
5
6
|
import { failure, success } from "@bessemer/cornerstone/result";
|
|
6
7
|
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
|
7
8
|
import { isError } from "@bessemer/cornerstone/error/error";
|
|
@@ -47,7 +48,7 @@ function toLiteral(likeValue) {
|
|
|
47
48
|
const value = from(likeValue);
|
|
48
49
|
return value.toString();
|
|
49
50
|
}
|
|
50
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString(it)
|
|
51
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString(it), (it2) => toLiteral(it2)));
|
|
51
52
|
var SchemaInstance = structuredTransform(Zod.string(), parseString);
|
|
52
53
|
var isPlainDateTime = (value) => {
|
|
53
54
|
return value instanceof Temporal.PlainDateTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/temporal/plain-date.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainDate = Temporal.PlainDate\nexport const Namespace = createNamespace('plain-date')\nexport type PlainDateLiteral = NominalType<string, typeof Namespace>\nexport type PlainDateBuilder = {\n year: number\n month: number\n day: number\n}\n\nexport type PlainDateLike = PlainDate | PlainDateLiteral | PlainDateBuilder\n\nexport function from(value: PlainDateLike | string): PlainDate\nexport function from(value: PlainDateLike | string | null): PlainDate | null\nexport function from(value: PlainDateLike | string | undefined): PlainDate | undefined\nexport function from(value: PlainDateLike | string | null | undefined): PlainDate | null | undefined\nexport function from(value: PlainDateLike | string | null | undefined): PlainDate | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainDate) {\n return value\n }\n\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainDate.from(value)\n}\n\nexport const CompareBy: Comparator<PlainDate> = (first: PlainDate, second: PlainDate): number => Temporal.PlainDateTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainDate, ErrorEvent> => {\n try {\n return success(Temporal.PlainDate.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainDate => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDate()\n}\n\nexport function toLiteral(likeValue: PlainDateLike): PlainDateLiteral\nexport function toLiteral(likeValue: PlainDateLike | null): PlainDateLiteral | null\nexport function toLiteral(likeValue: PlainDateLike | undefined): PlainDateLiteral | undefined\nexport function toLiteral(likeValue: PlainDateLike | null | undefined): PlainDateLiteral | null | undefined\nexport function toLiteral(likeValue: PlainDateLike | null | undefined): PlainDateLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return value.toString() as PlainDateLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it)
|
|
1
|
+
{"version":3,"sources":["../../src/temporal/plain-date.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainDate = Temporal.PlainDate\nexport const Namespace = createNamespace('plain-date')\nexport type PlainDateLiteral = NominalType<string, typeof Namespace>\nexport type PlainDateBuilder = {\n year: number\n month: number\n day: number\n}\n\nexport type PlainDateLike = PlainDate | PlainDateLiteral | PlainDateBuilder\n\nexport function from(value: PlainDateLike | string): PlainDate\nexport function from(value: PlainDateLike | string | null): PlainDate | null\nexport function from(value: PlainDateLike | string | undefined): PlainDate | undefined\nexport function from(value: PlainDateLike | string | null | undefined): PlainDate | null | undefined\nexport function from(value: PlainDateLike | string | null | undefined): PlainDate | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainDate) {\n return value\n }\n\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainDate.from(value)\n}\n\nexport const CompareBy: Comparator<PlainDate> = (first: PlainDate, second: PlainDate): number => Temporal.PlainDateTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainDate, ErrorEvent> => {\n try {\n return success(Temporal.PlainDate.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainDate => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDate()\n}\n\nexport function toLiteral(likeValue: PlainDateLike): PlainDateLiteral\nexport function toLiteral(likeValue: PlainDateLike | null): PlainDateLiteral | null\nexport function toLiteral(likeValue: PlainDateLike | undefined): PlainDateLiteral | undefined\nexport function toLiteral(likeValue: PlainDateLike | null | undefined): PlainDateLiteral | null | undefined\nexport function toLiteral(likeValue: PlainDateLike | null | undefined): PlainDateLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return value.toString() as PlainDateLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainDateTime = (value: unknown): value is PlainDate => {\n return value instanceof Temporal.PlainDateTime\n}\n\nexport const now = (zone: TimeZoneId, clock = DefaultClock): PlainDate => {\n return fromInstant(clock.instant(), zone)\n}\n\nexport const merge = (element: PlainDateLike, builder: Partial<PlainDateBuilder>): PlainDate => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainDateLike, duration: DurationLike): PlainDate => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainDateLike, duration: DurationLike): PlainDate => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainDateLike, other: PlainDateLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport function isEqual(element: PlainDateLike, other: PlainDateLike): boolean\nexport function isEqual(element: PlainDateLike | null, other: PlainDateLike | null): boolean\nexport function isEqual(element: PlainDateLike | undefined, other: PlainDateLike | undefined): boolean\nexport function isEqual(element: PlainDateLike | null | undefined, other: PlainDateLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainDateLike, other: PlainDate): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainDateLike, other: PlainDate): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport type DateFormatOptions = {\n era?: 'long' | 'short' | 'narrow' | undefined\n weekday?: 'long' | 'short' | 'narrow' | undefined\n year?: 'numeric' | '2-digit' | undefined\n month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' | undefined\n day?: 'numeric' | '2-digit' | undefined\n}\n\nexport const format = (element: PlainDateLike, locale: Locale, options: DateFormatOptions): string => {\n const plainDate = from(element)\n\n // Convert PlainDateTime to Date\n const date = new Date(\n plainDate.year,\n plainDate.month - 1, // Date months are 0-based\n plainDate.day\n )\n\n const formatter = new Intl.DateTimeFormat(locale, options)\n return formatter.format(date)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAGhC,SAAS,sBAAsB;AAC/B,YAAY,aAAa;AACzB,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,qBAAqB;AAC9D,SAAS,QAAQ,oBAAiC;AAElD,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAIf,IAAM,YAAY,gBAAgB,YAAY;AAc9C,SAAS,KAAK,OAAgF;AACnG,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,WAAW;AACvC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,aAAa,YAAY,KAAK,CAAC;AAAA,EACxC;AAEA,SAAO,SAAS,UAAU,KAAK,KAAK;AACtC;AAEO,IAAM,YAAmC,CAAC,OAAkB,WAA8B,SAAS,cAAc,QAAQ,OAAO,MAAM;AACtI,IAAM,UAAU,eAAe,SAAS;AAExC,IAAM,cAAc,CAAC,UAAiD;AAC3E,MAAI;AACF,WAAO,QAAQ,SAAS,UAAU,KAAK,KAAK,CAAC;AAAA,EAC/C,SAAS,GAAG;AACV,QAAI,CAAC,QAAQ,CAAC,GAAG;AAC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,GAAG,KAAK,KAAK,CAAC;AAC3C;AAEO,IAAM,WAAW,CAAC,SAAwB,UAA8B;AAC7E,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,UAAU,CAAC,SAAwB,UAA8B;AAC5E,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAUO,IAAM,SAAS,CAAC,SAAwB,QAAgB,YAAuC;AACpG,QAAM,YAAY,KAAK,OAAO;AAG9B,QAAM,OAAO,IAAI;AAAA,IACf,UAAU;AAAA,IACV,UAAU,QAAQ;AAAA;AAAA,IAClB,UAAU;AAAA,EACZ;AAEA,QAAM,YAAY,IAAI,KAAK,eAAe,QAAQ,OAAO;AACzD,SAAO,UAAU,OAAO,IAAI;AAC9B;","names":["it"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"plain-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAG7D,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAyB,MAAM,yCAAyC,CAAA;AACvG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AAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAA;AAC9E,wBAAgB,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAA;AAC5F,wBAAgB,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAAA;AAStG,eAAO,MAAM,QAAQ,GAAI,SAAS,aAAa,EAAE,OAAO,aAAa,KAAG,OAEvE,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,aAAa,EAAE,OAAO,aAAa,KAAG,OAEtE,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IACxC,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IAC1C,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CAC3C,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,aAAa,EAAE,QAAQ,MAAM,EAAE,UAAU,iBAAiB,KAAG,MAY5F,CAAA;AAED,eAAO,MAAM,QAAQ,oBAAoB,CAAA;AACzC,eAAO,MAAM,IAAI,oBAAqB,CAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { createNamespace } from "@bessemer/cornerstone/resource-key";
|
|
4
4
|
import { fromComparator } from "@bessemer/cornerstone/equalitor";
|
|
5
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
5
6
|
import { failure, success } from "@bessemer/cornerstone/result";
|
|
6
7
|
import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
|
|
7
8
|
import { isError } from "@bessemer/cornerstone/error/error";
|
|
@@ -53,7 +54,7 @@ function toLiteral(likeValue) {
|
|
|
53
54
|
}
|
|
54
55
|
return value.toString();
|
|
55
56
|
}
|
|
56
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString(it)
|
|
57
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString(it), (it2) => toLiteral(it2)));
|
|
57
58
|
var SchemaInstance = structuredTransform(Zod.string(), parseString);
|
|
58
59
|
var isPlainTime = (value) => {
|
|
59
60
|
return value instanceof Temporal.PlainTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/temporal/plain-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainTime = Temporal.PlainTime\nexport const Namespace = createNamespace('plain-time')\nexport type PlainTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainTimeBuilder = {\n hour: number\n minute?: number\n second?: number\n millisecond?: number\n microsecond?: number\n nanosecond?: number\n}\nexport type PlainTimeLike = PlainTime | PlainTimeLiteral | PlainTimeBuilder\n\nexport function from(value: PlainTimeLike | string): PlainTime\nexport function from(value: PlainTimeLike | string | null): PlainTime | null\nexport function from(value: PlainTimeLike | string | undefined): PlainTime | undefined\nexport function from(value: PlainTimeLike | string | null | undefined): PlainTime | null | undefined\nexport function from(value: PlainTimeLike | string | null | undefined): PlainTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainTime) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainTime> = (first: PlainTime, second: PlainTime): number => Temporal.PlainTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromDuration = (duration: DurationLike): PlainTime => {\n return Midnight.add(_fromDuration(duration))\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainTime()\n}\n\nexport function toLiteral(likeValue: PlainTimeLike): PlainTimeLiteral\nexport function toLiteral(likeValue: PlainTimeLike | null): PlainTimeLiteral | null\nexport function toLiteral(likeValue: PlainTimeLike | undefined): PlainTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (value.second === 0 && value.millisecond === 0 && value.microsecond === 0 && value.nanosecond === 0) {\n return `${value.hour.toString().padStart(2, '0')}:${value.minute.toString().padStart(2, '0')}` as PlainTimeLiteral\n }\n\n return value.toString() as PlainTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it)
|
|
1
|
+
{"version":3,"sources":["../../src/temporal/plain-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainTime = Temporal.PlainTime\nexport const Namespace = createNamespace('plain-time')\nexport type PlainTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainTimeBuilder = {\n hour: number\n minute?: number\n second?: number\n millisecond?: number\n microsecond?: number\n nanosecond?: number\n}\nexport type PlainTimeLike = PlainTime | PlainTimeLiteral | PlainTimeBuilder\n\nexport function from(value: PlainTimeLike | string): PlainTime\nexport function from(value: PlainTimeLike | string | null): PlainTime | null\nexport function from(value: PlainTimeLike | string | undefined): PlainTime | undefined\nexport function from(value: PlainTimeLike | string | null | undefined): PlainTime | null | undefined\nexport function from(value: PlainTimeLike | string | null | undefined): PlainTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainTime) {\n return value\n }\n if (isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return Temporal.PlainTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainTime> = (first: PlainTime, second: PlainTime): number => Temporal.PlainTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromDuration = (duration: DurationLike): PlainTime => {\n return Midnight.add(_fromDuration(duration))\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainTime()\n}\n\nexport function toLiteral(likeValue: PlainTimeLike): PlainTimeLiteral\nexport function toLiteral(likeValue: PlainTimeLike | null): PlainTimeLiteral | null\nexport function toLiteral(likeValue: PlainTimeLike | undefined): PlainTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (value.second === 0 && value.millisecond === 0 && value.microsecond === 0 && value.nanosecond === 0) {\n return `${value.hour.toString().padStart(2, '0')}:${value.minute.toString().padStart(2, '0')}` as PlainTimeLiteral\n }\n\n return value.toString() as PlainTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainTime = (value: unknown): value is PlainTime => {\n return value instanceof Temporal.PlainTime\n}\n\nexport const now = (zone: TimeZoneId, clock = DefaultClock): PlainTime => {\n return fromInstant(clock.instant(), zone)\n}\n\nexport const merge = (element: PlainTimeLike, builder: Partial<PlainTimeBuilder>): PlainTime => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainTimeLike, other: PlainTimeLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: PlainTimeLike, unit: TimeUnit): PlainTime => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: PlainTimeLike, other: PlainTimeLike): boolean\nexport function isEqual(element: PlainTimeLike | null, other: PlainTimeLike | null): boolean\nexport function isEqual(element: PlainTimeLike | undefined, other: PlainTimeLike | undefined): boolean\nexport function isEqual(element: PlainTimeLike | null | undefined, other: PlainTimeLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport type TimeFormatOptions = {\n hour12?: boolean | undefined\n hour?: 'numeric' | '2-digit' | undefined\n minute?: 'numeric' | '2-digit' | undefined\n second?: 'numeric' | '2-digit' | undefined\n}\n\nexport const format = (element: PlainTimeLike, locale: Locale, options?: TimeFormatOptions): string => {\n const plainTime = from(element)\n\n // Create a Date at Unix epoch with the time components\n const date = new Date(1970, 0, 1, plainTime.hour, plainTime.minute, plainTime.second, plainTime.millisecond)\n\n if (isNil(options) || (isNil(options.hour) && isNil(options.minute) && isNil(options.second))) {\n options = { ...options, hour: 'numeric', minute: '2-digit', ...(plainTime.second > 0 || plainTime.millisecond > 0 ? { second: '2-digit' } : {}) }\n }\n\n const formatter = new Intl.DateTimeFormat(locale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