@duplojs/lang 0.0.1-beta.6 → 0.0.1-beta.7

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.
@@ -1,4 +1,4 @@
1
1
  import { MaybeArray } from './maybeArray';
2
2
  export type Json = MaybeArray<string | undefined | boolean | number | null | {
3
- [key: string]: Json;
3
+ readonly [key: string]: Json;
4
4
  }>;
@@ -1,9 +1,24 @@
1
+ const require_bindPrototypeMethods = require("../../common/bindPrototypeMethods.cjs");
1
2
  const require_simpleClone = require("../../common/simpleClone.cjs");
2
3
  //#region scripts/dataStructure/constraint/base.ts
3
4
  const constraintKind = require("../kind.cjs").createKind("constraint");
5
+ var ConstraintBase = class ConstraintBase {
6
+ constructor() {}
7
+ static init(params) {
8
+ const self = new ConstraintBase();
9
+ require_bindPrototypeMethods.bindPrototypeMethods(self);
10
+ for (const key in params) self[key] = params[key];
11
+ return self;
12
+ }
13
+ static addToPrototype(prop, value) {
14
+ ConstraintBase.prototype[prop] = typeof value === "function" ? function(...args) {
15
+ return value(this, ...args);
16
+ } : value;
17
+ }
18
+ };
4
19
  function createConstraint(kindHandler, createConstructor) {
5
20
  const init = (definition, { executeCheck, isAsynchronous }) => {
6
- const self = {
21
+ const self = ConstraintBase.init({
7
22
  definition,
8
23
  executeCheck: (data) => executeCheck(self, data),
9
24
  isAsynchronous: () => isAsynchronous(self),
@@ -20,11 +35,12 @@ function createConstraint(kindHandler, createConstructor) {
20
35
  },
21
36
  [constraintKind.runTimeKey]: null,
22
37
  [kindHandler.runTimeKey]: null
23
- };
38
+ });
24
39
  return self;
25
40
  };
26
41
  return createConstructor({ init });
27
42
  }
28
43
  //#endregion
44
+ exports.ConstraintBase = ConstraintBase;
29
45
  exports.constraintKind = constraintKind;
30
46
  exports.createConstraint = createConstraint;
@@ -19,6 +19,11 @@ export interface CreateConstraintInitParams<GenericConstraint extends Constraint
19
19
  executeCheck(self: GenericConstraint, data: Parameters<GenericConstraint["executeCheck"]>[0]): DCommon.MaybePromise<SuccessSymbol | ErrorSymbol>;
20
20
  isAsynchronous(self: GenericConstraint): boolean;
21
21
  }
22
+ export declare class ConstraintBase {
23
+ private constructor();
24
+ static init(params: DKind.Remove<Constraint>): Constraint;
25
+ static addToPrototype<GenericProp extends keyof Constraint>(prop: GenericProp, value: Constraint[GenericProp] extends infer InferredValue ? InferredValue extends DCommon.AnyFunction ? (self: Constraint, ...rest: Parameters<InferredValue>) => ReturnType<InferredValue> : Constraint[GenericProp] : never): void;
26
+ }
22
27
  export interface CreateConstraintConstructorParams<GenericKindHandler extends DKind.Handler = DKind.Handler> {
23
28
  init<GenericConstraint extends (Constraint & DKind.Kind<GenericKindHandler>)>(definition: GenericConstraint["definition"], params: CreateConstraintInitParams<GenericConstraint>): GenericConstraint;
24
29
  }
@@ -1,10 +1,25 @@
1
+ import { bindPrototypeMethods } from "../../common/bindPrototypeMethods.mjs";
1
2
  import { simpleClone } from "../../common/simpleClone.mjs";
2
3
  import { createKind } from "../kind.mjs";
3
4
  //#region scripts/dataStructure/constraint/base.ts
4
5
  const constraintKind = createKind("constraint");
6
+ var ConstraintBase = class ConstraintBase {
7
+ constructor() {}
8
+ static init(params) {
9
+ const self = new ConstraintBase();
10
+ bindPrototypeMethods(self);
11
+ for (const key in params) self[key] = params[key];
12
+ return self;
13
+ }
14
+ static addToPrototype(prop, value) {
15
+ ConstraintBase.prototype[prop] = typeof value === "function" ? function(...args) {
16
+ return value(this, ...args);
17
+ } : value;
18
+ }
19
+ };
5
20
  function createConstraint(kindHandler, createConstructor) {
6
21
  const init = (definition, { executeCheck, isAsynchronous }) => {
7
- const self = {
22
+ const self = ConstraintBase.init({
8
23
  definition,
9
24
  executeCheck: (data) => executeCheck(self, data),
10
25
  isAsynchronous: () => isAsynchronous(self),
@@ -21,10 +36,10 @@ function createConstraint(kindHandler, createConstructor) {
21
36
  },
22
37
  [constraintKind.runTimeKey]: null,
23
38
  [kindHandler.runTimeKey]: null
24
- };
39
+ });
25
40
  return self;
26
41
  };
27
42
  return createConstructor({ init });
28
43
  }
29
44
  //#endregion
30
- export { constraintKind, createConstraint };
45
+ export { ConstraintBase, constraintKind, createConstraint };
@@ -138,6 +138,7 @@ var dataStructure_exports = /* @__PURE__ */ require_runtime.__exportAll({
138
138
  BigintType: () => require_bigint$1.BigintType,
139
139
  BooleanLiteralType: () => require_booleanLiteral.BooleanLiteralType,
140
140
  BooleanType: () => require_boolean$1.BooleanType,
141
+ ConstraintBase: () => require_base.ConstraintBase,
141
142
  DateType: () => require_date$1.DateType,
142
143
  EmailConstraint: () => require_email.EmailConstraint,
143
144
  ErrorSymbol: () => require_resultSymbol.ErrorSymbol,
@@ -340,6 +341,7 @@ exports.BigintLiteralType = require_bigintLiteral.BigintLiteralType;
340
341
  exports.BigintType = require_bigint$1.BigintType;
341
342
  exports.BooleanLiteralType = require_booleanLiteral.BooleanLiteralType;
342
343
  exports.BooleanType = require_boolean$1.BooleanType;
344
+ exports.ConstraintBase = require_base.ConstraintBase;
343
345
  exports.DateType = require_date$1.DateType;
344
346
  exports.EmailConstraint = require_email.EmailConstraint;
345
347
  exports.ErrorSymbol = require_resultSymbol.ErrorSymbol;
@@ -4,7 +4,7 @@ import { ErrorSymbol, SuccessSymbol } from "./common/resultSymbol.mjs";
4
4
  import { codecKind, codecsKind, createCodec, createCodecs } from "./common/codec.mjs";
5
5
  import { createErrorHandler, createGetErrorHandler, decodeIssueKind, encodeIssueKind, issueKind } from "./common/error.mjs";
6
6
  import { createErrorInterpreter } from "./common/errorInterpreter.mjs";
7
- import { constraintKind, createConstraint } from "./constraint/base.mjs";
7
+ import { ConstraintBase, constraintKind, createConstraint } from "./constraint/base.mjs";
8
8
  import { AbsolutePathConstraint, absolutePathConstraintKind } from "./constraint/defaults/absolutePath.mjs";
9
9
  import { AllowedCharactersConstraint, allowedCharactersConstraintKind } from "./constraint/defaults/allowedCharacters.mjs";
10
10
  import { ArrayLengthEqualConstraint, arrayLengthEqualConstraintKind } from "./constraint/defaults/arrayLengthEqual.mjs";
@@ -138,6 +138,7 @@ var dataStructure_exports = /* @__PURE__ */ __exportAll({
138
138
  BigintType: () => BigintType,
139
139
  BooleanLiteralType: () => BooleanLiteralType,
140
140
  BooleanType: () => BooleanType,
141
+ ConstraintBase: () => ConstraintBase,
141
142
  DateType: () => DateType,
142
143
  EmailConstraint: () => EmailConstraint,
143
144
  ErrorSymbol: () => ErrorSymbol,
@@ -330,4 +331,4 @@ var dataStructure_exports = /* @__PURE__ */ __exportAll({
330
331
  uuidConstraintKind: () => uuidConstraintKind
331
332
  });
332
333
  //#endregion
333
- export { AbsolutePathConstraint, AllowedCharactersConstraint, ArrayLengthEqualConstraint, ArrayStructure, BetweenThanConstraint, BetweenThanOrEqualConstraint, BigintLiteralType, BigintType, BooleanLiteralType, BooleanType, DateType, EmailConstraint, ErrorSymbol, EvenConstraint, GreaterThanConstraint, GreaterThanOrEqualConstraint, IntegerConstraint, LazyStructure, LessThanConstraint, LessThanOrEqualConstraint, MaxCharactersConstraint, MaxElementsConstraint, MinCharactersConstraint, MinElementsConstraint, MultipleOfConstraint, NegativeConstraint, NonEncodableStringStructure, NotEmptyConstraint, NotZeroConstraint, NullType, NumberLiteralType, NumberType, ObjectStructure, OddConstraint, PathConstraint, PositiveConstraint, RecordStructure, RefineConstraint, RegexConstraint, SafeConstraint, SegmentPathConstraint, StrictNegativeConstraint, StrictPositiveConstraint, StringLengthEqualConstraint, StringLiteralType, StringType, StructureClass, SuccessSymbol, TheBigint, TheBoolean, TheDate, TheNull, TheNumber, TheString, TheTime, TheUndefined, TimeType, TrimmedConstraint, TypeStructure, UndefinedType, UnionStructure, UrlConstraint, UuidConstraint, absolutePath, absolutePathConstraintKind, allowedCharacters, allowedCharactersConstraintKind, array, arrayLengthEqual, arrayLengthEqualConstraintKind, arrayStructureKind, betweenThan, betweenThanConstraintKind, betweenThanOrEqual, betweenThanOrEqualConstraintKind, bigint, bigintFundamentalTypeKind, bigintLiteralTypeKind, bigintTypeKind, boolean, booleanFundamentalTypeKind, booleanLiteralTypeKind, booleanTypeKind, codecKind, codecsKind, constraintIdentifier, constraintKind, createCodec, createCodecs, createConstraint, createErrorHandler, createErrorInterpreter, createFundamentalType, createGetErrorHandler, createKind, createStructure, createType, dataStructure_exports, date, dateFundamentalTypeKind, dateTypeKind, decodeIssueKind, email, emailConstraintKind, encodeIssueKind, even, evenConstraintKind, extend, fundamentalTypeIdentifier, fundamentalTypeKind, greaterThan, greaterThanConstraintKind, greaterThanOrEqual, greaterThanOrEqualConstraintKind, integer, integerConstraintKind, isNullStructure, isUndefinedStructure, issueKind, lazy, lazyStructureKind, lessThan, lessThanConstraintKind, lessThanOrEqual, lessThanOrEqualConstraintKind, literal, maxCharacters, maxCharactersConstraintKind, maxElements, maxElementsConstraintKind, minCharacters, minCharactersConstraintKind, minElements, minElementsConstraintKind, multipleOf, multipleOfConstraintKind, negative, negativeConstraintKind, nonEncodableStringStructureKind, notEmpty, notEmptyConstraintKind, notZero, notZeroConstraintKind, nullHelper as null, nullFundamentalTypeKind, nullTypeKind, nullable, number, numberFundamentalTypeKind, numberLiteralTypeKind, numberTypeKind, object, objectStructureKind, odd, oddConstraintKind, optional, partial, path, pathConstraintKind, positive, positiveConstraintKind, record, recordStructureKind, refine, refineConstraintKind, regex, regexConstraintKind, required, safe, safeConstraintKind, segmentPath, segmentPathConstraintKind, strictNegative, strictNegativeConstraintKind, strictPositive, strictPositiveConstraintKind, string, stringFundamentalTypeKind, stringLengthEqual, stringLengthEqualConstraintKind, stringLiteralTypeKind, stringTypeKind, structureIdentifier, structureKind, time, timeFundamentalTypeKind, timeTypeKind, trimmed, trimmedConstraintKind, typeIdentifier, typeKind, typeStructureKind, undefinedHelper as undefined, undefinedFundamentalTypeKind, undefinedTypeKind, union, unionStructureKind, url, urlConstraintKind, uuid, uuidConstraintKind };
334
+ export { AbsolutePathConstraint, AllowedCharactersConstraint, ArrayLengthEqualConstraint, ArrayStructure, BetweenThanConstraint, BetweenThanOrEqualConstraint, BigintLiteralType, BigintType, BooleanLiteralType, BooleanType, ConstraintBase, DateType, EmailConstraint, ErrorSymbol, EvenConstraint, GreaterThanConstraint, GreaterThanOrEqualConstraint, IntegerConstraint, LazyStructure, LessThanConstraint, LessThanOrEqualConstraint, MaxCharactersConstraint, MaxElementsConstraint, MinCharactersConstraint, MinElementsConstraint, MultipleOfConstraint, NegativeConstraint, NonEncodableStringStructure, NotEmptyConstraint, NotZeroConstraint, NullType, NumberLiteralType, NumberType, ObjectStructure, OddConstraint, PathConstraint, PositiveConstraint, RecordStructure, RefineConstraint, RegexConstraint, SafeConstraint, SegmentPathConstraint, StrictNegativeConstraint, StrictPositiveConstraint, StringLengthEqualConstraint, StringLiteralType, StringType, StructureClass, SuccessSymbol, TheBigint, TheBoolean, TheDate, TheNull, TheNumber, TheString, TheTime, TheUndefined, TimeType, TrimmedConstraint, TypeStructure, UndefinedType, UnionStructure, UrlConstraint, UuidConstraint, absolutePath, absolutePathConstraintKind, allowedCharacters, allowedCharactersConstraintKind, array, arrayLengthEqual, arrayLengthEqualConstraintKind, arrayStructureKind, betweenThan, betweenThanConstraintKind, betweenThanOrEqual, betweenThanOrEqualConstraintKind, bigint, bigintFundamentalTypeKind, bigintLiteralTypeKind, bigintTypeKind, boolean, booleanFundamentalTypeKind, booleanLiteralTypeKind, booleanTypeKind, codecKind, codecsKind, constraintIdentifier, constraintKind, createCodec, createCodecs, createConstraint, createErrorHandler, createErrorInterpreter, createFundamentalType, createGetErrorHandler, createKind, createStructure, createType, dataStructure_exports, date, dateFundamentalTypeKind, dateTypeKind, decodeIssueKind, email, emailConstraintKind, encodeIssueKind, even, evenConstraintKind, extend, fundamentalTypeIdentifier, fundamentalTypeKind, greaterThan, greaterThanConstraintKind, greaterThanOrEqual, greaterThanOrEqualConstraintKind, integer, integerConstraintKind, isNullStructure, isUndefinedStructure, issueKind, lazy, lazyStructureKind, lessThan, lessThanConstraintKind, lessThanOrEqual, lessThanOrEqualConstraintKind, literal, maxCharacters, maxCharactersConstraintKind, maxElements, maxElementsConstraintKind, minCharacters, minCharactersConstraintKind, minElements, minElementsConstraintKind, multipleOf, multipleOfConstraintKind, negative, negativeConstraintKind, nonEncodableStringStructureKind, notEmpty, notEmptyConstraintKind, notZero, notZeroConstraintKind, nullHelper as null, nullFundamentalTypeKind, nullTypeKind, nullable, number, numberFundamentalTypeKind, numberLiteralTypeKind, numberTypeKind, object, objectStructureKind, odd, oddConstraintKind, optional, partial, path, pathConstraintKind, positive, positiveConstraintKind, record, recordStructureKind, refine, refineConstraintKind, regex, regexConstraintKind, required, safe, safeConstraintKind, segmentPath, segmentPathConstraintKind, strictNegative, strictNegativeConstraintKind, strictPositive, strictPositiveConstraintKind, string, stringFundamentalTypeKind, stringLengthEqual, stringLengthEqualConstraintKind, stringLiteralTypeKind, stringTypeKind, structureIdentifier, structureKind, time, timeFundamentalTypeKind, timeTypeKind, trimmed, trimmedConstraintKind, typeIdentifier, typeKind, typeStructureKind, undefinedHelper as undefined, undefinedFundamentalTypeKind, undefinedTypeKind, union, unionStructureKind, url, urlConstraintKind, uuid, uuidConstraintKind };
@@ -24,14 +24,14 @@ export declare const entityStructureKind: DKind.Handler<DKind.Definition<"@Duplo
24
24
  export interface EntityStructureDefinition extends DDataStructure.StructureDefinition<readonly []> {
25
25
  readonly inner: DCommon.Memoized<DDataStructure.ObjectStructure>;
26
26
  }
27
- export type EntityMap<GenericValue extends unknown, GenericRawValue = DCommon.RemoveConstraint<GenericValue>> = GenericRawValue extends NewType ? NewTypeMap<GenericRawValue> : GenericRawValue extends Entity ? GenericRawValue : GenericRawValue extends object ? DCommon.Or<[
27
+ export type EntityMap<GenericValue extends unknown, GenericRawValue = DCommon.RemoveConstraint<GenericValue>> = GenericRawValue extends NewType ? NewTypeMap<GenericRawValue> : GenericRawValue extends object ? DCommon.Or<[
28
28
  DCommon.IsExtends<GenericRawValue, readonly any[]>,
29
29
  DCommon.And<[
30
30
  DCommon.IsExtends<keyof GenericRawValue, string>,
31
31
  DCommon.Not<DCommon.IsExtends<DCommon.AnyFunction, GenericRawValue[keyof GenericRawValue]>>
32
32
  ]>
33
33
  ]> extends true ? {
34
- [Prop in keyof GenericRawValue]: NewTypeMap<GenericRawValue[Prop]>;
34
+ [Prop in keyof GenericRawValue]: EntityMap<GenericRawValue[Prop]>;
35
35
  } : GenericRawValue : GenericRawValue;
36
36
  export interface EntityStructure<GenericName extends string = string, GenericProperties extends Record<string, unknown> = Record<string, unknown>> extends DCommon.Forward<DDataStructure.Structure<Entity<GenericName> & GenericProperties, EntityStructureDefinition> & DKind.Kind<typeof entityStructureKind>> {
37
37
  readonly name: GenericName;
@@ -1,3 +1,9 @@
1
+ const require_isSimple = require("../../object/isSimple.cjs");
2
+ const require_create = require("../../either/left/create.cjs");
3
+ const require_create$1 = require("../../either/right/create.cjs");
4
+ const require_justExec = require("../../common/justExec.cjs");
5
+ const require_resultSymbol = require("../../dataStructure/common/resultSymbol.cjs");
6
+ const require_error = require("../../dataStructure/common/error.cjs");
1
7
  const require_base = require("../../dataStructure/structure/base.cjs");
2
8
  const require_nonEncodableString = require("../../dataStructure/structure/defaults/nonEncodableString.cjs");
3
9
  const require_object = require("../../dataStructure/structure/defaults/object.cjs");
@@ -16,7 +22,64 @@ const TaggedObjectStructure = require_base.createStructure(taggedObjectStructure
16
22
  executeEncode: (self, codecContext, data, errorHandler) => self.definition.inner.executeEncode(codecContext, data, errorHandler),
17
23
  executeDecode: (self, codecContext, data, errorHandler) => self.definition.inner.executeDecode(codecContext, data, errorHandler),
18
24
  isAsynchronous: (self) => self.definition.inner.isAsynchronous()
19
- }, { name }));
25
+ }, {
26
+ name,
27
+ new: (self, properties) => ({
28
+ ...properties,
29
+ [objectTagKind.runTimeKey]: name
30
+ }),
31
+ decodeMap: (self, ...args) => {
32
+ if (args.length === 1) {
33
+ const [codecs] = args;
34
+ return (value) => self.decodeMap(codecs, value);
35
+ }
36
+ const errorHandler = require_error.createGetErrorHandler();
37
+ const [codecs, data] = args;
38
+ const result = self.executeDecode(codecs.context.value, require_isSimple.isSimple(data) ? {
39
+ ...data,
40
+ [objectTagKind.runTimeKey]: name
41
+ } : data, errorHandler);
42
+ if (result instanceof Promise) return require_create.left("async-error", void 0);
43
+ if (result === require_resultSymbol.ErrorSymbol) return require_create.left("map-error", errorHandler().createError());
44
+ return require_create$1.right("map-success", result);
45
+ },
46
+ map: (self, data) => {
47
+ const errorHandler = require_error.createGetErrorHandler();
48
+ const formattedData = require_isSimple.isSimple(data) ? {
49
+ ...data,
50
+ [objectTagKind.runTimeKey]: name
51
+ } : data;
52
+ const result = self.executeCheck(formattedData, errorHandler);
53
+ if (result instanceof Promise) return require_create.left("async-error", void 0);
54
+ if (result === require_resultSymbol.ErrorSymbol) return require_create.left("map-error", errorHandler().createError());
55
+ return require_create$1.right("map-success", formattedData);
56
+ },
57
+ asyncDecodeMap: (self, ...args) => {
58
+ if (args.length === 1) {
59
+ const [codecs] = args;
60
+ return (value) => self.asyncDecodeMap(codecs, value);
61
+ }
62
+ return require_justExec.justExec(async () => {
63
+ const errorHandler = require_error.createGetErrorHandler();
64
+ const [codecs, data] = args;
65
+ const result = await self.executeDecode(codecs.context.value, require_isSimple.isSimple(data) ? {
66
+ ...data,
67
+ [objectTagKind.runTimeKey]: name
68
+ } : data, errorHandler);
69
+ if (result === require_resultSymbol.ErrorSymbol) return require_create.left("map-error", errorHandler().createError());
70
+ return require_create$1.right("map-success", result);
71
+ });
72
+ },
73
+ asyncMap: (self, data) => require_justExec.justExec(async () => {
74
+ const errorHandler = require_error.createGetErrorHandler();
75
+ const formattedData = require_isSimple.isSimple(data) ? {
76
+ ...data,
77
+ [objectTagKind.runTimeKey]: name
78
+ } : data;
79
+ if (await self.executeCheck(formattedData, errorHandler) === require_resultSymbol.ErrorSymbol) return require_create.left("map-error", errorHandler().createError());
80
+ return require_create$1.right("map-success", formattedData);
81
+ })
82
+ }));
20
83
  //#endregion
21
84
  exports.TaggedObjectStructure = TaggedObjectStructure;
22
85
  exports.objectTagKind = objectTagKind;
@@ -1,5 +1,7 @@
1
+ import { NewType, NewTypeMap } from '../newType';
1
2
  import type * as DKind from '../../kind';
2
- import type * as DCommon from '../../common';
3
+ import * as DCommon from '../../common';
4
+ import * as DEither from '../../either';
3
5
  import * as DDataStructure from '../../dataStructure';
4
6
  declare module '../../dataStructure' {
5
7
  interface StructuresStore {
@@ -25,7 +27,23 @@ export declare const taggedObjectStructureKind: DKind.Handler<DKind.Definition<"
25
27
  export interface TaggedObjectStructureDefinition extends DDataStructure.StructureDefinition<readonly []> {
26
28
  readonly inner: DDataStructure.ObjectStructure;
27
29
  }
30
+ export type TaggedObjectMap<GenericValue extends unknown, GenericRawValue = DCommon.RemoveConstraint<GenericValue>> = GenericRawValue extends NewType ? NewTypeMap<GenericRawValue> : GenericRawValue extends object ? DCommon.Or<[
31
+ DCommon.IsExtends<GenericRawValue, readonly any[]>,
32
+ DCommon.And<[
33
+ DCommon.IsExtends<keyof GenericRawValue, string>,
34
+ DCommon.Not<DCommon.IsExtends<DCommon.AnyFunction, GenericRawValue[keyof GenericRawValue]>>
35
+ ]>
36
+ ]> extends true ? {
37
+ [Prop in keyof GenericRawValue]: TaggedObjectMap<GenericRawValue[Prop]>;
38
+ } : GenericRawValue : GenericRawValue;
28
39
  export interface TaggedObjectStructure<GenericTaggedObject extends ObjectTag = ObjectTag> extends DCommon.Forward<DDataStructure.Structure<GenericTaggedObject, TaggedObjectStructureDefinition> & DKind.Kind<typeof taggedObjectStructureKind>> {
29
40
  readonly name: GetTagValue<GenericTaggedObject>;
41
+ "new"(properties: DCommon.SimplifyTopLevel<DKind.Remove<GenericTaggedObject>>): GenericTaggedObject;
42
+ decodeMap<GenericCodecs extends DDataStructure.Codecs>(codecs: GenericCodecs): (data: DDataStructure.EncodedValue<TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>, GenericCodecs>) => (DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"async-error", undefined> | DEither.Left<"map-error", DDataStructure.Error>);
43
+ decodeMap<GenericCodecs extends DDataStructure.Codecs>(codecs: GenericCodecs, data: DDataStructure.EncodedValue<TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>, GenericCodecs>): (DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"async-error", undefined> | DEither.Left<"map-error", DDataStructure.Error>);
44
+ map(data: TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>): (DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"async-error", undefined> | DEither.Left<"map-error", DDataStructure.Error>);
45
+ asyncDecodeMap<GenericCodecs extends DDataStructure.Codecs>(codecs: GenericCodecs): (data: DDataStructure.EncodedValue<TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>, GenericCodecs>) => Promise<DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"map-error", DDataStructure.Error>>;
46
+ asyncDecodeMap<GenericCodecs extends DDataStructure.Codecs>(codecs: GenericCodecs, data: DDataStructure.EncodedValue<TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>, GenericCodecs>): Promise<DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"map-error", DDataStructure.Error>>;
47
+ asyncMap(data: TaggedObjectMap<DKind.Remove<DDataStructure.StructureValue<this>>>): Promise<DEither.Right<"map-success", DDataStructure.StructureValue<this>> | DEither.Left<"map-error", DDataStructure.Error>>;
30
48
  }
31
49
  export declare const TaggedObjectStructure: <GenericTaggedObject extends ObjectTag, GenericName extends string = never, GenericShape extends DDataStructure.ShapeObjectStructure = never>(name: GetTagValue<GenericTaggedObject> | GenericName, shape: ShapeTaggedObjectStructure<GenericTaggedObject> | GenericShape) => TaggedObjectStructure<ObjectTag extends GenericTaggedObject ? (ObjectTag<GenericName> & DDataStructure.ShapeObjectStructureValue<GenericShape>) : GenericTaggedObject>;
@@ -1,3 +1,9 @@
1
+ import { isSimple } from "../../object/isSimple.mjs";
2
+ import { left } from "../../either/left/create.mjs";
3
+ import { right } from "../../either/right/create.mjs";
4
+ import { justExec } from "../../common/justExec.mjs";
5
+ import { ErrorSymbol } from "../../dataStructure/common/resultSymbol.mjs";
6
+ import { createGetErrorHandler } from "../../dataStructure/common/error.mjs";
1
7
  import { createStructure } from "../../dataStructure/structure/base.mjs";
2
8
  import { NonEncodableStringStructure } from "../../dataStructure/structure/defaults/nonEncodableString.mjs";
3
9
  import { ObjectStructure } from "../../dataStructure/structure/defaults/object.mjs";
@@ -16,6 +22,63 @@ const TaggedObjectStructure = createStructure(taggedObjectStructureKind, ({ init
16
22
  executeEncode: (self, codecContext, data, errorHandler) => self.definition.inner.executeEncode(codecContext, data, errorHandler),
17
23
  executeDecode: (self, codecContext, data, errorHandler) => self.definition.inner.executeDecode(codecContext, data, errorHandler),
18
24
  isAsynchronous: (self) => self.definition.inner.isAsynchronous()
19
- }, { name }));
25
+ }, {
26
+ name,
27
+ new: (self, properties) => ({
28
+ ...properties,
29
+ [objectTagKind.runTimeKey]: name
30
+ }),
31
+ decodeMap: (self, ...args) => {
32
+ if (args.length === 1) {
33
+ const [codecs] = args;
34
+ return (value) => self.decodeMap(codecs, value);
35
+ }
36
+ const errorHandler = createGetErrorHandler();
37
+ const [codecs, data] = args;
38
+ const result = self.executeDecode(codecs.context.value, isSimple(data) ? {
39
+ ...data,
40
+ [objectTagKind.runTimeKey]: name
41
+ } : data, errorHandler);
42
+ if (result instanceof Promise) return left("async-error", void 0);
43
+ if (result === ErrorSymbol) return left("map-error", errorHandler().createError());
44
+ return right("map-success", result);
45
+ },
46
+ map: (self, data) => {
47
+ const errorHandler = createGetErrorHandler();
48
+ const formattedData = isSimple(data) ? {
49
+ ...data,
50
+ [objectTagKind.runTimeKey]: name
51
+ } : data;
52
+ const result = self.executeCheck(formattedData, errorHandler);
53
+ if (result instanceof Promise) return left("async-error", void 0);
54
+ if (result === ErrorSymbol) return left("map-error", errorHandler().createError());
55
+ return right("map-success", formattedData);
56
+ },
57
+ asyncDecodeMap: (self, ...args) => {
58
+ if (args.length === 1) {
59
+ const [codecs] = args;
60
+ return (value) => self.asyncDecodeMap(codecs, value);
61
+ }
62
+ return justExec(async () => {
63
+ const errorHandler = createGetErrorHandler();
64
+ const [codecs, data] = args;
65
+ const result = await self.executeDecode(codecs.context.value, isSimple(data) ? {
66
+ ...data,
67
+ [objectTagKind.runTimeKey]: name
68
+ } : data, errorHandler);
69
+ if (result === ErrorSymbol) return left("map-error", errorHandler().createError());
70
+ return right("map-success", result);
71
+ });
72
+ },
73
+ asyncMap: (self, data) => justExec(async () => {
74
+ const errorHandler = createGetErrorHandler();
75
+ const formattedData = isSimple(data) ? {
76
+ ...data,
77
+ [objectTagKind.runTimeKey]: name
78
+ } : data;
79
+ if (await self.executeCheck(formattedData, errorHandler) === ErrorSymbol) return left("map-error", errorHandler().createError());
80
+ return right("map-success", formattedData);
81
+ })
82
+ }));
20
83
  //#endregion
21
84
  export { TaggedObjectStructure, objectTagKind, taggedObjectStructureKind };
@@ -1,9 +1,13 @@
1
1
  //#region scripts/path/getParentFolderPath.ts
2
2
  const parentFolderPathRegex = /^([^]*)\/[^/]+$/;
3
- const onlyParentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
3
+ const onlyParentSegmentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
4
4
  function getParentFolderPath(path) {
5
+ if (path === "/") return null;
6
+ if (path === ".") return "..";
7
+ if (onlyParentSegmentsRegex.test(path)) return `${path}/..`;
5
8
  const parent = parentFolderPathRegex.exec(path)?.[1];
6
- if (parent === void 0 || parent === "" || onlyParentsRegex.test(parent)) return path.startsWith("/") && parent === "" ? "/" : null;
9
+ if (parent === void 0) return ".";
10
+ if (parent === "") return "/";
7
11
  return parent;
8
12
  }
9
13
  //#endregion
@@ -1,2 +1,2 @@
1
1
  import { Absolute, Path } from './constraints';
2
- export declare function getParentFolderPath<GenericPath extends string & (Path | Absolute)>(path: GenericPath): string | null;
2
+ export declare function getParentFolderPath<GenericPath extends string & (Path | Absolute)>(path: GenericPath): (string & Path) | null;
@@ -1,9 +1,13 @@
1
1
  //#region scripts/path/getParentFolderPath.ts
2
2
  const parentFolderPathRegex = /^([^]*)\/[^/]+$/;
3
- const onlyParentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
3
+ const onlyParentSegmentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
4
4
  function getParentFolderPath(path) {
5
+ if (path === "/") return null;
6
+ if (path === ".") return "..";
7
+ if (onlyParentSegmentsRegex.test(path)) return `${path}/..`;
5
8
  const parent = parentFolderPathRegex.exec(path)?.[1];
6
- if (parent === void 0 || parent === "" || onlyParentsRegex.test(parent)) return path.startsWith("/") && parent === "" ? "/" : null;
9
+ if (parent === void 0) return ".";
10
+ if (parent === "") return "/";
7
11
  return parent;
8
12
  }
9
13
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/lang",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {