@duplojs/agents-kit 0.0.0-stage → 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -2
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.mjs +7 -0
- package/dist/bin/install/index.d.ts +2 -0
- package/dist/bin/install/index.mjs +25 -0
- package/dist/bin/install/skill.d.ts +28 -0
- package/dist/bin/install/skill.mjs +58 -0
- package/dist/bin/packagePath.d.ts +2 -0
- package/dist/bin/packagePath.mjs +12 -0
- package/dist/bin/setup/index.d.ts +12 -0
- package/dist/bin/setup/index.mjs +33 -0
- package/dist/bin/setup/instructions.d.ts +8 -0
- package/dist/bin/setup/instructions.mjs +27 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +0 -0
- package/docs/API/10-lang/10-array/10-at.ts +65 -0
- package/docs/API/10-lang/10-array/10-chunk.ts +42 -0
- package/docs/API/10-lang/10-array/10-coalescing.ts +19 -0
- package/docs/API/10-lang/10-array/10-concat.ts +34 -0
- package/docs/API/10-lang/10-array/10-copyWithin.ts +34 -0
- package/docs/API/10-lang/10-array/10-every.ts +25 -0
- package/docs/API/10-lang/10-array/10-fill.ts +34 -0
- package/docs/API/10-lang/10-array/10-fillAll.ts +34 -0
- package/docs/API/10-lang/10-array/10-filter.ts +43 -0
- package/docs/API/10-lang/10-array/10-find.ts +33 -0
- package/docs/API/10-lang/10-array/10-findAndReplace.ts +35 -0
- package/docs/API/10-lang/10-array/10-findAndSpliceDelete.ts +35 -0
- package/docs/API/10-lang/10-array/10-findAndSpliceInsert.ts +35 -0
- package/docs/API/10-lang/10-array/10-findAndSpliceReplace.ts +24 -0
- package/docs/API/10-lang/10-array/10-findDuplicates.ts +19 -0
- package/docs/API/10-lang/10-array/10-findIndex.ts +25 -0
- package/docs/API/10-lang/10-array/10-findLast.ts +33 -0
- package/docs/API/10-lang/10-array/10-findLastIndex.ts +25 -0
- package/docs/API/10-lang/10-array/10-first.ts +21 -0
- package/docs/API/10-lang/10-array/10-flat.ts +22 -0
- package/docs/API/10-lang/10-array/10-flatMap.ts +24 -0
- package/docs/API/10-lang/10-array/10-from.ts +25 -0
- package/docs/API/10-lang/10-array/10-group.ts +27 -0
- package/docs/API/10-lang/10-array/10-groupOutput.ts +30 -0
- package/docs/API/10-lang/10-array/10-includes.ts +24 -0
- package/docs/API/10-lang/10-array/10-indexOf.ts +24 -0
- package/docs/API/10-lang/10-array/10-insert.ts +34 -0
- package/docs/API/10-lang/10-array/10-is.ts +15 -0
- package/docs/API/10-lang/10-array/10-isLastIndex.ts +24 -0
- package/docs/API/10-lang/10-array/10-last.ts +21 -0
- package/docs/API/10-lang/10-array/10-lastIndexOf.ts +24 -0
- package/docs/API/10-lang/10-array/10-length.ts +28 -0
- package/docs/API/10-lang/10-array/10-lengthEqual.ts +39 -0
- package/docs/API/10-lang/10-array/10-map.ts +34 -0
- package/docs/API/10-lang/10-array/10-maxElements.ts +44 -0
- package/docs/API/10-lang/10-array/10-minElements.ts +44 -0
- package/docs/API/10-lang/10-array/10-notIncludes.ts +24 -0
- package/docs/API/10-lang/10-array/10-pop.ts +23 -0
- package/docs/API/10-lang/10-array/10-prepend.ts +34 -0
- package/docs/API/10-lang/10-array/10-push.ts +34 -0
- package/docs/API/10-lang/10-array/10-reduce.ts +28 -0
- package/docs/API/10-lang/10-array/10-reduceFrom.ts +16 -0
- package/docs/API/10-lang/10-array/10-reduceRight.ts +28 -0
- package/docs/API/10-lang/10-array/10-reverse.ts +25 -0
- package/docs/API/10-lang/10-array/10-select.ts +26 -0
- package/docs/API/10-lang/10-array/10-set.ts +24 -0
- package/docs/API/10-lang/10-array/10-shift.ts +23 -0
- package/docs/API/10-lang/10-array/10-slice.ts +24 -0
- package/docs/API/10-lang/10-array/10-some.ts +25 -0
- package/docs/API/10-lang/10-array/10-sort.ts +34 -0
- package/docs/API/10-lang/10-array/10-spliceDelete.ts +34 -0
- package/docs/API/10-lang/10-array/10-spliceInsert.ts +34 -0
- package/docs/API/10-lang/10-array/10-spliceReplace.ts +24 -0
- package/docs/API/10-lang/10-array/10-unshift.ts +34 -0
- package/docs/API/10-lang/10-array/index.llms.md +220 -0
- package/docs/API/10-lang/10-array/index.md +3 -0
- package/docs/API/10-lang/10-chrono/10-addDays.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addHours.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addMilliseconds.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addMinutes.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addMonths.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addSeconds.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addTime.ts +38 -0
- package/docs/API/10-lang/10-chrono/10-addWeeks.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-addYears.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-applyTimezone.ts +29 -0
- package/docs/API/10-lang/10-chrono/10-betweenThanDate.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-betweenThanOrEqualDate.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-betweenThanOrEqualTime.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-betweenThanTime.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-closestTo.ts +48 -0
- package/docs/API/10-lang/10-chrono/10-computeTime.ts +35 -0
- package/docs/API/10-lang/10-chrono/10-createDate.ts +122 -0
- package/docs/API/10-lang/10-chrono/10-createDateOrThrow.ts +39 -0
- package/docs/API/10-lang/10-chrono/10-createTime.ts +86 -0
- package/docs/API/10-lang/10-chrono/10-createTimeOrThrow.ts +28 -0
- package/docs/API/10-lang/10-chrono/10-eachDate.ts +67 -0
- package/docs/API/10-lang/10-chrono/10-equalDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-equalTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-formatDate.ts +43 -0
- package/docs/API/10-lang/10-chrono/10-formatTime.ts +37 -0
- package/docs/API/10-lang/10-chrono/10-getDayOfMonth.ts +37 -0
- package/docs/API/10-lang/10-chrono/10-getDayOfWeek.ts +30 -0
- package/docs/API/10-lang/10-chrono/10-getDayOfYear.ts +28 -0
- package/docs/API/10-lang/10-chrono/10-getDifference.ts +29 -0
- package/docs/API/10-lang/10-chrono/10-getFirstDayOfMonth.ts +24 -0
- package/docs/API/10-lang/10-chrono/10-getFirstDayOfWeek.ts +24 -0
- package/docs/API/10-lang/10-chrono/10-getHour.ts +28 -0
- package/docs/API/10-lang/10-chrono/10-getLastDayOfMonth.ts +24 -0
- package/docs/API/10-lang/10-chrono/10-getLastDayOfWeek.ts +24 -0
- package/docs/API/10-lang/10-chrono/10-getMilliseconds.ts +24 -0
- package/docs/API/10-lang/10-chrono/10-getMinute.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-getMonth.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-getSecond.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-getTimezoneOffset.ts +28 -0
- package/docs/API/10-lang/10-chrono/10-getWeekOfYear.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-getYear.ts +27 -0
- package/docs/API/10-lang/10-chrono/10-greaterThanDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-greaterThanOrEqualDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-greaterThanOrEqualTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-greaterThanTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-isDate.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-isSafeTimeValue.ts +19 -0
- package/docs/API/10-lang/10-chrono/10-isSafeTimestamp.ts +19 -0
- package/docs/API/10-lang/10-chrono/10-isSerializedTheDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-isSerializedTheTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-isTime.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-lessThanDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-lessThanOrEqualDate.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-lessThanOrEqualTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-lessThanTime.ts +26 -0
- package/docs/API/10-lang/10-chrono/10-makeSafeTimeValue.ts +19 -0
- package/docs/API/10-lang/10-chrono/10-makeSafeTimestamp.ts +19 -0
- package/docs/API/10-lang/10-chrono/10-maxDate.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-maxTime.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-minDate.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-minTime.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-now.ts +13 -0
- package/docs/API/10-lang/10-chrono/10-round.ts +41 -0
- package/docs/API/10-lang/10-chrono/10-serialize.ts +23 -0
- package/docs/API/10-lang/10-chrono/10-sortDates.ts +32 -0
- package/docs/API/10-lang/10-chrono/10-sortTimes.ts +31 -0
- package/docs/API/10-lang/10-chrono/10-subtractDays.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractHours.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractMilliseconds.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractMinutes.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractMonths.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractSeconds.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractTime.ts +38 -0
- package/docs/API/10-lang/10-chrono/10-subtractWeeks.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-subtractYears.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-toDateISOString.ts +17 -0
- package/docs/API/10-lang/10-chrono/10-toNative.ts +25 -0
- package/docs/API/10-lang/10-chrono/10-toTimeValue.ts +17 -0
- package/docs/API/10-lang/10-chrono/10-toTimestamp.ts +17 -0
- package/docs/API/10-lang/10-chrono/10-today.ts +13 -0
- package/docs/API/10-lang/10-chrono/10-tomorrow.ts +13 -0
- package/docs/API/10-lang/10-chrono/10-yesterday.ts +13 -0
- package/docs/API/10-lang/10-chrono/index.llms.md +332 -0
- package/docs/API/10-lang/10-chrono/index.md +3 -0
- package/docs/API/10-lang/10-common/10-and.ts +45 -0
- package/docs/API/10-lang/10-common/10-asserts.ts +13 -0
- package/docs/API/10-lang/10-common/10-asyncInnerPipe.ts +23 -0
- package/docs/API/10-lang/10-common/10-asyncLoop.ts +25 -0
- package/docs/API/10-lang/10-common/10-asyncPipe.ts +21 -0
- package/docs/API/10-lang/10-common/10-callThen.ts +22 -0
- package/docs/API/10-lang/10-common/10-cast.ts +16 -0
- package/docs/API/10-lang/10-common/10-clone.ts +12 -0
- package/docs/API/10-lang/10-common/10-createAsyncRetry.ts +34 -0
- package/docs/API/10-lang/10-common/10-createBuilder.ts +19 -0
- package/docs/API/10-lang/10-common/10-createEnum.ts +25 -0
- package/docs/API/10-lang/10-common/10-createExternalPromise.ts +13 -0
- package/docs/API/10-lang/10-common/10-createFormData.ts +16 -0
- package/docs/API/10-lang/10-common/10-createInterpolation.ts +12 -0
- package/docs/API/10-lang/10-common/10-createQueue.ts +16 -0
- package/docs/API/10-lang/10-common/10-createTransformer.ts +16 -0
- package/docs/API/10-lang/10-common/10-detachObjectMethod.ts +20 -0
- package/docs/API/10-lang/10-common/10-equal.ts +31 -0
- package/docs/API/10-lang/10-common/10-escapeRegExp.ts +11 -0
- package/docs/API/10-lang/10-common/10-falsy.ts +12 -0
- package/docs/API/10-lang/10-common/10-forward.ts +11 -0
- package/docs/API/10-lang/10-common/10-forwardAsserts.ts +17 -0
- package/docs/API/10-lang/10-common/10-forwardLog.ts +11 -0
- package/docs/API/10-lang/10-common/10-infer.ts +16 -0
- package/docs/API/10-lang/10-common/10-innerPipe.ts +23 -0
- package/docs/API/10-lang/10-common/10-instanceOf.ts +23 -0
- package/docs/API/10-lang/10-common/10-isType.ts +29 -0
- package/docs/API/10-lang/10-common/10-justExec.ts +28 -0
- package/docs/API/10-lang/10-common/10-justReturn.ts +19 -0
- package/docs/API/10-lang/10-common/10-loop.ts +20 -0
- package/docs/API/10-lang/10-common/10-memo.ts +12 -0
- package/docs/API/10-lang/10-common/10-memoObject.ts +11 -0
- package/docs/API/10-lang/10-common/10-memoPromise.ts +16 -0
- package/docs/API/10-lang/10-common/10-or.ts +29 -0
- package/docs/API/10-lang/10-common/10-pipe.ts +21 -0
- package/docs/API/10-lang/10-common/10-pipeCall.ts +20 -0
- package/docs/API/10-lang/10-common/10-prepareAsyncPipe.ts +20 -0
- package/docs/API/10-lang/10-common/10-preparePipe.ts +20 -0
- package/docs/API/10-lang/10-common/10-promiseAll.ts +16 -0
- package/docs/API/10-lang/10-common/10-promiseObject.ts +22 -0
- package/docs/API/10-lang/10-common/10-removeConstraint.ts +13 -0
- package/docs/API/10-lang/10-common/10-shameOnYou.ts +20 -0
- package/docs/API/10-lang/10-common/10-simpleClone.ts +12 -0
- package/docs/API/10-lang/10-common/10-stringToBytes.ts +16 -0
- package/docs/API/10-lang/10-common/10-stringToMillisecond.ts +17 -0
- package/docs/API/10-lang/10-common/10-timeout.ts +11 -0
- package/docs/API/10-lang/10-common/10-toCurriedPredicate.ts +28 -0
- package/docs/API/10-lang/10-common/10-toJSON.ts +15 -0
- package/docs/API/10-lang/10-common/10-toNative.ts +15 -0
- package/docs/API/10-lang/10-common/10-toRegExp.ts +17 -0
- package/docs/API/10-lang/10-common/10-transformer.ts +21 -0
- package/docs/API/10-lang/10-common/10-truthy.ts +12 -0
- package/docs/API/10-lang/10-common/10-useAsyncRetry.ts +31 -0
- package/docs/API/10-lang/10-common/10-when.ts +27 -0
- package/docs/API/10-lang/10-common/10-whenElse.ts +28 -0
- package/docs/API/10-lang/10-common/10-whenNot.ts +26 -0
- package/docs/API/10-lang/10-common/index.llms.md +228 -0
- package/docs/API/10-lang/10-common/index.md +3 -0
- package/docs/API/10-lang/10-dataStructure/10-absolutePath.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-allowedCharacters.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-array.ts +23 -0
- package/docs/API/10-lang/10-dataStructure/10-arrayLengthEqual.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-betweenThan.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-betweenThanOrEqual.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-bigint.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-boolean.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-createCodec.ts +45 -0
- package/docs/API/10-lang/10-dataStructure/10-createCodecs.ts +134 -0
- package/docs/API/10-lang/10-dataStructure/10-createErrorInterpreter.ts +74 -0
- package/docs/API/10-lang/10-dataStructure/10-date.ts +23 -0
- package/docs/API/10-lang/10-dataStructure/10-email.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-endsWith.ts +24 -0
- package/docs/API/10-lang/10-dataStructure/10-even.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-extend.ts +27 -0
- package/docs/API/10-lang/10-dataStructure/10-greaterThan.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-greaterThanOrEqual.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-include.ts +24 -0
- package/docs/API/10-lang/10-dataStructure/10-integer.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-isNullStructure.ts +12 -0
- package/docs/API/10-lang/10-dataStructure/10-isNullable.ts +12 -0
- package/docs/API/10-lang/10-dataStructure/10-isOptional.ts +12 -0
- package/docs/API/10-lang/10-dataStructure/10-isUndefinedStructure.ts +12 -0
- package/docs/API/10-lang/10-dataStructure/10-lazy.ts +23 -0
- package/docs/API/10-lang/10-dataStructure/10-lessThan.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-lessThanOrEqual.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-literal.ts +19 -0
- package/docs/API/10-lang/10-dataStructure/10-maxCharacters.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-maxElements.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-minCharacters.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-minElements.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-multipleOf.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-negative.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-notEmpty.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-notZero.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-null.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-nullable.ts +19 -0
- package/docs/API/10-lang/10-dataStructure/10-number.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-numberInString.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-object.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-odd.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-optional.ts +19 -0
- package/docs/API/10-lang/10-dataStructure/10-partial.ts +23 -0
- package/docs/API/10-lang/10-dataStructure/10-path.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-positive.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-record.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-refine.ts +27 -0
- package/docs/API/10-lang/10-dataStructure/10-regex.ts +24 -0
- package/docs/API/10-lang/10-dataStructure/10-required.ts +21 -0
- package/docs/API/10-lang/10-dataStructure/10-safe.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-segmentPath.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-startsWith.ts +24 -0
- package/docs/API/10-lang/10-dataStructure/10-strictNegative.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-strictPositive.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-string.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-stringLengthEqual.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-time.ts +23 -0
- package/docs/API/10-lang/10-dataStructure/10-trimmed.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-typeStructureIdentifier.ts +33 -0
- package/docs/API/10-lang/10-dataStructure/10-undefined.ts +22 -0
- package/docs/API/10-lang/10-dataStructure/10-union.ts +24 -0
- package/docs/API/10-lang/10-dataStructure/10-unwrapLazy.ts +17 -0
- package/docs/API/10-lang/10-dataStructure/10-url.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/10-uuid.ts +25 -0
- package/docs/API/10-lang/10-dataStructure/index.llms.md +264 -0
- package/docs/API/10-lang/10-dataStructure/index.md +3 -0
- package/docs/API/10-lang/10-either/10-asyncGroup.ts +44 -0
- package/docs/API/10-lang/10-either/10-asyncSafeCallback.ts +23 -0
- package/docs/API/10-lang/10-either/10-error.ts +12 -0
- package/docs/API/10-lang/10-either/10-expect.ts +13 -0
- package/docs/API/10-lang/10-either/10-fail.ts +12 -0
- package/docs/API/10-lang/10-either/10-forwardAssertsSelection.ts +28 -0
- package/docs/API/10-lang/10-either/10-group.ts +58 -0
- package/docs/API/10-lang/10-either/10-hasInformation.ts +24 -0
- package/docs/API/10-lang/10-either/10-isLeft.ts +16 -0
- package/docs/API/10-lang/10-either/10-isRight.ts +16 -0
- package/docs/API/10-lang/10-either/10-isSelected.ts +29 -0
- package/docs/API/10-lang/10-either/10-keepAsRightByInformation.ts +29 -0
- package/docs/API/10-lang/10-either/10-keepAsRightSelection.ts +23 -0
- package/docs/API/10-lang/10-either/10-left.ts +13 -0
- package/docs/API/10-lang/10-either/10-matchInformation.ts +26 -0
- package/docs/API/10-lang/10-either/10-matchInformationOtherwise.ts +27 -0
- package/docs/API/10-lang/10-either/10-none.ts +12 -0
- package/docs/API/10-lang/10-either/10-ok.ts +12 -0
- package/docs/API/10-lang/10-either/10-result.ts +18 -0
- package/docs/API/10-lang/10-either/10-rewriteInformation.ts +24 -0
- package/docs/API/10-lang/10-either/10-right.ts +13 -0
- package/docs/API/10-lang/10-either/10-rightAsyncPipe.ts +69 -0
- package/docs/API/10-lang/10-either/10-rightPipe.ts +72 -0
- package/docs/API/10-lang/10-either/10-safeCallback.ts +29 -0
- package/docs/API/10-lang/10-either/10-some.ts +12 -0
- package/docs/API/10-lang/10-either/10-success.ts +12 -0
- package/docs/API/10-lang/10-either/10-toMaybe.ts +53 -0
- package/docs/API/10-lang/10-either/10-unwrapByInformation.ts +20 -0
- package/docs/API/10-lang/10-either/10-unwrapByInformationOrThrow.ts +19 -0
- package/docs/API/10-lang/10-either/10-unwrapLeft.ts +14 -0
- package/docs/API/10-lang/10-either/10-unwrapLeftOrThrow.ts +17 -0
- package/docs/API/10-lang/10-either/10-unwrapOr.ts +17 -0
- package/docs/API/10-lang/10-either/10-unwrapOtherwise.ts +20 -0
- package/docs/API/10-lang/10-either/10-unwrapRight.ts +14 -0
- package/docs/API/10-lang/10-either/10-unwrapRightOrThrow.ts +17 -0
- package/docs/API/10-lang/10-either/10-unwrapSelection.ts +26 -0
- package/docs/API/10-lang/10-either/10-unwrapSelectionOrThrow.ts +19 -0
- package/docs/API/10-lang/10-either/10-whenHasInformation.ts +35 -0
- package/docs/API/10-lang/10-either/10-whenHasInformationOtherwise.ts +29 -0
- package/docs/API/10-lang/10-either/10-whenIsLeft.ts +20 -0
- package/docs/API/10-lang/10-either/10-whenIsLeftOtherwise.ts +27 -0
- package/docs/API/10-lang/10-either/10-whenIsRight.ts +20 -0
- package/docs/API/10-lang/10-either/10-whenIsRightOtherwise.ts +26 -0
- package/docs/API/10-lang/10-either/10-whenIsSelected.ts +33 -0
- package/docs/API/10-lang/10-either/10-whenIsSelectedOtherwise.ts +35 -0
- package/docs/API/10-lang/10-either/index.llms.md +184 -0
- package/docs/API/10-lang/10-either/index.md +3 -0
- package/docs/API/10-lang/10-generator/10-asyncChunk.ts +55 -0
- package/docs/API/10-lang/10-generator/10-asyncConcat.ts +46 -0
- package/docs/API/10-lang/10-generator/10-asyncFilter.ts +41 -0
- package/docs/API/10-lang/10-generator/10-asyncFlat.ts +37 -0
- package/docs/API/10-lang/10-generator/10-asyncGroup.ts +65 -0
- package/docs/API/10-lang/10-generator/10-asyncLoop.ts +59 -0
- package/docs/API/10-lang/10-generator/10-asyncMap.ts +48 -0
- package/docs/API/10-lang/10-generator/10-asyncReduce.ts +63 -0
- package/docs/API/10-lang/10-generator/10-chunk.ts +44 -0
- package/docs/API/10-lang/10-generator/10-concat.ts +37 -0
- package/docs/API/10-lang/10-generator/10-createExternalAsyncGenerator.ts +29 -0
- package/docs/API/10-lang/10-generator/10-execute.ts +44 -0
- package/docs/API/10-lang/10-generator/10-filter.ts +35 -0
- package/docs/API/10-lang/10-generator/10-flat.ts +25 -0
- package/docs/API/10-lang/10-generator/10-group.ts +44 -0
- package/docs/API/10-lang/10-generator/10-groupOutput.ts +48 -0
- package/docs/API/10-lang/10-generator/10-loop.ts +55 -0
- package/docs/API/10-lang/10-generator/10-map.ts +35 -0
- package/docs/API/10-lang/10-generator/10-reduce.ts +51 -0
- package/docs/API/10-lang/10-generator/10-reduceFrom.ts +30 -0
- package/docs/API/10-lang/10-generator/index.llms.md +84 -0
- package/docs/API/10-lang/10-generator/index.md +3 -0
- package/docs/API/10-lang/index.md +3 -0
- package/docs/API/index.md +3 -0
- package/docs/API.llms.md +31 -0
- package/docs/concepts/01-fundamental/01-constraint/01-use.ts +22 -0
- package/docs/concepts/01-fundamental/01-constraint/10-built-in-constraint.ts +37 -0
- package/docs/concepts/01-fundamental/01-constraint/20-manipulation.ts +38 -0
- package/docs/concepts/01-fundamental/01-constraint/30-cast.ts +62 -0
- package/docs/concepts/01-fundamental/01-constraint/40-custom-constraint.ts +45 -0
- package/docs/concepts/01-fundamental/01-constraint/index.md +3 -0
- package/docs/concepts/01-fundamental/02-currying/01-use.ts +33 -0
- package/docs/concepts/01-fundamental/02-currying/10-built-in-function.ts +178 -0
- package/docs/concepts/01-fundamental/02-currying/20-inner-pipe.ts +39 -0
- package/docs/concepts/01-fundamental/02-currying/30-async-pipe.ts +42 -0
- package/docs/concepts/01-fundamental/02-currying/index.md +3 -0
- package/docs/concepts/01-fundamental/03-either/01-use.ts +21 -0
- package/docs/concepts/01-fundamental/03-either/10-discrimination.ts +79 -0
- package/docs/concepts/01-fundamental/03-either/20-exhaustive-handling.ts +73 -0
- package/docs/concepts/01-fundamental/03-either/30-composition.ts +72 -0
- package/docs/concepts/01-fundamental/03-either/40-result-adaptation.ts +40 -0
- package/docs/concepts/01-fundamental/03-either/50-external-results.ts +59 -0
- package/docs/concepts/01-fundamental/03-either/60-contextual-state.ts +40 -0
- package/docs/concepts/01-fundamental/03-either/index.md +3 -0
- package/docs/concepts/01-fundamental/04-data-structure/01-use.ts +22 -0
- package/docs/concepts/01-fundamental/04-data-structure/10-structure.ts +193 -0
- package/docs/concepts/01-fundamental/04-data-structure/20-constraint.ts +78 -0
- package/docs/concepts/01-fundamental/04-data-structure/30-validation.ts +100 -0
- package/docs/concepts/01-fundamental/04-data-structure/40-codecs.ts +151 -0
- package/docs/concepts/01-fundamental/04-data-structure/50-recursive.ts +48 -0
- package/docs/concepts/01-fundamental/04-data-structure/60-interpret-error.ts +123 -0
- package/docs/concepts/01-fundamental/04-data-structure/index.md +3 -0
- package/docs/concepts/01-fundamental/05-chrono/01-use.ts +14 -0
- package/docs/concepts/01-fundamental/05-chrono/10-creation.ts +59 -0
- package/docs/concepts/01-fundamental/05-chrono/20-manipulation.ts +94 -0
- package/docs/concepts/01-fundamental/05-chrono/30-serialized.ts +73 -0
- package/docs/concepts/01-fundamental/05-chrono/40-timezone.ts +81 -0
- package/docs/concepts/01-fundamental/05-chrono/index.md +3 -0
- package/docs/concepts/01-fundamental/06-modeling/10-new-type.ts +42 -0
- package/docs/concepts/01-fundamental/06-modeling/20-entity.ts +204 -0
- package/docs/concepts/01-fundamental/06-modeling/30-tagged-object.ts +181 -0
- package/docs/concepts/01-fundamental/06-modeling/40-entity-lifecycle.ts +275 -0
- package/docs/concepts/01-fundamental/06-modeling/50-evidence.ts +94 -0
- package/docs/concepts/01-fundamental/06-modeling/60-signed-function.ts +26 -0
- package/docs/concepts/01-fundamental/06-modeling/index.md +3 -0
- package/docs/concepts/01-fundamental/07-discrimination/10-entity.ts +104 -0
- package/docs/concepts/01-fundamental/07-discrimination/20-fact.ts +142 -0
- package/docs/concepts/01-fundamental/07-discrimination/30-tagged-object.ts +105 -0
- package/docs/concepts/01-fundamental/07-discrimination/40-error.ts +57 -0
- package/docs/concepts/01-fundamental/07-discrimination/50-literal.ts +87 -0
- package/docs/concepts/01-fundamental/07-discrimination/60-shape.ts +152 -0
- package/docs/concepts/01-fundamental/07-discrimination/70-predicate.ts +89 -0
- package/docs/concepts/01-fundamental/07-discrimination/index.md +3 -0
- package/docs/concepts/01-fundamental/index.md +1 -0
- package/docs/concepts/02-server/10-file/10-manipulation.ts +40 -0
- package/docs/concepts/02-server/10-file/20-path.ts +56 -0
- package/docs/concepts/02-server/10-file/index.md +3 -0
- package/docs/concepts/02-server/20-http/10-init.ts +31 -0
- package/docs/concepts/02-server/20-http/20-route.ts +174 -0
- package/docs/concepts/02-server/20-http/30-routine.ts +195 -0
- package/docs/concepts/02-server/20-http/40-jwt.ts +137 -0
- package/docs/concepts/02-server/20-http/50-codegen.ts +29 -0
- package/docs/concepts/02-server/20-http/index.md +3 -0
- package/docs/concepts/02-server/30-environment/10-platform.ts +38 -0
- package/docs/concepts/02-server/30-environment/20-variable.ts +41 -0
- package/docs/concepts/02-server/30-environment/index.md +3 -0
- package/docs/concepts/02-server/40-command/10-use.ts +112 -0
- package/docs/concepts/02-server/40-command/20-sub-command.ts +48 -0
- package/docs/concepts/02-server/40-command/index.md +3 -0
- package/docs/concepts/02-server/index.md +1 -0
- package/docs/concepts/03-client/10-http/10-init.ts +64 -0
- package/docs/concepts/03-client/10-http/20-request.ts +244 -0
- package/docs/concepts/03-client/10-http/30-hook.ts +139 -0
- package/docs/concepts/03-client/10-http/index.md +3 -0
- package/docs/concepts/03-client/20-form/10-init.ts +95 -0
- package/docs/concepts/03-client/20-form/20-input.ts +96 -0
- package/docs/concepts/03-client/20-form/30-layout.ts +160 -0
- package/docs/concepts/03-client/20-form/40-template.ts +89 -0
- package/docs/concepts/03-client/20-form/index.md +3 -0
- package/docs/concepts/03-client/index.md +1 -0
- package/docs/concepts/04-tests/01-unit/10-either.ts +136 -0
- package/docs/concepts/04-tests/01-unit/20-server-mocking.ts +53 -0
- package/docs/concepts/04-tests/01-unit/index.md +3 -0
- package/docs/concepts/04-tests/02-e2e/10-init.ts +80 -0
- package/docs/concepts/04-tests/02-e2e/20-architecture.ts +76 -0
- package/docs/concepts/04-tests/02-e2e/30-testing.ts +90 -0
- package/docs/concepts/04-tests/02-e2e/index.md +3 -0
- package/docs/concepts/04-tests/index.md +1 -0
- package/docs/concepts/05-type-driven-design/01-architecture/10-boundaries.md +41 -0
- package/docs/concepts/05-type-driven-design/01-architecture/index.md +3 -0
- package/docs/concepts/05-type-driven-design/02-domains/10-entities.md +58 -0
- package/docs/concepts/05-type-driven-design/02-domains/20-aggregates.md +49 -0
- package/docs/concepts/05-type-driven-design/02-domains/30-repositories.md +41 -0
- package/docs/concepts/05-type-driven-design/02-domains/index.md +3 -0
- package/docs/concepts/05-type-driven-design/03-applications/10-use-case.md +69 -0
- package/docs/concepts/05-type-driven-design/03-applications/index.md +3 -0
- package/docs/concepts/05-type-driven-design/04-infrastructure/10-implementation.md +56 -0
- package/docs/concepts/05-type-driven-design/04-infrastructure/index.md +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/ports/book.ts +10 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/ports/client.ts +10 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/ports/email.ts +7 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/ports/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/useCases/clientGiveBackBook.ts +27 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/useCases/clientRentBook.ts +30 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/useCases/createBook.ts +32 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/applications/useCases/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/aggregates/clientGiveBackBook.ts +15 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/aggregates/clientRentBook.ts +16 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/aggregates/createBook.ts +21 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/aggregates/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/book/facts/create.ts +34 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/book/facts/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/book/facts/rental.ts +31 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/book/facts/returnBook.ts +30 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/book/index.ts +87 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/client/facts/giveBackBook.ts +33 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/client/facts/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/client/facts/rentBook.ts +32 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/client/index.ts +82 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/entities/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/repositories/book.ts +16 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/repositories/client.ts +7 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/repositories/email.ts +12 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/domains/repositories/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/business/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/command/clientRentBook.ts +62 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/command/index.ts +11 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/checkers/bookExist.ts +19 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/checkers/clientExist.ts +19 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/checkers/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/main.ts +19 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/routes/clientGiveBackBook.ts +37 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/routes/clientRentBook.ts +50 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/http/routes/index.ts +2 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/ports/book.ts +25 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/ports/client.ts +7 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/ports/email.ts +10 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/ports/index.ts +3 -0
- package/docs/concepts/05-type-driven-design/fixtures/infrastructure/useCases/index.ts +12 -0
- package/docs/concepts/05-type-driven-design/index.md +3 -0
- package/docs/concepts.llms.md +475 -0
- package/instructions/coding-conventions.md +8 -0
- package/package.json +96 -3
- package/skills/command/SKILL.md +63 -0
- package/skills/command/references/examples/cli.ts +22 -0
- package/skills/command/references/examples/options-only.ts +27 -0
- package/skills/command/references/examples/preview-command.ts +57 -0
- package/skills/command/references/execution.md +31 -0
- package/skills/command/references/inputs.md +27 -0
- package/skills/fundamental/SKILL.md +80 -0
- package/skills/fundamental/references/composition.md +35 -0
- package/skills/fundamental/references/constraints-and-validation.md +61 -0
- package/skills/fundamental/references/examples/async-composition.ts +15 -0
- package/skills/fundamental/references/examples/cast.ts +18 -0
- package/skills/fundamental/references/examples/composition.ts +40 -0
- package/skills/fundamental/references/examples/environment-initialization.ts +19 -0
- package/skills/fundamental/references/examples/error-propagation.ts +24 -0
- package/skills/fundamental/references/examples/generic-inference.ts +31 -0
- package/skills/fundamental/references/examples/guaranteed-array-access.ts +31 -0
- package/skills/fundamental/references/examples/independent-inputs.ts +18 -0
- package/skills/fundamental/references/examples/infer.ts +21 -0
- package/skills/fundamental/references/examples/input-validation.ts +37 -0
- package/skills/fundamental/references/examples/safe-declarations.ts +25 -0
- package/skills/fundamental/references/results-and-errors.md +59 -0
- package/skills/http-client/SKILL.md +50 -0
- package/skills/http-client/references/configuration.md +9 -0
- package/skills/http-client/references/examples/client-expectations.ts +84 -0
- package/skills/http-client/references/examples/client-streams.ts +74 -0
- package/skills/http-client/references/examples/external-client.ts +78 -0
- package/skills/http-client/references/hooks.md +7 -0
- package/skills/http-client/references/responses.md +39 -0
- package/skills/http-client/references/streams.md +10 -0
- package/skills/http-server/SKILL.md +66 -0
- package/skills/http-server/references/code-generation.md +31 -0
- package/skills/http-server/references/examples/authentication.ts +42 -0
- package/skills/http-server/references/examples/contracts.ts +19 -0
- package/skills/http-server/references/examples/generate-sdk.ts +36 -0
- package/skills/http-server/references/examples/initialize.ts +29 -0
- package/skills/http-server/references/examples/minimal-route.ts +18 -0
- package/skills/http-server/references/examples/protected-route.ts +31 -0
- package/skills/http-server/references/examples/rename-user-route.ts +54 -0
- package/skills/http-server/references/examples/user-checker.ts +26 -0
- package/skills/http-server/references/examples/user-route.ts +38 -0
- package/skills/http-server/references/initialization.md +33 -0
- package/skills/http-server/references/reusable-flows.md +40 -0
- package/skills/http-server/references/routes-and-floor.md +38 -0
- package/skills/modeling/SKILL.md +76 -0
- package/skills/modeling/references/domain.md +33 -0
- package/skills/modeling/references/orchestration.md +36 -0
- package/skills/server/SKILL.md +55 -0
- package/skills/server/references/environment.md +30 -0
- package/skills/server/references/examples/environment.ts +41 -0
- package/skills/server/references/examples/file-structure.ts +26 -0
- package/skills/server/references/examples/files.ts +52 -0
- package/skills/server/references/files.md +38 -0
- package/skills/server/references/structures.md +15 -0
- package/skills/test/SKILL.md +70 -0
- package/skills/test/references/examples/results.ts +95 -0
- package/skills/test/references/examples/server.ts +59 -0
- package/skills/test/references/results.md +21 -0
- package/skills/test/references/server.md +17 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Contrats de données avec DataStructure.
|
|
3
|
+
*
|
|
4
|
+
* Décrire les données attendues et obtenir des valeurs typées après validation.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
import * as DEither from "@duplojs/lang/either";
|
|
8
|
+
|
|
9
|
+
// Une structure porte le même contrat dans TypeScript et au runtime.
|
|
10
|
+
// L’utiliser aux frontières du logiciel pour vérifier les données encore inconnues.
|
|
11
|
+
const userStructure = DDataStructure.object({
|
|
12
|
+
name: DDataStructure.string(),
|
|
13
|
+
email: DDataStructure.string([DDataStructure.email()]),
|
|
14
|
+
});
|
|
15
|
+
type User = DDataStructure.StructureValue<typeof userStructure>;
|
|
16
|
+
|
|
17
|
+
declare const input: unknown;
|
|
18
|
+
const result = userStructure.check(input);
|
|
19
|
+
if (DEither.isRight(result)) {
|
|
20
|
+
const user: User = DEither.unwrapRight(result);
|
|
21
|
+
}
|
|
22
|
+
// Un Left conserve une erreur structurée lorsque la validation échoue.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Composition des contrats de données.
|
|
3
|
+
*
|
|
4
|
+
* Construire et réutiliser des structures pour décrire des données simples ou composées.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
|
|
8
|
+
// Une Structure associe un type TypeScript à une représentation capable de vérifier la donnée.
|
|
9
|
+
// Une TypeStructure repose sur un Type ; les autres structures composent plusieurs contrats.
|
|
10
|
+
|
|
11
|
+
// string
|
|
12
|
+
const nameStructure = DDataStructure.string();
|
|
13
|
+
|
|
14
|
+
// number
|
|
15
|
+
const ageStructure = DDataStructure.number();
|
|
16
|
+
|
|
17
|
+
// boolean
|
|
18
|
+
const activeStructure = DDataStructure.boolean();
|
|
19
|
+
|
|
20
|
+
// Les structures simples comme `string`, `number` ou `boolean` sont des
|
|
21
|
+
// `TypeStructure`. Elles représentent directement un type fondamental.
|
|
22
|
+
|
|
23
|
+
// "user"
|
|
24
|
+
const userKindStructure = DDataStructure.literal("user");
|
|
25
|
+
|
|
26
|
+
// `literal` produit également une `TypeStructure` lorsqu'une seule valeur
|
|
27
|
+
// est représentée.
|
|
28
|
+
|
|
29
|
+
// "admin" | "member" | "guest"
|
|
30
|
+
const roleStructure = DDataStructure.literal([
|
|
31
|
+
"admin",
|
|
32
|
+
"member",
|
|
33
|
+
"guest",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
// Lorsque plusieurs valeurs sont représentées, `literal` construit une
|
|
37
|
+
// `UnionStructure` composée de plusieurs `TypeStructure`.
|
|
38
|
+
|
|
39
|
+
// {
|
|
40
|
+
// readonly street: string;
|
|
41
|
+
// readonly city: string;
|
|
42
|
+
// readonly zipCode: string;
|
|
43
|
+
// }
|
|
44
|
+
const addressStructure = DDataStructure.object({
|
|
45
|
+
street: DDataStructure.string(),
|
|
46
|
+
city: DDataStructure.string(),
|
|
47
|
+
zipCode: DDataStructure.string(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// `ObjectStructure` compose plusieurs structures pour représenter les
|
|
51
|
+
// propriétés d'un objet.
|
|
52
|
+
|
|
53
|
+
// {
|
|
54
|
+
// readonly name: string;
|
|
55
|
+
// readonly age: number;
|
|
56
|
+
// readonly active: boolean;
|
|
57
|
+
// readonly role: "admin" | "member" | "guest";
|
|
58
|
+
// readonly address: Address;
|
|
59
|
+
// }
|
|
60
|
+
const userStructure = DDataStructure.object({
|
|
61
|
+
name: nameStructure,
|
|
62
|
+
age: ageStructure,
|
|
63
|
+
active: activeStructure,
|
|
64
|
+
role: roleStructure,
|
|
65
|
+
address: addressStructure,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Une structure déjà définie peut et doit être réutilisée pour construire
|
|
69
|
+
// des structures plus complexes.
|
|
70
|
+
|
|
71
|
+
// readonly User[]
|
|
72
|
+
const usersStructure = DDataStructure.array(
|
|
73
|
+
userStructure,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// `array` applique une même structure à chaque élément du tableau.
|
|
77
|
+
|
|
78
|
+
// {
|
|
79
|
+
// readonly name: string;
|
|
80
|
+
// readonly bio?: string | undefined;
|
|
81
|
+
// }
|
|
82
|
+
const profileStructure = DDataStructure.object({
|
|
83
|
+
name: DDataStructure.string(),
|
|
84
|
+
bio: DDataStructure.optional(
|
|
85
|
+
DDataStructure.string(),
|
|
86
|
+
),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
type Profile = DDataStructure.StructureValue<typeof profileStructure>;
|
|
90
|
+
|
|
91
|
+
// `optional` ajoute `undefined` à une structure.
|
|
92
|
+
// Dans un `ObjectStructure`, cela permet également d'omettre la propriété.
|
|
93
|
+
|
|
94
|
+
// {
|
|
95
|
+
// readonly user: User | null;
|
|
96
|
+
// }
|
|
97
|
+
const sessionStructure = DDataStructure.object({
|
|
98
|
+
user: DDataStructure.nullable(
|
|
99
|
+
userStructure,
|
|
100
|
+
),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// `nullable` ajoute `null` à une structure sans rendre la propriété optionnelle.
|
|
104
|
+
|
|
105
|
+
// string | number
|
|
106
|
+
const identifierStructure = DDataStructure.union([
|
|
107
|
+
DDataStructure.string(),
|
|
108
|
+
DDataStructure.number(),
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
// `union` représente plusieurs structures possibles.
|
|
112
|
+
|
|
113
|
+
// {
|
|
114
|
+
// readonly type: "user-created";
|
|
115
|
+
// readonly user: User;
|
|
116
|
+
// }
|
|
117
|
+
// |
|
|
118
|
+
// {
|
|
119
|
+
// readonly type: "user-deleted";
|
|
120
|
+
// readonly userId: string | number;
|
|
121
|
+
// }
|
|
122
|
+
const eventStructure = DDataStructure.union([
|
|
123
|
+
DDataStructure.object({
|
|
124
|
+
type: DDataStructure.literal("user-created"),
|
|
125
|
+
user: userStructure,
|
|
126
|
+
}),
|
|
127
|
+
DDataStructure.object({
|
|
128
|
+
type: DDataStructure.literal("user-deleted"),
|
|
129
|
+
userId: identifierStructure,
|
|
130
|
+
}),
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
// Les unions peuvent représenter plusieurs formes d'objets.
|
|
134
|
+
// Des valeurs littérales peuvent être utilisées pour créer une union discriminée.
|
|
135
|
+
|
|
136
|
+
// {
|
|
137
|
+
// readonly fr: string;
|
|
138
|
+
// readonly en: string;
|
|
139
|
+
// }
|
|
140
|
+
const translationsStructure = DDataStructure.record(
|
|
141
|
+
DDataStructure.literal([
|
|
142
|
+
"fr",
|
|
143
|
+
"en",
|
|
144
|
+
]),
|
|
145
|
+
DDataStructure.string(),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// `record` représente un objet dont les clés possibles et les valeurs
|
|
149
|
+
// sont elles-mêmes décrites par des structures.
|
|
150
|
+
|
|
151
|
+
// {
|
|
152
|
+
// readonly name?: string | undefined;
|
|
153
|
+
// readonly age?: number | undefined;
|
|
154
|
+
// readonly active?: boolean | undefined;
|
|
155
|
+
// readonly role?: "admin" | "member" | "guest" | undefined;
|
|
156
|
+
// readonly address?: Address | undefined;
|
|
157
|
+
// }
|
|
158
|
+
const updateUserStructure = DDataStructure.partial(
|
|
159
|
+
userStructure,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// `partial` transforme toutes les propriétés d'un `ObjectStructure`
|
|
163
|
+
// en propriétés optionnelles.
|
|
164
|
+
|
|
165
|
+
// {
|
|
166
|
+
// readonly name: string;
|
|
167
|
+
// readonly bio: string;
|
|
168
|
+
// }
|
|
169
|
+
const requiredProfileStructure = DDataStructure.required(
|
|
170
|
+
profileStructure,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// `required` réalise l'opération inverse et rend les propriétés obligatoires.
|
|
174
|
+
|
|
175
|
+
// {
|
|
176
|
+
// readonly name: string;
|
|
177
|
+
// readonly age: number;
|
|
178
|
+
// readonly active: boolean;
|
|
179
|
+
// readonly role: "admin" | "member" | "guest";
|
|
180
|
+
// readonly address: Address;
|
|
181
|
+
// readonly id: string | number;
|
|
182
|
+
// readonly createdAt: string;
|
|
183
|
+
// }
|
|
184
|
+
const persistedUserStructure = DDataStructure.extend(
|
|
185
|
+
userStructure,
|
|
186
|
+
{
|
|
187
|
+
id: identifierStructure,
|
|
188
|
+
createdAt: DDataStructure.string(),
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// `extend` crée un nouvel `ObjectStructure` en ajoutant des propriétés
|
|
193
|
+
// à une structure objet existante.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Contraintes de validation dans les structures.
|
|
3
|
+
*
|
|
4
|
+
* Ajouter et cumuler des contraintes compatibles, fournies ou personnalisées.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
|
|
8
|
+
// Une structure vérifie la nature de la donnée, puis ses propriétés supplémentaires.
|
|
9
|
+
// Les contraintes sont vérifiées au runtime et enrichissent le type obtenu par StructureValue.
|
|
10
|
+
// Toute structure peut en recevoir, à condition que la contrainte soit compatible.
|
|
11
|
+
|
|
12
|
+
// string & DString.Email
|
|
13
|
+
const emailStructure = DDataStructure.string([DDataStructure.email()]);
|
|
14
|
+
|
|
15
|
+
// Une contrainte ne remplace pas le type de base.
|
|
16
|
+
// Elle apporte une information supplémentaire garantie après validation.
|
|
17
|
+
|
|
18
|
+
// number & DNumber.Integer & DNumber.GreaterThanOrEqual<18>
|
|
19
|
+
const ageStructure = DDataStructure.number([
|
|
20
|
+
DDataStructure.integer(),
|
|
21
|
+
DDataStructure.greaterThanOrEqual(18),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
type Age = DDataStructure.StructureValue<typeof ageStructure>;
|
|
25
|
+
|
|
26
|
+
// Plusieurs contraintes peuvent être cumulées.
|
|
27
|
+
// Toutes doivent être vérifiées pour que la donnée soit valide.
|
|
28
|
+
|
|
29
|
+
// string & DString.MinCharacters<3> & DString.Trimmed
|
|
30
|
+
const usernameStructure = DDataStructure.string([
|
|
31
|
+
DDataStructure.minCharacters(3),
|
|
32
|
+
DDataStructure.trimmed(),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
// Les contraintes ne concernent pas uniquement les `TypeStructure`.
|
|
36
|
+
// Elles peuvent s'appliquer aux autres structures comme les tableaux.
|
|
37
|
+
|
|
38
|
+
// readonly string[] & DArray.MinElements<1>
|
|
39
|
+
const tagsStructure = DDataStructure.array(
|
|
40
|
+
DDataStructure.string(),
|
|
41
|
+
[DDataStructure.minElements(1)],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Une contrainte peut également être ajoutée après la création d'une structure.
|
|
45
|
+
// La structure originale n'est pas modifiée.
|
|
46
|
+
|
|
47
|
+
// string
|
|
48
|
+
const stringStructure = DDataStructure.string();
|
|
49
|
+
|
|
50
|
+
// string & DString.Email
|
|
51
|
+
const constrainedStringStructure = stringStructure.addConstraint(
|
|
52
|
+
DDataStructure.email(),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// `refine` permet de définir une contrainte spécifique au domaine.
|
|
56
|
+
// Un type predicate permet également d'affiner le type produit par la structure.
|
|
57
|
+
|
|
58
|
+
type UserId = `user:${string}`;
|
|
59
|
+
|
|
60
|
+
// `user:${string}`
|
|
61
|
+
const userIdStructure = DDataStructure.string([
|
|
62
|
+
DDataStructure.refine(
|
|
63
|
+
(value): value is UserId => value.startsWith("user:"),
|
|
64
|
+
),
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// Une contrainte ne peut être utilisée que sur une structure compatible.
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error `positive` est une contrainte de nombre.
|
|
70
|
+
DDataStructure.string([DDataStructure.positive()]);
|
|
71
|
+
|
|
72
|
+
// @ts-expect-error `email` est une contrainte de string.
|
|
73
|
+
DDataStructure.number([DDataStructure.email()]);
|
|
74
|
+
|
|
75
|
+
// La compatibilité est également vérifiée avec `addConstraint`.
|
|
76
|
+
|
|
77
|
+
// @ts-expect-error une structure de tableau ne peut pas recevoir une contrainte de string.
|
|
78
|
+
DDataStructure.array(DDataStructure.string()).addConstraint(DDataStructure.email());
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Validation des données entrantes.
|
|
3
|
+
*
|
|
4
|
+
* Vérification, conversion et narrowing aux frontières du logiciel, en synchrone ou asynchrone.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
|
|
8
|
+
// La structure décrit la donnée attendue à la fois dans TypeScript et au runtime.
|
|
9
|
+
// Les opérations ci-dessous s’appliquent aux frontières du logiciel, avant de considérer
|
|
10
|
+
// une donnée externe comme fiable.
|
|
11
|
+
const componentStructure = DDataStructure.object({
|
|
12
|
+
id: DDataStructure.bigint(),
|
|
13
|
+
name: DDataStructure.string(),
|
|
14
|
+
alt: DDataStructure.optional(
|
|
15
|
+
DDataStructure.string(),
|
|
16
|
+
),
|
|
17
|
+
image: DDataStructure.object({
|
|
18
|
+
src: DDataStructure.string([DDataStructure.url()]),
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Le type TypeScript correspondant à une structure peut être récupéré
|
|
23
|
+
// avec `StructureValue`.
|
|
24
|
+
//
|
|
25
|
+
// {
|
|
26
|
+
// readonly id: bigint;
|
|
27
|
+
// readonly name: string;
|
|
28
|
+
// readonly alt?: string | undefined;
|
|
29
|
+
// readonly image: {
|
|
30
|
+
// readonly src: string & DString.Url;
|
|
31
|
+
// };
|
|
32
|
+
// }
|
|
33
|
+
type Component = DDataStructure.StructureValue<typeof componentStructure>;
|
|
34
|
+
|
|
35
|
+
declare const unknownComponent: unknown;
|
|
36
|
+
|
|
37
|
+
// check, decode et encode retournent un Either : donnée valide ou erreur structurée.
|
|
38
|
+
// `check` valide une donnée déjà dans sa représentation interne.
|
|
39
|
+
//
|
|
40
|
+
// Il est principalement utilisé lorsqu'une donnée provient d'une source
|
|
41
|
+
// non fiable mais ne nécessite aucune transformation de représentation.
|
|
42
|
+
const checkResult = componentStructure.check(
|
|
43
|
+
unknownComponent,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// `decode` transforme une représentation externe vers la représentation
|
|
47
|
+
// interne décrite par la structure, puis valide la donnée obtenue.
|
|
48
|
+
//
|
|
49
|
+
// Ici, `codecsJson` permet notamment de transformer `string` en `bigint`.
|
|
50
|
+
const decodeResult = componentStructure.decode(
|
|
51
|
+
DDataStructure.codecsJson,
|
|
52
|
+
{
|
|
53
|
+
id: "42",
|
|
54
|
+
name: "Header",
|
|
55
|
+
image: {
|
|
56
|
+
src: "https://duplojs.dev/image.png",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
declare const component: Component;
|
|
62
|
+
|
|
63
|
+
// `encode` réalise l'opération inverse de `decode`.
|
|
64
|
+
//
|
|
65
|
+
// Il vérifie la donnée interne avant de la transformer vers la représentation attendue
|
|
66
|
+
// par le système externe.
|
|
67
|
+
//
|
|
68
|
+
// Ici, `codecsJson` transforme notamment `bigint` en `string`.
|
|
69
|
+
const encodeResult = componentStructure.encode(
|
|
70
|
+
DDataStructure.codecsJson,
|
|
71
|
+
component,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
declare const value: unknown;
|
|
75
|
+
|
|
76
|
+
// `is` permet de vérifier simplement si une donnée respecte la structure.
|
|
77
|
+
//
|
|
78
|
+
// Contrairement à `check`, il ne retourne pas les détails de l'erreur.
|
|
79
|
+
// Il agit également comme un type predicate TypeScript.
|
|
80
|
+
if (componentStructure.is(value)) {
|
|
81
|
+
// Component
|
|
82
|
+
void value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Les variantes asyncCheck, asyncDecode et asyncEncode attendent les traitements asynchrones.
|
|
86
|
+
// Une opération synchrone rencontrant une Promise retourne un Left "async-error".
|
|
87
|
+
// is retourne false dans ce cas ; il ne peut pas attendre une validation asynchrone.
|
|
88
|
+
const asyncCheckResult = componentStructure.asyncCheck(
|
|
89
|
+
unknownComponent,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const asyncDecodeResult = componentStructure.asyncDecode(
|
|
93
|
+
DDataStructure.codecsJson,
|
|
94
|
+
unknownComponent,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const asyncEncodeResult = componentStructure.asyncEncode(
|
|
98
|
+
DDataStructure.codecsJson,
|
|
99
|
+
component,
|
|
100
|
+
);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Changement de représentation avec des codecs.
|
|
3
|
+
*
|
|
4
|
+
* Encoder et décoder les données avec un même contrat, selon leur type fondamental.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
import * as DString from "@duplojs/lang/string";
|
|
8
|
+
|
|
9
|
+
// Un codec fait transiter les données entre deux représentations d’une même structure.
|
|
10
|
+
// encode convertit la représentation interne vers l’externe ; decode effectue l’inverse.
|
|
11
|
+
// Le contexte associe les codecs aux types fondamentaux pendant le parcours de la structure.
|
|
12
|
+
|
|
13
|
+
// Les `FundamentalType` représentent les familles fondamentales de données.
|
|
14
|
+
//
|
|
15
|
+
// Par exemple :
|
|
16
|
+
// `number()` utilise `TheNumber`.
|
|
17
|
+
// `string()` utilise `TheString`.
|
|
18
|
+
// `bigint()` utilise `TheBigint`.
|
|
19
|
+
//
|
|
20
|
+
// Le codec utilise ce `FundamentalType` comme repère pour savoir
|
|
21
|
+
// quelles valeurs il doit transformer.
|
|
22
|
+
|
|
23
|
+
// Codec : number <-> string
|
|
24
|
+
const numberStringCodec = DDataStructure.createCodec(
|
|
25
|
+
DDataStructure.TheNumber,
|
|
26
|
+
|
|
27
|
+
// Décrit la représentation externe acceptée par le codec.
|
|
28
|
+
(data) => (
|
|
29
|
+
typeof data === "string"
|
|
30
|
+
&& DString.isNumber(data)
|
|
31
|
+
),
|
|
32
|
+
|
|
33
|
+
// encode : number -> string
|
|
34
|
+
DString.to,
|
|
35
|
+
|
|
36
|
+
// decode : string -> number
|
|
37
|
+
(data) => Number(data),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Les codecs sont regroupés dans un contexte.
|
|
41
|
+
// Un `FundamentalType` ne peut avoir qu'un seul codec dans ce contexte.
|
|
42
|
+
const codecs = DDataStructure.createCodecs({
|
|
43
|
+
number: numberStringCodec,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Une seule structure décrit la donnée.
|
|
47
|
+
// Les codecs vont modifier sa représentation sans nécessiter
|
|
48
|
+
// de créer une seconde structure pour la forme encodée.
|
|
49
|
+
const productStructure = DDataStructure.object({
|
|
50
|
+
name: DDataStructure.string(),
|
|
51
|
+
price: DDataStructure.number(),
|
|
52
|
+
quantity: DDataStructure.number([
|
|
53
|
+
DDataStructure.integer(),
|
|
54
|
+
DDataStructure.positive(),
|
|
55
|
+
]),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// DEither.Right<
|
|
59
|
+
// "encode-success",
|
|
60
|
+
// {
|
|
61
|
+
// readonly name: string;
|
|
62
|
+
// readonly price: string & DString.Number;
|
|
63
|
+
// readonly quantity: string & DString.Number;
|
|
64
|
+
// }
|
|
65
|
+
// >
|
|
66
|
+
// | DEither.Left<"async-error", DDataStructure.ErrorPromise>
|
|
67
|
+
// | DEither.Left<"encode-error", DDataStructure.Error>
|
|
68
|
+
const encodedProduct = productStructure.encode(
|
|
69
|
+
codecs,
|
|
70
|
+
{
|
|
71
|
+
name: "Keyboard",
|
|
72
|
+
price: 99.9,
|
|
73
|
+
quantity: 2,
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Pendant l'encode, la structure est parcourue.
|
|
78
|
+
//
|
|
79
|
+
// `name` utilise `TheString`.
|
|
80
|
+
// Aucun codec n'est enregistré pour `TheString`, la valeur reste inchangée.
|
|
81
|
+
//
|
|
82
|
+
// `price` et `quantity` utilisent `TheNumber`.
|
|
83
|
+
// Le codec associé à `TheNumber` transforme donc automatiquement
|
|
84
|
+
// leurs valeurs de `number` vers `string`.
|
|
85
|
+
|
|
86
|
+
// DEither.Right<
|
|
87
|
+
// "decode-success",
|
|
88
|
+
// {
|
|
89
|
+
// readonly name: string;
|
|
90
|
+
// readonly price: number;
|
|
91
|
+
// readonly quantity: number & DNumber.Integer & DNumber.Positive;
|
|
92
|
+
// }
|
|
93
|
+
// >
|
|
94
|
+
// | DEither.Left<"async-error", DDataStructure.ErrorPromise>
|
|
95
|
+
// | DEither.Left<"decode-error", DDataStructure.Error>
|
|
96
|
+
const decodedProduct = productStructure.decode(
|
|
97
|
+
codecs,
|
|
98
|
+
{
|
|
99
|
+
name: "Keyboard",
|
|
100
|
+
price: "99.9",
|
|
101
|
+
quantity: "2",
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Le decode parcourt exactement la même structure dans le sens inverse.
|
|
106
|
+
//
|
|
107
|
+
// Le codec retrouve les valeurs associées à `TheNumber`, vérifie que
|
|
108
|
+
// leur représentation externe est valide, puis les transforme en `number`.
|
|
109
|
+
//
|
|
110
|
+
// Les contraintes de la structure sont ensuite toujours appliquées.
|
|
111
|
+
// `"2"` devient donc `2`, puis `integer()` et `positive()` sont vérifiés.
|
|
112
|
+
|
|
113
|
+
// Ce principe permet de définir différents systèmes de représentation
|
|
114
|
+
// sans modifier les structures métier.
|
|
115
|
+
//
|
|
116
|
+
// `codecsString` applique ce principe pour représenter les types
|
|
117
|
+
// fondamentaux sous forme de chaînes de caractères.
|
|
118
|
+
//
|
|
119
|
+
// `codecsJson` applique le même principe aux types qui ne possèdent pas
|
|
120
|
+
// naturellement de représentation JSON, notamment :
|
|
121
|
+
//
|
|
122
|
+
// bigint -> string
|
|
123
|
+
// date -> string
|
|
124
|
+
// time -> string
|
|
125
|
+
|
|
126
|
+
const stringEncodedProduct = productStructure.encode(
|
|
127
|
+
DDataStructure.codecsString,
|
|
128
|
+
{
|
|
129
|
+
name: "Keyboard",
|
|
130
|
+
price: 99.9,
|
|
131
|
+
quantity: 2,
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Le principe reste toujours le même :
|
|
136
|
+
//
|
|
137
|
+
// état interne
|
|
138
|
+
// |
|
|
139
|
+
// encode
|
|
140
|
+
// |
|
|
141
|
+
// v
|
|
142
|
+
// état externe
|
|
143
|
+
// |
|
|
144
|
+
// decode
|
|
145
|
+
// |
|
|
146
|
+
// v
|
|
147
|
+
// état interne
|
|
148
|
+
//
|
|
149
|
+
// La `DataStructure` définit la forme de la donnée.
|
|
150
|
+
// Le `FundamentalType` identifie la famille de valeur.
|
|
151
|
+
// Le `Codec` définit comment cette famille transite entre les deux états.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Contrats de données récursifs.
|
|
3
|
+
*
|
|
4
|
+
* Références différées et cohérence entre un type déclaré et sa structure runtime.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
|
|
8
|
+
// Une structure récursive se référence elle-même. Le type attendu est déclaré en amont
|
|
9
|
+
// pour permettre à TypeScript de typer cette dépendance récursive.
|
|
10
|
+
interface Tree {
|
|
11
|
+
readonly value: string;
|
|
12
|
+
readonly children: readonly Tree[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Tree
|
|
16
|
+
const treeStructure: DDataStructure.Structure<Tree> = DDataStructure.object({
|
|
17
|
+
value: DDataStructure.string(),
|
|
18
|
+
children: DDataStructure.array(
|
|
19
|
+
DDataStructure.lazy(() => treeStructure),
|
|
20
|
+
),
|
|
21
|
+
}).contract();
|
|
22
|
+
|
|
23
|
+
// `lazy` retarde la résolution de `treeStructure`.
|
|
24
|
+
//
|
|
25
|
+
// Sans lui, la construction de la structure devrait accéder immédiatement
|
|
26
|
+
// à une variable qui est elle-même en train d'être construite.
|
|
27
|
+
//
|
|
28
|
+
// Le type doit être déclaré en amont car TypeScript ne peut pas inférer
|
|
29
|
+
// une structure qui dépend récursivement de son propre type.
|
|
30
|
+
//
|
|
31
|
+
// `contract()` compare strictement le type attendu par `Structure<Tree>`
|
|
32
|
+
// avec le type obtenu par l'inférence de la structure.
|
|
33
|
+
//
|
|
34
|
+
// Si la structure ne correspond pas exactement à `Tree`, l'appel à
|
|
35
|
+
// `contract()` produit une erreur de typage. Cela évite qu'une interface
|
|
36
|
+
// déclarée manuellement diverge de sa représentation runtime.
|
|
37
|
+
|
|
38
|
+
const tree = {
|
|
39
|
+
value: "root",
|
|
40
|
+
children: [
|
|
41
|
+
{
|
|
42
|
+
value: "child",
|
|
43
|
+
children: [],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const result = treeStructure.check(tree);
|