diff --git a/.commands/test-lint.sh b/.commands/test-lint.sh new file mode 100755 index 0000000..2352b8c --- /dev/null +++ b/.commands/test-lint.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +ARGUMENTS="$@" + +eslint --quiet $ARGUMENTS \ No newline at end of file diff --git a/.commands/test-tu.sh b/.commands/test-tu.sh new file mode 100755 index 0000000..dcbb299 --- /dev/null +++ b/.commands/test-tu.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +ARGUMENTS="$@" + +vitest --coverage $ARGUMENTS \ No newline at end of file diff --git a/.commands/test-types.sh b/.commands/test-types.sh new file mode 100755 index 0000000..1b22ad4 --- /dev/null +++ b/.commands/test-types.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +tsc -p tsconfig.test.json + +# docs +npm -w docs run test:types \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index a51c5f5..e9e816a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,11 +18,12 @@ "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" }, - - "typescript.tsdk": "node_modules/typescript/lib", - "deno.enable": true, "deno.enablePaths": ["integration/deno"], "deno.disablePaths": ["dist", "node_modules"], - "deno.config": "./integration/deno/deno.json" + "deno.config": "./integration/deno/deno.json", + "js/ts.tsdk.path": "node_modules/typescript/lib", + "cSpell.words": [ + "vitest" + ] } \ No newline at end of file diff --git a/docs/.commands/test-types.sh b/docs/.commands/test-types.sh new file mode 100755 index 0000000..ef0a496 --- /dev/null +++ b/docs/.commands/test-types.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +tsc -p tsconfig.app.json +tsc -p tsconfig.v0.json \ No newline at end of file diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index ae5fe26..4d3e714 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -95,25 +95,25 @@ export default defineConfig({ ({ namedGroups }) => A.join( [ "// @filename: @duplojs/server-utils.ts", - `export * from "@v${namedGroups?.version ?? ""}";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}";`, "// @filename: @duplojs/server-utils/file.ts", - `export * from "@v${namedGroups?.version ?? ""}/file";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/file";`, "// @filename: @duplojs/server-utils/common.ts", - `export * from "@v${namedGroups?.version ?? ""}/common";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/common";`, "// @filename: @duplojs/server-utils/dataParser.ts", - `export * from "@v${namedGroups?.version ?? ""}/dataParser";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/dataParser";`, "// @filename: @duplojs/server-utils/dataParserCoerce.ts", - `export * from "@v${namedGroups?.version ?? ""}/dataParserCoerce";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/dataParserCoerce";`, "// @filename: @duplojs/server-utils/dataParserExtended.ts", - `export * from "@v${namedGroups?.version ?? ""}/dataParserExtended";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/dataParserExtended";`, "// @filename: @duplojs/server-utils/command.ts", - `export * from "@v${namedGroups?.version ?? ""}/command";`, + `export * from "@server-utils/v${namedGroups?.version ?? ""}/command";`, "// @filename: index.ts", "// ---cut---", @@ -134,13 +134,13 @@ export default defineConfig({ moduleResolution: ModuleResolutionKind.Bundler, moduleDetection: ModuleDetectionKind.Force, paths: { - "@v0": ["libs/v0/index"], - "@v0/common": ["libs/v0/common/index"], - "@v0/file": ["libs/v0/file/index"], - "@v0/dataParser": ["libs/v0/dataParser/index"], - "@v0/dataParserCoerce": ["libs/v0/dataParser/parsers/coerce/index"], - "@v0/dataParserExtended": ["libs/v0/dataParser/extended/index"], - "@v0/command": ["libs/v0/command/index"], + "@server-utils/v0": ["libs/v0/index"], + "@server-utils/v0/common": ["libs/v0/common/index"], + "@server-utils/v0/file": ["libs/v0/file/index"], + "@server-utils/v0/dataParser": ["libs/v0/dataParser/index"], + "@server-utils/v0/dataParserCoerce": ["libs/v0/dataParser/parsers/coerce/index"], + "@server-utils/v0/dataParserExtended": ["libs/v0/dataParser/extended/index"], + "@server-utils/v0/command": ["libs/v0/command/index"], }, }, }, diff --git a/docs/en/v0/api/command/create.md b/docs/en/v0/api/command/create.md index db32d98..2d895f0 100644 --- a/docs/en/v0/api/command/create.md +++ b/docs/en/v0/api/command/create.md @@ -6,14 +6,13 @@ prev: next: text: "createBooleanOption" link: "/en/v0/api/command/createBooleanOption" -description: "Creates a CLI command with a name, an execute handler, and optional configuration." +description: "Creates a CLI command with a name, optional options/subject, and an execute handler." --- # create -`create` is used to declare a CLI command. -You provide a name and an execute function. -You can also add options, a subject (positional arguments), or sub-commands. +`create` declares a CLI command. +You provide a name and an execute function, and you can also add options, a subject for positional arguments, or child commands. ## Example @@ -48,8 +47,8 @@ function create< - `params` (`CreateCommandParams`, optional) : command configuration. - `params.description` (`string`, optional) : help description. - `params.options` (`Option[]`, optional) : option parsers. -- `params.subject` (`Subject | Command[]`, optional) : parser for positional data or sub-commands list. -- `execute` : command handler. Receives typed `options` and optional typed `subject`. +- `params.subject` (`Subject | Command[]`, optional) : parser-like contract for positional data or sub-commands list. +- `execute` : command handler. Receives typed `options` and, when present, a typed `subject`. ## Return value diff --git a/docs/en/v0/api/command/createArrayOption.md b/docs/en/v0/api/command/createArrayOption.md index 14c3cd3..8a9914b 100644 --- a/docs/en/v0/api/command/createArrayOption.md +++ b/docs/en/v0/api/command/createArrayOption.md @@ -6,7 +6,7 @@ prev: next: text: "API Reference" link: "/en/v0/api/" -description: "Creates an option that parses a delimited list into a typed array." +description: "Creates an option that parses a delimited list into a typed array from a DataParser or clean contract." --- # createArrayOption @@ -25,11 +25,11 @@ Creates an option that parses a delimited list into a typed array. ```typescript function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string aliases?: readonly string[] @@ -41,18 +41,18 @@ function createArrayOption< ): Option< GenericName, [ - ...A.CreateTuple, GenericMinValues>, - ...DP.Output[] + ...A.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ] > function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string aliases?: readonly string[] @@ -63,8 +63,8 @@ function createArrayOption< ): Option< GenericName, | [ - ...A.CreateTuple, GenericMinValues>, - ...DP.Output[] + ...A.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ] | undefined > @@ -73,7 +73,7 @@ function createArrayOption< ## Parameters - `name` (`string`) : option name used as `--name`. -- `schema` (`EligibleDataParser`) : parser for each array element. +- `contract` (`EligibleContract`) : parser or clean contract for each array element. - `params` (optional) : option metadata and array constraints. - `params.required` (`true`, optional) : throws when option is missing. - `params.min` (`number`, optional) : minimum number of values. @@ -87,6 +87,10 @@ function createArrayOption< - Required mode: `Option`. - Optional mode: `Option`. +## Notes + +- Primitive parsers and clean primitive contracts are coerced from CLI string input automatically. + ## See also - [`createOption`](/en/v0/api/command/createOption) - Builds a single-value option. diff --git a/docs/en/v0/api/command/createOption.md b/docs/en/v0/api/command/createOption.md index 2afc8d8..95a2ada 100644 --- a/docs/en/v0/api/command/createOption.md +++ b/docs/en/v0/api/command/createOption.md @@ -6,12 +6,12 @@ prev: next: text: "createArrayOption" link: "/en/v0/api/command/createArrayOption" -description: "Creates an option with a single parsed value from a DataParser schema." +description: "Creates an option with a single parsed value from a DataParser or clean contract." --- # createOption -Creates an option with a single parsed value from a DataParser schema. +Creates an option with a single parsed value from a DataParser or clean contract. ## Example @@ -25,34 +25,36 @@ Creates an option with a single parsed value from a DataParser schema. ```typescript function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string aliases?: readonly string[] required: true } -): Option> +): Option function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string aliases?: readonly string[] } -): Option | undefined> +): Option ``` ## Parameters - `name` (`string`) : option name used as `--name`. -- `schema` (`EligibleDataParser`) : parser used to validate/transform the value. +- `contract` (`EligibleContract`) : parser or clean contract used to validate/transform the value. - `params` (optional) : option metadata and requirement behavior. - `params.required` (`true`, optional) : throws when option is missing. - `params.description` (`string`, optional) : help description. @@ -60,8 +62,12 @@ function createOption< ## Return value -- `Option>` when `required: true`. -- `Option | undefined>` otherwise. +- `Option` when `required: true`. +- `Option` otherwise. + +## Notes + +- Primitive parsers and clean primitive contracts are coerced from CLI string input automatically. ## See also diff --git a/docs/examples/v0/api/command/createArrayOption/main.ts b/docs/examples/v0/api/command/createArrayOption/main.ts index 64b6b0f..ba9aa9f 100644 --- a/docs/examples/v0/api/command/createArrayOption/main.ts +++ b/docs/examples/v0/api/command/createArrayOption/main.ts @@ -1,5 +1,7 @@ import { SC } from "@duplojs/server-utils"; -import { DP, type ExpectType } from "@duplojs/utils"; +import { C, DP, type ExpectType } from "@duplojs/utils"; + +const UserId = C.createNewType("user-id", DP.number(), C.Positive); const command = SC.create( "batch", @@ -18,6 +20,8 @@ const command = SC.create( separator: ";", }, ), + SC.createArrayOption("emails", C.Email), + SC.createArrayOption("userIds", UserId), ], }, ({ options }) => { @@ -26,6 +30,8 @@ const command = SC.create( { tags: string[] | undefined; files: [string, ...string[]]; + emails: C.Email[] | undefined; + userIds: C.GetNewType[] | undefined; }, "strict" >; @@ -35,4 +41,6 @@ const command = SC.create( await command.execute([ "--tags=api,docs", "--files=src/a.ts;src/b.ts", + "--emails=dev@duplojs.dev,ops@duplojs.dev", + "--userIds=1,2", ]); diff --git a/docs/examples/v0/api/command/createOption/main.ts b/docs/examples/v0/api/command/createOption/main.ts index 58525c5..9b46faf 100644 --- a/docs/examples/v0/api/command/createOption/main.ts +++ b/docs/examples/v0/api/command/createOption/main.ts @@ -1,5 +1,7 @@ import { SC } from "@duplojs/server-utils"; -import { DP, type ExpectType } from "@duplojs/utils"; +import { C, DP, type ExpectType } from "@duplojs/utils"; + +const UserId = C.createNewType("user-id", DP.number(), C.Positive); const command = SC.create( "serve", @@ -8,13 +10,15 @@ const command = SC.create( SC.createOption("host", DP.string()), SC.createOption( "port", - DP.coerce.number(), + DP.number(), { required: true }, ), SC.createOption( "environment", DP.literal(["dev", "prod"]), ), + SC.createOption("email", C.Email), + SC.createOption("userId", UserId), ], }, ({ options }) => { @@ -24,6 +28,8 @@ const command = SC.create( host: string | undefined; port: number; environment: "dev" | "prod" | undefined; + email: C.Email | undefined; + userId: C.GetNewType | undefined; }, "strict" >; @@ -35,4 +41,6 @@ await command.execute([ "0.0.0.0", "--port=8080", "--environment=prod", + "--email=dev@duplojs.dev", + "--userId=42", ]); diff --git a/docs/fr/v0/api/command/create.md b/docs/fr/v0/api/command/create.md index 13eda2e..0f1112e 100644 --- a/docs/fr/v0/api/command/create.md +++ b/docs/fr/v0/api/command/create.md @@ -6,14 +6,13 @@ prev: next: text: "createBooleanOption" link: "/fr/v0/api/command/createBooleanOption" -description: "Crée une commande CLI avec son nom, son comportement, et une configuration optionnelle." +description: "Crée une commande CLI avec un nom, des options/sujets optionnels et un handler d'exécution." --- # create `create` sert à déclarer une commande CLI. -Vous donnez un nom et une fonction à exécuter. -Vous pouvez aussi ajouter des options, un sujet (arguments positionnels), ou des sous-commandes. +Vous fournissez un nom et une fonction d'exécution, et vous pouvez aussi ajouter des options, un sujet pour les arguments positionnels, ou des sous-commandes. ## Exemple @@ -48,8 +47,8 @@ function create< - `params` (`CreateCommandParams`, optionnel) : configuration de la commande. - `params.description` (`string`, optionnel) : description affichée dans le help. - `params.options` (`Option[]`, optionnel) : parseurs d'options. -- `params.subject` (`Subject | Command[]`, optionnel) : parser de données positionnelles ou liste de sous-commandes. -- `execute` : handler de commande. Reçoit `options` typées et `subject` typé optionnel. +- `params.subject` (`Subject | Command[]`, optionnel) : contrat de parsing pour les données positionnelles ou liste de sous-commandes. +- `execute` : handler de commande. Reçoit des `options` typées et, si présent, un `subject` typé. ## Valeur de retour diff --git a/docs/fr/v0/api/command/createArrayOption.md b/docs/fr/v0/api/command/createArrayOption.md index 8681c15..707b157 100644 --- a/docs/fr/v0/api/command/createArrayOption.md +++ b/docs/fr/v0/api/command/createArrayOption.md @@ -6,7 +6,7 @@ prev: next: text: "Référence API" link: "/fr/v0/api/" -description: "Crée une option qui parse une liste séparée en tableau typé." +description: "Crée une option qui parse une liste délimitée vers un tableau typé depuis un DataParser ou un contrat clean." --- # createArrayOption @@ -25,11 +25,11 @@ Crée une option qui parse une liste séparée en tableau typé. ```typescript function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string aliases?: readonly string[] @@ -41,18 +41,18 @@ function createArrayOption< ): Option< GenericName, [ - ...A.CreateTuple, GenericMinValues>, - ...DP.Output[] + ...A.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ] > function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string aliases?: readonly string[] @@ -63,8 +63,8 @@ function createArrayOption< ): Option< GenericName, | [ - ...A.CreateTuple, GenericMinValues>, - ...DP.Output[] + ...A.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ] | undefined > @@ -73,7 +73,7 @@ function createArrayOption< ## Paramètres - `name` (`string`) : nom de l'option utilisé comme `--name`. -- `schema` (`EligibleDataParser`) : parseur de chaque élément du tableau. +- `contract` (`EligibleContract`) : parseur ou contrat clean pour chaque élément du tableau. - `params` (optionnel) : métadonnées et contraintes de tableau. - `params.required` (`true`, optionnel) : déclenche une erreur si l'option est absente. - `params.min` (`number`, optionnel) : nombre minimal de valeurs. @@ -87,6 +87,10 @@ function createArrayOption< - Mode requis: `Option`. - Mode optionnel: `Option`. +## Notes + +- Les parsers primitifs et les contrats clean primitifs sont coercés automatiquement depuis l'entrée CLI en chaîne. + ## Voir aussi - [`createOption`](/fr/v0/api/command/createOption) - Construit une option à valeur unique. diff --git a/docs/fr/v0/api/command/createOption.md b/docs/fr/v0/api/command/createOption.md index 49f7f0a..20bc87d 100644 --- a/docs/fr/v0/api/command/createOption.md +++ b/docs/fr/v0/api/command/createOption.md @@ -6,12 +6,12 @@ prev: next: text: "createArrayOption" link: "/fr/v0/api/command/createArrayOption" -description: "Crée une option avec une valeur unique parsée via un schéma DataParser." +description: "Crée une option à valeur unique depuis un DataParser ou un contrat clean." --- # createOption -Crée une option avec une valeur unique parsée via un schéma DataParser. +Crée une option à valeur unique depuis un DataParser ou un contrat clean. ## Exemple @@ -25,34 +25,36 @@ Crée une option avec une valeur unique parsée via un schéma DataParser. ```typescript function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string aliases?: readonly string[] required: true } -): Option> +): Option function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string aliases?: readonly string[] } -): Option | undefined> +): Option ``` ## Paramètres - `name` (`string`) : nom de l'option utilisé comme `--name`. -- `schema` (`EligibleDataParser`) : parseur utilisé pour valider/transformer la valeur. +- `contract` (`EligibleContract`) : parseur ou contrat clean utilisé pour valider/transformer la valeur. - `params` (optionnel) : métadonnées d'option et comportement d'obligation. - `params.required` (`true`, optionnel) : déclenche une erreur si l'option est absente. - `params.description` (`string`, optionnel) : description dans le help. @@ -60,8 +62,12 @@ function createOption< ## Valeur de retour -- `Option>` quand `required: true`. -- `Option | undefined>` sinon. +- `Option` quand `required: true`. +- `Option` sinon. + +## Notes + +- Les parsers primitifs et les contrats clean primitifs sont coercés automatiquement depuis l'entrée CLI en chaîne. ## Voir aussi diff --git a/docs/libs/.gitignore b/docs/libs/.gitignore new file mode 100644 index 0000000..586e3d7 --- /dev/null +++ b/docs/libs/.gitignore @@ -0,0 +1 @@ +!dist \ No newline at end of file diff --git a/docs/libs/v0/command/options/simple.d.ts b/docs/libs/v0/command/options/simple.d.ts deleted file mode 100644 index 99e0477..0000000 --- a/docs/libs/v0/command/options/simple.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -import * as DDP from "@duplojs/utils/dataParser"; -import { type Option } from "./base"; -import type { EligibleDataParser } from "../types"; -/** - * Create an option with a single parsed value. - * - * Use a DataParser schema to parse and validate the option value from `--name=value` or `--name value`. - * - * ```ts - * const port = SC.createOption("port", DP.string()); - * - * const name = SC.createOption( - * "name", - * DP.string(), - * { - * required: true, - * aliases: ["n"], - * }, - * ); - * - * const mode = SC.createOption( - * "mode", - * DP.literal(["dev", "prod"]), - * ); - * - * SC.create( - * "serve", - * { - * options: [port, name, mode], - * }, - * ({ options: { port, name, mode } }) => { - * // port: string | undefined - * // name: string - * ``` - * - * @remarks - * Set `required: true` to throw when the option is missing. - * - * @see https://server-utils.duplojs.dev/en/v0/api/command/createOption - * @namespace SC - * - */ -export declare function createOption(name: GenericName, schema: GenericSchema, params: { - description?: string; - aliases?: readonly string[]; - required: true; -}): Option>; -export declare function createOption(name: GenericName, schema: GenericSchema, params?: { - description?: string; - aliases?: readonly string[]; -}): Option | undefined>; diff --git a/docs/libs/v0/command/types/eligibleDataParser.d.ts b/docs/libs/v0/command/types/eligibleDataParser.d.ts deleted file mode 100644 index ff584e3..0000000 --- a/docs/libs/v0/command/types/eligibleDataParser.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { DP, SimplifyTopLevel } from "@duplojs/utils"; -export type EligibleDataParser = (DP.DataParserString | DP.DataParserNumber & { - readonly coerce: true; -}>> | DP.DataParserBigInt & { - readonly coerce: true; -}>> | DP.DataParserDate & { - readonly coerce: true; -}>> | DP.DataParserTime & { - readonly coerce: true; -}>> | DP.DataParserLiteral & { - readonly value: readonly string[]; -}>> | DP.DataParserNil & { - readonly coerce: true; -}>> | DP.DataParserTemplateLiteral | DP.DataParserUnion & { - readonly options: readonly [ - EligibleDataParser, - ...EligibleDataParser[] - ]; -}>> | DP.DataParserTransform & { - readonly inner: EligibleDataParser; -}>> | DP.DataParserPipe & { - readonly input: EligibleDataParser; - readonly output: EligibleDataParser; -}>> | DP.DataParserOptional & { - readonly inner: EligibleDataParser; -}>>); diff --git a/docs/libs/v0/command/types/index.d.ts b/docs/libs/v0/command/types/index.d.ts deleted file mode 100644 index 9ef3554..0000000 --- a/docs/libs/v0/command/types/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./eligibleDataParser"; diff --git a/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.cjs b/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.cjs deleted file mode 100644 index 114eb4a..0000000 --- a/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.cjs +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); - -const envVarRegex = /(?[^{}]+)}/g; -const escapedDollarRegex = /\\\$/g; -function expandValue(value, env, stack = new Set()) { - return utils.S.replace(value, envVarRegex, ({ namedGroups }) => { - const value = namedGroups.value; - const rawEnvValue = env[value]; - if (rawEnvValue === undefined || stack.has(value)) { - return ""; - } - stack.add(value); - const resolved = expandValue(rawEnvValue, env, stack); - stack.delete(value); - return resolved; - }); -} -function expandEnvironmentVariables(env) { - return utils.G.reduce(utils.O.entries(env), utils.G.reduceFrom(env), ({ element: [key, value], lastValue, nextWithObject }) => nextWithObject(lastValue, { - [key]: utils.S.replaceAll(expandValue(value, lastValue), escapedDollarRegex, "$"), - })); -} - -exports.expandEnvironmentVariables = expandEnvironmentVariables; -exports.expandValue = expandValue; diff --git a/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.cjs b/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.cjs deleted file mode 100644 index 64cb1b0..0000000 --- a/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.cjs +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); - -function overrideEnvironmentVariables(arrayEnv, override) { - return utils.pipe(arrayEnv, utils.A.map(utils.O.entries), utils.A.flat, (entries) => override - ? entries - : utils.A.reverse(entries), utils.O.fromEntries); -} - -exports.overrideEnvironmentVariables = overrideEnvironmentVariables; diff --git a/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.mjs b/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.mjs deleted file mode 100644 index 6d56502..0000000 --- a/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import { pipe, A, O } from '@duplojs/utils'; - -function overrideEnvironmentVariables(arrayEnv, override) { - return pipe(arrayEnv, A.map(O.entries), A.flat, (entries) => override - ? entries - : A.reverse(entries), O.fromEntries); -} - -export { overrideEnvironmentVariables }; diff --git a/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.cjs b/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.cjs deleted file mode 100644 index 4108f2f..0000000 --- a/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.cjs +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var readTextFile = require('../../file/readTextFile.cjs'); - -const lineRegex = /^(?:export\s+)?(?[A-Z_][A-Z0-9_]*)=(?'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|`(?:\\`|[^`])*`|[^\s#\r\n][^#\r\n]*|)\s*(?:#.*)?$/mg; -const endLineBreakerRegex = /\r\n?/mg; -const surroundingQuoteRegex = /^(['"`])([\s\S]*)\1$/mg; -const backCartRegex = /\\r/g; -const newLineRegex = /\\n/g; -function parseEnvironmentLine(line) { - return utils.pipe(line, utils.S.replace(endLineBreakerRegex, "\n"), utils.S.extractAll(lineRegex), utils.G.reduce(utils.G.reduceFrom({}), ({ element, nextWithObject, lastValue, next }) => { - if (element.namedGroups?.key && element.namedGroups?.value) { - return nextWithObject(lastValue, { - [element.namedGroups.key]: utils.pipe(element.namedGroups.value, (value) => { - const surroundingValue = utils.S.replace(value, surroundingQuoteRegex, "$2"); - if (utils.S.startsWith(value, "\"")) { - return utils.pipe(surroundingValue, utils.S.replace(newLineRegex, "\n"), utils.S.replace(backCartRegex, "\r")); - } - return surroundingValue; - }), - }); - } - return next(lastValue); - })); -} -function parseEnvironmentFiles(baseEnv, paths) { - return utils.G.asyncReduce(paths, utils.G.reduceFrom([baseEnv]), ({ lastValue, element, nextPush, exit }) => readTextFile.readTextFile(element) - .then(utils.innerPipe(utils.E.whenIsRight(utils.innerPipe(parseEnvironmentLine, (value) => nextPush(lastValue, value))), utils.when(utils.E.isLeft, exit)))); -} - -exports.parseEnvironmentFiles = parseEnvironmentFiles; -exports.parseEnvironmentLine = parseEnvironmentLine; diff --git a/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.mjs b/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.mjs deleted file mode 100644 index cf2a193..0000000 --- a/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.mjs +++ /dev/null @@ -1,30 +0,0 @@ -import { G, innerPipe, E, when, pipe, S } from '@duplojs/utils'; -import { readTextFile } from '../../file/readTextFile.mjs'; - -const lineRegex = /^(?:export\s+)?(?[A-Z_][A-Z0-9_]*)=(?'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|`(?:\\`|[^`])*`|[^\s#\r\n][^#\r\n]*|)\s*(?:#.*)?$/mg; -const endLineBreakerRegex = /\r\n?/mg; -const surroundingQuoteRegex = /^(['"`])([\s\S]*)\1$/mg; -const backCartRegex = /\\r/g; -const newLineRegex = /\\n/g; -function parseEnvironmentLine(line) { - return pipe(line, S.replace(endLineBreakerRegex, "\n"), S.extractAll(lineRegex), G.reduce(G.reduceFrom({}), ({ element, nextWithObject, lastValue, next }) => { - if (element.namedGroups?.key && element.namedGroups?.value) { - return nextWithObject(lastValue, { - [element.namedGroups.key]: pipe(element.namedGroups.value, (value) => { - const surroundingValue = S.replace(value, surroundingQuoteRegex, "$2"); - if (S.startsWith(value, "\"")) { - return pipe(surroundingValue, S.replace(newLineRegex, "\n"), S.replace(backCartRegex, "\r")); - } - return surroundingValue; - }), - }); - } - return next(lastValue); - })); -} -function parseEnvironmentFiles(baseEnv, paths) { - return G.asyncReduce(paths, G.reduceFrom([baseEnv]), ({ lastValue, element, nextPush, exit }) => readTextFile(element) - .then(innerPipe(E.whenIsRight(innerPipe(parseEnvironmentLine, (value) => nextPush(lastValue, value))), when(E.isLeft, exit)))); -} - -export { parseEnvironmentFiles, parseEnvironmentLine }; diff --git a/docs/libs/v0/common/getCurrentWorkDirectory.cjs b/docs/libs/v0/common/getCurrentWorkDirectory.cjs deleted file mode 100644 index fc25889..0000000 --- a/docs/libs/v0/common/getCurrentWorkDirectory.cjs +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include common/getCurrentWorkDirectory/index.md} - */ -const getCurrentWorkDirectory = implementor.implementFunction("getCurrentWorkDirectory", { - NODE: () => utils.pipe(utils.E.safeCallback(() => utils.E.success(process.cwd())), utils.E.whenIsLeft(utils.E.error)), - DENO: () => utils.pipe(utils.E.safeCallback(() => utils.E.success(Deno.cwd())), utils.E.whenIsLeft(utils.E.error)), -}); - -exports.getCurrentWorkDirectory = getCurrentWorkDirectory; diff --git a/docs/libs/v0/common/getCurrentWorkDirectory.mjs b/docs/libs/v0/common/getCurrentWorkDirectory.mjs deleted file mode 100644 index d2d165f..0000000 --- a/docs/libs/v0/common/getCurrentWorkDirectory.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import { pipe, E } from '@duplojs/utils'; -import { implementFunction } from '../implementor.mjs'; - -/** - * {@include common/getCurrentWorkDirectory/index.md} - */ -const getCurrentWorkDirectory = implementFunction("getCurrentWorkDirectory", { - NODE: () => pipe(E.safeCallback(() => E.success(process.cwd())), E.whenIsLeft(E.error)), - DENO: () => pipe(E.safeCallback(() => E.success(Deno.cwd())), E.whenIsLeft(E.error)), -}); - -export { getCurrentWorkDirectory }; diff --git a/docs/libs/v0/common/setCurrentWorkingDirectory.cjs b/docs/libs/v0/common/setCurrentWorkingDirectory.cjs deleted file mode 100644 index e8889b9..0000000 --- a/docs/libs/v0/common/setCurrentWorkingDirectory.cjs +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include common/setCurrentWorkingDirectory/index.md} - */ -const setCurrentWorkingDirectory = implementor.implementFunction("setCurrentWorkingDirectory", { - NODE: (path) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => utils.E.safeCallback(() => void process.chdir(path)), utils.P.when(utils.E.isLeft, utils.E.fail), utils.P.otherwise(utils.E.ok)), - DENO: (path) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => utils.E.safeCallback(() => void Deno.chdir(path)), utils.P.when(utils.E.isLeft, utils.E.fail), utils.P.otherwise(utils.E.ok)), -}); - -exports.setCurrentWorkingDirectory = setCurrentWorkingDirectory; diff --git a/docs/libs/v0/common/setCurrentWorkingDirectory.mjs b/docs/libs/v0/common/setCurrentWorkingDirectory.mjs deleted file mode 100644 index fc372a0..0000000 --- a/docs/libs/v0/common/setCurrentWorkingDirectory.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import { pipe, when, instanceOf, E, P } from '@duplojs/utils'; -import { implementFunction } from '../implementor.mjs'; - -/** - * {@include common/setCurrentWorkingDirectory/index.md} - */ -const setCurrentWorkingDirectory = implementFunction("setCurrentWorkingDirectory", { - NODE: (path) => pipe(path, when(instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => E.safeCallback(() => void process.chdir(path)), P.when(E.isLeft, E.fail), P.otherwise(E.ok)), - DENO: (path) => pipe(path, when(instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => E.safeCallback(() => void Deno.chdir(path)), P.when(E.isLeft, E.fail), P.otherwise(E.ok)), -}); - -export { setCurrentWorkingDirectory }; diff --git a/docs/libs/v0/command/create.cjs b/docs/libs/v0/dist/command/create.cjs similarity index 80% rename from docs/libs/v0/command/create.cjs rename to docs/libs/v0/dist/command/create.cjs index 90d3033..832193e 100644 --- a/docs/libs/v0/command/create.cjs +++ b/docs/libs/v0/dist/command/create.cjs @@ -5,6 +5,7 @@ var AA = require('@duplojs/utils/array'); var OO = require('@duplojs/utils/object'); var DDP = require('@duplojs/utils/dataParser'); var EE = require('@duplojs/utils/either'); +var CC = require('@duplojs/utils/clean'); var kind = require('../kind.cjs'); var exitProcess = require('../common/exitProcess.cjs'); var error = require('./error.cjs'); @@ -32,7 +33,37 @@ var AA__namespace = /*#__PURE__*/_interopNamespaceDefault(AA); var OO__namespace = /*#__PURE__*/_interopNamespaceDefault(OO); var DDP__namespace = /*#__PURE__*/_interopNamespaceDefault(DDP); var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var CC__namespace = /*#__PURE__*/_interopNamespaceDefault(CC); +function commandSubjectToDataParser(contract) { + if (utils.hasSomeKinds(contract, [ + DDP__namespace.stringKind, + DDP__namespace.numberKind, + DDP__namespace.bigIntKind, + DDP__namespace.dateKind, + DDP__namespace.timeKind, + DDP__namespace.nilKind, + ])) { + const clone = contract.clone(); + clone.definition.coerce = true; + return clone; + } + if (DDP__namespace.identifier(contract, DDP__namespace.arrayKind)) { + return DDP__namespace.array(commandSubjectToDataParser(contract.definition.element), contract.definition); + } + if (DDP__namespace.identifier(contract, DDP__namespace.tupleKind)) { + return DDP__namespace.tuple(contract.definition.shape.map((part) => commandSubjectToDataParser(part)), { + ...contract.definition, + rest: contract.definition.rest + ? commandSubjectToDataParser(contract.definition.rest) + : undefined, + }); + } + if (DDP__namespace.identifier(contract, DDP__namespace.dataParserKind)) { + return contract; + } + return CC__namespace.toMapDataParser(contract, { coerce: true }); +} function printError(commandError, error$1) { if (!error$1) { // eslint-disable-next-line no-console @@ -47,11 +78,15 @@ function create(...args) { const [name, params, execute] = args.length === 2 ? [args[0], {}, args[1]] : args; + const subject = (params.subject + && !(params.subject instanceof Array) + ? commandSubjectToDataParser(params.subject) + : params.subject) ?? null; const self = commandKind.setTo({ name, description: params.description ?? null, options: params.options ?? [], - subject: params.subject ?? null, + subject: subject, execute: async (args, error$1) => { const commandError = error$1 ?? error.createError(self.name); const pathIndex = commandError.currentCommandPath.length; @@ -126,7 +161,7 @@ function create(...args) { }); return printError(commandError, error$1); } - const subjectResult = self.subject.parse(commandOptions.restArgs); + const subjectResult = self.subject.parse(commandOptions.restArgs[0]); if (EE__namespace.isLeft(subjectResult)) { error.addDataParserError(commandError, utils.unwrap(subjectResult), { type: "subject", diff --git a/docs/libs/v0/command/create.d.ts b/docs/libs/v0/dist/command/create.d.ts similarity index 71% rename from docs/libs/v0/command/create.d.ts rename to docs/libs/v0/dist/command/create.d.ts index 3abc03d..ab2f418 100644 --- a/docs/libs/v0/command/create.d.ts +++ b/docs/libs/v0/dist/command/create.d.ts @@ -1,9 +1,9 @@ import { type SimplifyTopLevel, type Kind, type MaybePromise } from "@duplojs/utils"; import * as DDP from "@duplojs/utils/dataParser"; import { type Option } from "./options"; -import type { EligibleDataParser } from "./types"; +import type { EligibleCleanType, EligibleContract, EligibleDataParser, ComputeEligibleCleanType } from "./types"; import { SymbolCommandError, type CommandError } from "./error"; -export type Subject = (EligibleDataParser | DDP.DataParserArray & { +export type Subject = (EligibleContract | DDP.DataParserArray & { readonly element: EligibleDataParser; }>> | DDP.AdvancedContract & { readonly shape: readonly [ @@ -12,6 +12,7 @@ export type Subject = (EligibleDataParser | DDP.DataParserArray>>); +type ComputeSubject = [GenericSubject] extends [DDP.DataParser] ? DDP.Output : [GenericSubject] extends [EligibleCleanType] ? ComputeEligibleCleanType : never; declare const commandKind: import("@duplojs/utils").KindHandler>; export interface Command extends Kind { readonly name: string; @@ -31,12 +32,12 @@ export interface CreateCommandExecuteParams["execute"]>, SymbolCommandError>["result"]; }; - subject: DDP.Output; + subject: ComputeSubject; } /** * Create a command node. * - * Use this builder to define a command name, its optional options/subject, and the execute handler called after parsing. + * Use this builder to define a command name, optional options, an optional subject, and the execute handler called after parsing. * * ```ts * const ping = SC.create( @@ -46,13 +47,17 @@ export interface CreateCommandExecuteParams { - * // name: string + * ({ options: { email }, subject }) => { + * // email: C.Email | undefined + * // subject: C.GetNewType * }, * ); * @@ -75,7 +80,7 @@ export interface CreateCommandExecuteParams commandSubjectToDataParser(part)), { + ...contract.definition, + rest: contract.definition.rest + ? commandSubjectToDataParser(contract.definition.rest) + : undefined, + }); + } + if (DDP.identifier(contract, DDP.dataParserKind)) { + return contract; + } + return CC.toMapDataParser(contract, { coerce: true }); +} function printError(commandError, error) { if (!error) { // eslint-disable-next-line no-console @@ -23,11 +53,15 @@ function create(...args) { const [name, params, execute] = args.length === 2 ? [args[0], {}, args[1]] : args; + const subject = (params.subject + && !(params.subject instanceof Array) + ? commandSubjectToDataParser(params.subject) + : params.subject) ?? null; const self = commandKind.setTo({ name, description: params.description ?? null, options: params.options ?? [], - subject: params.subject ?? null, + subject: subject, execute: async (args, error) => { const commandError = error ?? createError(self.name); const pathIndex = commandError.currentCommandPath.length; @@ -102,7 +136,7 @@ function create(...args) { }); return printError(commandError, error); } - const subjectResult = self.subject.parse(commandOptions.restArgs); + const subjectResult = self.subject.parse(commandOptions.restArgs[0]); if (EE.isLeft(subjectResult)) { addDataParserError(commandError, unwrap(subjectResult), { type: "subject", diff --git a/docs/libs/v0/command/error.cjs b/docs/libs/v0/dist/command/error.cjs similarity index 100% rename from docs/libs/v0/command/error.cjs rename to docs/libs/v0/dist/command/error.cjs diff --git a/docs/libs/v0/command/error.d.ts b/docs/libs/v0/dist/command/error.d.ts similarity index 100% rename from docs/libs/v0/command/error.d.ts rename to docs/libs/v0/dist/command/error.d.ts diff --git a/docs/libs/v0/command/error.mjs b/docs/libs/v0/dist/command/error.mjs similarity index 100% rename from docs/libs/v0/command/error.mjs rename to docs/libs/v0/dist/command/error.mjs diff --git a/docs/libs/v0/command/exec.cjs b/docs/libs/v0/dist/command/exec.cjs similarity index 100% rename from docs/libs/v0/command/exec.cjs rename to docs/libs/v0/dist/command/exec.cjs diff --git a/docs/libs/v0/command/exec.d.ts b/docs/libs/v0/dist/command/exec.d.ts similarity index 100% rename from docs/libs/v0/command/exec.d.ts rename to docs/libs/v0/dist/command/exec.d.ts diff --git a/docs/libs/v0/command/exec.mjs b/docs/libs/v0/dist/command/exec.mjs similarity index 100% rename from docs/libs/v0/command/exec.mjs rename to docs/libs/v0/dist/command/exec.mjs diff --git a/docs/libs/v0/command/execOptions.cjs b/docs/libs/v0/dist/command/execOptions.cjs similarity index 100% rename from docs/libs/v0/command/execOptions.cjs rename to docs/libs/v0/dist/command/execOptions.cjs diff --git a/docs/libs/v0/command/execOptions.d.ts b/docs/libs/v0/dist/command/execOptions.d.ts similarity index 100% rename from docs/libs/v0/command/execOptions.d.ts rename to docs/libs/v0/dist/command/execOptions.d.ts diff --git a/docs/libs/v0/command/execOptions.mjs b/docs/libs/v0/dist/command/execOptions.mjs similarity index 100% rename from docs/libs/v0/command/execOptions.mjs rename to docs/libs/v0/dist/command/execOptions.mjs diff --git a/docs/libs/v0/command/help.cjs b/docs/libs/v0/dist/command/help.cjs similarity index 100% rename from docs/libs/v0/command/help.cjs rename to docs/libs/v0/dist/command/help.cjs diff --git a/docs/libs/v0/command/help.d.ts b/docs/libs/v0/dist/command/help.d.ts similarity index 100% rename from docs/libs/v0/command/help.d.ts rename to docs/libs/v0/dist/command/help.d.ts diff --git a/docs/libs/v0/command/help.mjs b/docs/libs/v0/dist/command/help.mjs similarity index 100% rename from docs/libs/v0/command/help.mjs rename to docs/libs/v0/dist/command/help.mjs diff --git a/docs/libs/v0/command/index.cjs b/docs/libs/v0/dist/command/index.cjs similarity index 100% rename from docs/libs/v0/command/index.cjs rename to docs/libs/v0/dist/command/index.cjs diff --git a/docs/libs/v0/command/index.d.ts b/docs/libs/v0/dist/command/index.d.ts similarity index 100% rename from docs/libs/v0/command/index.d.ts rename to docs/libs/v0/dist/command/index.d.ts diff --git a/docs/libs/v0/command/index.mjs b/docs/libs/v0/dist/command/index.mjs similarity index 100% rename from docs/libs/v0/command/index.mjs rename to docs/libs/v0/dist/command/index.mjs diff --git a/docs/libs/v0/command/options/array.cjs b/docs/libs/v0/dist/command/options/array.cjs similarity index 71% rename from docs/libs/v0/command/options/array.cjs rename to docs/libs/v0/dist/command/options/array.cjs index 71625bb..f27c856 100644 --- a/docs/libs/v0/command/options/array.cjs +++ b/docs/libs/v0/dist/command/options/array.cjs @@ -4,6 +4,7 @@ var utils = require('@duplojs/utils'); var SS = require('@duplojs/utils/string'); var DDP = require('@duplojs/utils/dataParser'); var EE = require('@duplojs/utils/either'); +var CC = require('@duplojs/utils/clean'); var base = require('./base.cjs'); var error = require('../error.cjs'); @@ -27,10 +28,30 @@ function _interopNamespaceDefault(e) { var SS__namespace = /*#__PURE__*/_interopNamespaceDefault(SS); var DDP__namespace = /*#__PURE__*/_interopNamespaceDefault(DDP); var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var CC__namespace = /*#__PURE__*/_interopNamespaceDefault(CC); const defaultSeparator = ","; -function createArrayOption(name, schema, params) { - const dataParser = utils.pipe(schema, DDP__namespace.array, (schema) => params?.min +function createArrayOption(name, contract, params) { + let computeDataParser = undefined; + if (utils.hasSomeKinds(contract, [ + DDP__namespace.stringKind, + DDP__namespace.numberKind, + DDP__namespace.bigIntKind, + DDP__namespace.dateKind, + DDP__namespace.timeKind, + DDP__namespace.nilKind, + ])) { + const clone = contract.clone(); + clone.definition.coerce = true; + computeDataParser = clone; + } + else if (DDP__namespace.identifier(contract, DDP__namespace.dataParserKind)) { + computeDataParser = contract; + } + else { + computeDataParser = CC__namespace.toMapDataParser(contract, { coerce: true }); + } + const dataParser = utils.pipe(computeDataParser, DDP__namespace.array, (schema) => params?.min ? schema.addChecker(DDP__namespace.checkerArrayMin(params.min)) : schema, (schema) => params?.max ? schema.addChecker(DDP__namespace.checkerArrayMax(params.max)) diff --git a/docs/libs/v0/command/options/array.d.ts b/docs/libs/v0/dist/command/options/array.d.ts similarity index 51% rename from docs/libs/v0/command/options/array.d.ts rename to docs/libs/v0/dist/command/options/array.d.ts index 751ae0d..3e8e6e3 100644 --- a/docs/libs/v0/command/options/array.d.ts +++ b/docs/libs/v0/dist/command/options/array.d.ts @@ -1,18 +1,16 @@ -import * as DDP from "@duplojs/utils/dataParser"; import type * as AA from "@duplojs/utils/array"; import { type Option } from "./base"; -import type { EligibleDataParser } from "../types"; +import type { EligibleContract } from "../types"; +import type { ComputeOptionContract } from "./types"; /** * Create an option that parses an array of values. * - * This option parses a delimited string value into an array and validates each element with the provided DataParser schema. + * This option parses a delimited string value into an array and validates each element with the provided DataParser or clean contract. * * ```ts - * const tags = SC.createArrayOption("tags", DP.string()); - * * const ids = SC.createArrayOption( * "ids", - * DP.string(), + * DP.number(), * { * required: true, * min: 1, @@ -25,27 +23,35 @@ import type { EligibleDataParser } from "../types"; * { separator: ";" }, * ); * + * const UserId = C.createNewType("user-id", DP.number(), C.Positive); + * const userIds = SC.createArrayOption("userIds", UserId); + * + * const tags = SC.createArrayOption("tags", DP.string()); + * const emails = SC.createArrayOption("emails", C.Email); + * * SC.create( * "batch", * { - * options: [tags, ids, paths], + * options: [tags, ids, paths, emails, userIds], * }, - * ({ options: { ids, tags, paths } }) => { - * // ids: [string, ...string[]] + * ({ options: { ids, tags, paths, emails, userIds } }) => { + * // ids: [number, ...number[]] * // tags: string[] | undefined * // paths: string[] | undefined + * // emails: C.Email[] | undefined + * // userIds: C.GetNewType[] | undefined * }, * ); * ``` * * @remarks - * The default separator is `,`. You can customize it with `separator`. + * The default separator is `,`. You can customize it with `separator`, and primitive elements are coerced from CLI string input. * * @see https://server-utils.duplojs.dev/en/v0/api/command/createArrayOption * @namespace SC * */ -export declare function createArrayOption(name: GenericName, schema: GenericSchema, params: { +export declare function createArrayOption(name: GenericName, contract: GenericContract, params: { description?: string; aliases?: readonly string[]; min?: GenericMinValues; @@ -53,16 +59,16 @@ export declare function createArrayOption, GenericMinValues>, - ...DDP.Output[] + ...AA.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ]>; -export declare function createArrayOption(name: GenericName, schema: GenericSchema, params?: { +export declare function createArrayOption(name: GenericName, contract: GenericContract, params?: { description?: string; aliases?: readonly string[]; min?: GenericMinValues; max?: number; separator?: string; }): Option, GenericMinValues>, - ...DDP.Output[] + ...AA.CreateTuple, GenericMinValues>, + ...ComputeOptionContract[] ] | undefined>; diff --git a/docs/libs/v0/command/options/array.mjs b/docs/libs/v0/dist/command/options/array.mjs similarity index 65% rename from docs/libs/v0/command/options/array.mjs rename to docs/libs/v0/dist/command/options/array.mjs index a776309..a2a68d1 100644 --- a/docs/libs/v0/command/options/array.mjs +++ b/docs/libs/v0/dist/command/options/array.mjs @@ -1,13 +1,33 @@ -import { pipe, unwrap } from '@duplojs/utils'; +import { hasSomeKinds, pipe, unwrap } from '@duplojs/utils'; import * as SS from '@duplojs/utils/string'; import * as DDP from '@duplojs/utils/dataParser'; import * as EE from '@duplojs/utils/either'; +import * as CC from '@duplojs/utils/clean'; import { initOption } from './base.mjs'; import { addIssue, addDataParserError } from '../error.mjs'; const defaultSeparator = ","; -function createArrayOption(name, schema, params) { - const dataParser = pipe(schema, DDP.array, (schema) => params?.min +function createArrayOption(name, contract, params) { + let computeDataParser = undefined; + if (hasSomeKinds(contract, [ + DDP.stringKind, + DDP.numberKind, + DDP.bigIntKind, + DDP.dateKind, + DDP.timeKind, + DDP.nilKind, + ])) { + const clone = contract.clone(); + clone.definition.coerce = true; + computeDataParser = clone; + } + else if (DDP.identifier(contract, DDP.dataParserKind)) { + computeDataParser = contract; + } + else { + computeDataParser = CC.toMapDataParser(contract, { coerce: true }); + } + const dataParser = pipe(computeDataParser, DDP.array, (schema) => params?.min ? schema.addChecker(DDP.checkerArrayMin(params.min)) : schema, (schema) => params?.max ? schema.addChecker(DDP.checkerArrayMax(params.max)) diff --git a/docs/libs/v0/command/options/base.cjs b/docs/libs/v0/dist/command/options/base.cjs similarity index 100% rename from docs/libs/v0/command/options/base.cjs rename to docs/libs/v0/dist/command/options/base.cjs diff --git a/docs/libs/v0/command/options/base.d.ts b/docs/libs/v0/dist/command/options/base.d.ts similarity index 100% rename from docs/libs/v0/command/options/base.d.ts rename to docs/libs/v0/dist/command/options/base.d.ts diff --git a/docs/libs/v0/command/options/base.mjs b/docs/libs/v0/dist/command/options/base.mjs similarity index 100% rename from docs/libs/v0/command/options/base.mjs rename to docs/libs/v0/dist/command/options/base.mjs diff --git a/docs/libs/v0/command/options/boolean.cjs b/docs/libs/v0/dist/command/options/boolean.cjs similarity index 100% rename from docs/libs/v0/command/options/boolean.cjs rename to docs/libs/v0/dist/command/options/boolean.cjs diff --git a/docs/libs/v0/command/options/boolean.d.ts b/docs/libs/v0/dist/command/options/boolean.d.ts similarity index 100% rename from docs/libs/v0/command/options/boolean.d.ts rename to docs/libs/v0/dist/command/options/boolean.d.ts diff --git a/docs/libs/v0/command/options/boolean.mjs b/docs/libs/v0/dist/command/options/boolean.mjs similarity index 100% rename from docs/libs/v0/command/options/boolean.mjs rename to docs/libs/v0/dist/command/options/boolean.mjs diff --git a/docs/libs/v0/command/options/index.d.ts b/docs/libs/v0/dist/command/options/index.d.ts similarity index 80% rename from docs/libs/v0/command/options/index.d.ts rename to docs/libs/v0/dist/command/options/index.d.ts index ea2ddbf..82bf9de 100644 --- a/docs/libs/v0/command/options/index.d.ts +++ b/docs/libs/v0/dist/command/options/index.d.ts @@ -1,4 +1,5 @@ export * from "./base"; +export * from "./types"; export * from "./boolean"; export * from "./simple"; export * from "./array"; diff --git a/docs/libs/v0/command/options/simple.cjs b/docs/libs/v0/dist/command/options/simple.cjs similarity index 66% rename from docs/libs/v0/command/options/simple.cjs rename to docs/libs/v0/dist/command/options/simple.cjs index 4b2eea5..8dabdcd 100644 --- a/docs/libs/v0/command/options/simple.cjs +++ b/docs/libs/v0/dist/command/options/simple.cjs @@ -1,8 +1,9 @@ 'use strict'; var utils = require('@duplojs/utils'); -var EE = require('@duplojs/utils/either'); var DDP = require('@duplojs/utils/dataParser'); +var EE = require('@duplojs/utils/either'); +var CC = require('@duplojs/utils/clean'); var base = require('./base.cjs'); var error = require('../error.cjs'); @@ -23,13 +24,33 @@ function _interopNamespaceDefault(e) { return Object.freeze(n); } -var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); var DDP__namespace = /*#__PURE__*/_interopNamespaceDefault(DDP); +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var CC__namespace = /*#__PURE__*/_interopNamespaceDefault(CC); -function createOption(name, schema, params) { +function createOption(name, contract, params) { + let computeDataParser = undefined; + if (utils.hasSomeKinds(contract, [ + DDP__namespace.stringKind, + DDP__namespace.numberKind, + DDP__namespace.bigIntKind, + DDP__namespace.dateKind, + DDP__namespace.timeKind, + DDP__namespace.nilKind, + ])) { + const clone = contract.clone(); + clone.definition.coerce = true; + computeDataParser = clone; + } + else if (DDP__namespace.identifier(contract, DDP__namespace.dataParserKind)) { + computeDataParser = contract; + } + else { + computeDataParser = CC__namespace.toMapDataParser(contract, { coerce: true }); + } const dataParser = params?.required - ? schema - : DDP__namespace.optional(schema); + ? computeDataParser + : DDP__namespace.optional(computeDataParser); return base.initOption(name, ({ isHere, value }, error$1) => { if (!isHere && params?.required) { return error.addIssue(error$1, { diff --git a/docs/libs/v0/dist/command/options/simple.d.ts b/docs/libs/v0/dist/command/options/simple.d.ts new file mode 100644 index 0000000..b63bd7d --- /dev/null +++ b/docs/libs/v0/dist/command/options/simple.d.ts @@ -0,0 +1,60 @@ +import { type Option } from "./base"; +import type { EligibleContract } from "../types"; +import type { ComputeOptionContract } from "./types"; +/** + * Create an option with a single parsed value. + * + * Use a DataParser or a clean contract to parse and validate the option value from `--name=value` or `--name value`. + * + * ```ts + * const name = SC.createOption( + * "name", + * DP.string(), + * { + * required: true, + * aliases: ["n"], + * }, + * ); + * + * const mode = SC.createOption( + * "mode", + * DP.literal(["dev", "prod"]), + * ); + * + * const UserId = C.createNewType("user-id", DP.number(), C.Positive); + * const userId = SC.createOption("userId", UserId); + * + * const port = SC.createOption("port", DP.number()); + * const email = SC.createOption("email", C.Email); + * + * SC.create( + * "serve", + * { + * options: [port, name, mode, email, userId], + * }, + * ({ options: { port, name, mode, email, userId } }) => { + * // port: number | undefined + * // name: string + * // mode: "dev" | "prod" | undefined + * // email: C.Email | undefined + * // userId: C.GetNewType | undefined + * }, + * ); + * ``` + * + * @remarks + * Primitive parsers and clean primitive contracts are coerced from CLI string input automatically. + * + * @see https://server-utils.duplojs.dev/en/v0/api/command/createOption + * @namespace SC + * + */ +export declare function createOption = ComputeOptionContract>(name: GenericName, contract: GenericContract, params: { + description?: string; + aliases?: readonly string[]; + required: true; +}): Option; +export declare function createOption = ComputeOptionContract>(name: GenericName, contract: GenericContract, params?: { + description?: string; + aliases?: readonly string[]; +}): Option; diff --git a/docs/libs/v0/command/options/simple.mjs b/docs/libs/v0/dist/command/options/simple.mjs similarity index 57% rename from docs/libs/v0/command/options/simple.mjs rename to docs/libs/v0/dist/command/options/simple.mjs index b557d72..6277bad 100644 --- a/docs/libs/v0/command/options/simple.mjs +++ b/docs/libs/v0/dist/command/options/simple.mjs @@ -1,13 +1,33 @@ -import { unwrap } from '@duplojs/utils'; -import * as EE from '@duplojs/utils/either'; +import { hasSomeKinds, unwrap } from '@duplojs/utils'; import * as DDP from '@duplojs/utils/dataParser'; +import * as EE from '@duplojs/utils/either'; +import * as CC from '@duplojs/utils/clean'; import { initOption } from './base.mjs'; import { addIssue, addDataParserError } from '../error.mjs'; -function createOption(name, schema, params) { +function createOption(name, contract, params) { + let computeDataParser = undefined; + if (hasSomeKinds(contract, [ + DDP.stringKind, + DDP.numberKind, + DDP.bigIntKind, + DDP.dateKind, + DDP.timeKind, + DDP.nilKind, + ])) { + const clone = contract.clone(); + clone.definition.coerce = true; + computeDataParser = clone; + } + else if (DDP.identifier(contract, DDP.dataParserKind)) { + computeDataParser = contract; + } + else { + computeDataParser = CC.toMapDataParser(contract, { coerce: true }); + } const dataParser = params?.required - ? schema - : DDP.optional(schema); + ? computeDataParser + : DDP.optional(computeDataParser); return initOption(name, ({ isHere, value }, error) => { if (!isHere && params?.required) { return addIssue(error, { diff --git a/docs/libs/v0/dist/command/options/types/computeOptionContract.d.ts b/docs/libs/v0/dist/command/options/types/computeOptionContract.d.ts new file mode 100644 index 0000000..b92203c --- /dev/null +++ b/docs/libs/v0/dist/command/options/types/computeOptionContract.d.ts @@ -0,0 +1,3 @@ +import type * as DDP from "@duplojs/utils/dataParser"; +import type { ComputeEligibleCleanType, EligibleCleanType, EligibleContract } from "../../types"; +export type ComputeOptionContract = [GenericContract] extends [DDP.DataParser] ? DDP.Output : [GenericContract] extends [EligibleCleanType] ? ComputeEligibleCleanType : never; diff --git a/docs/libs/v0/dist/command/options/types/index.d.ts b/docs/libs/v0/dist/command/options/types/index.d.ts new file mode 100644 index 0000000..7f7edc8 --- /dev/null +++ b/docs/libs/v0/dist/command/options/types/index.d.ts @@ -0,0 +1 @@ +export * from "./computeOptionContract"; diff --git a/docs/libs/v0/dist/command/types/eligibleCleanType.d.ts b/docs/libs/v0/dist/command/types/eligibleCleanType.d.ts new file mode 100644 index 0000000..5af2461 --- /dev/null +++ b/docs/libs/v0/dist/command/types/eligibleCleanType.d.ts @@ -0,0 +1,7 @@ +import type { AnyTuple } from "@duplojs/utils"; +import type * as CC from "@duplojs/utils/clean"; +import type * as DD from "@duplojs/utils/date"; +export type EligiblePrimitive = string | number | boolean | bigint | DD.TheDate | DD.TheTime; +export type EligibleEntityProperty = (CC.NewTypeHandler | CC.EntityPropertyDefinitionUnion> | CC.EntityPropertyDefinitionNullable | CC.EntityPropertyDefinitionArray | CC.EntityPropertyDefinitionIdentifier); +export type EligibleCleanType = (CC.ConstraintHandler | CC.ConstraintsSetHandler | CC.PrimitiveHandler | EligibleEntityProperty); +export type ComputeEligibleCleanType = [GenericSubject] extends [CC.ConstraintHandler] ? CC.GetConstraint : [GenericSubject] extends [CC.ConstraintsSetHandler] ? CC.GetConstraints : [GenericSubject] extends [CC.PrimitiveHandler] ? ReturnType : [GenericSubject] extends [EligibleEntityProperty] ? CC.EntityProperty : never; diff --git a/docs/libs/v0/dist/command/types/eligibleContract.d.ts b/docs/libs/v0/dist/command/types/eligibleContract.d.ts new file mode 100644 index 0000000..79ea269 --- /dev/null +++ b/docs/libs/v0/dist/command/types/eligibleContract.d.ts @@ -0,0 +1,3 @@ +import type { EligibleCleanType } from "./eligibleCleanType"; +import type { EligibleDataParser } from "./eligibleDataParser"; +export type EligibleContract = (EligibleDataParser | EligibleCleanType); diff --git a/docs/libs/v0/dist/command/types/eligibleDataParser.d.ts b/docs/libs/v0/dist/command/types/eligibleDataParser.d.ts new file mode 100644 index 0000000..4e6abef --- /dev/null +++ b/docs/libs/v0/dist/command/types/eligibleDataParser.d.ts @@ -0,0 +1,17 @@ +import type { SimplifyTopLevel } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; +export type EligibleDataParser = (DDP.DataParserString | DDP.DataParserNumber | DDP.DataParserBigInt | DDP.DataParserDate | DDP.DataParserTime | DDP.DataParserNil | DDP.DataParserTemplateLiteral | DDP.DataParserLiteral & { + readonly value: readonly string[]; +}>> | DDP.DataParserUnion & { + readonly options: readonly [ + EligibleDataParser, + ...EligibleDataParser[] + ]; +}>> | DDP.DataParserTransform & { + readonly inner: EligibleDataParser; +}>> | DDP.DataParserPipe & { + readonly input: EligibleDataParser; + readonly output: EligibleDataParser; +}>> | DDP.DataParserOptional & { + readonly inner: EligibleDataParser; +}>>); diff --git a/docs/libs/v0/dist/command/types/index.d.ts b/docs/libs/v0/dist/command/types/index.d.ts new file mode 100644 index 0000000..d02bdc3 --- /dev/null +++ b/docs/libs/v0/dist/command/types/index.d.ts @@ -0,0 +1,3 @@ +export * from "./eligibleDataParser"; +export * from "./eligibleCleanType"; +export * from "./eligibleContract"; diff --git a/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.cjs b/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.cjs new file mode 100644 index 0000000..73ec89f --- /dev/null +++ b/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.cjs @@ -0,0 +1,50 @@ +'use strict'; + +var GG = require('@duplojs/utils/generator'); +var OO = require('@duplojs/utils/object'); +var SS = require('@duplojs/utils/string'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var GG__namespace = /*#__PURE__*/_interopNamespaceDefault(GG); +var OO__namespace = /*#__PURE__*/_interopNamespaceDefault(OO); +var SS__namespace = /*#__PURE__*/_interopNamespaceDefault(SS); + +const envVarRegex = /(?[^{}]+)}/g; +const escapedDollarRegex = /\\\$/g; +function expandValue(value, env, stack = new Set()) { + return SS__namespace.replace(value, envVarRegex, ({ namedGroups }) => { + const value = namedGroups.value; + const rawEnvValue = env[value]; + if (rawEnvValue === undefined || stack.has(value)) { + return ""; + } + stack.add(value); + const resolved = expandValue(rawEnvValue, env, stack); + stack.delete(value); + return resolved; + }); +} +function expandEnvironmentVariables(env) { + return GG__namespace.reduce(OO__namespace.entries(env), GG__namespace.reduceFrom(env), ({ element: [key, value], lastValue, nextWithObject }) => nextWithObject(lastValue, { + [key]: SS__namespace.replaceAll(expandValue(value, lastValue), escapedDollarRegex, "$"), + })); +} + +exports.expandEnvironmentVariables = expandEnvironmentVariables; +exports.expandValue = expandValue; diff --git a/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.d.ts b/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.d.ts similarity index 100% rename from docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.d.ts rename to docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.d.ts diff --git a/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.mjs b/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.mjs similarity index 57% rename from docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.mjs rename to docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.mjs index 8776b33..9913efa 100644 --- a/docs/libs/v0/common/environmentVariable/expandEnvironmentVariables.mjs +++ b/docs/libs/v0/dist/common/environmentVariable/expandEnvironmentVariables.mjs @@ -1,9 +1,11 @@ -import { G, O, S } from '@duplojs/utils'; +import * as GG from '@duplojs/utils/generator'; +import * as OO from '@duplojs/utils/object'; +import * as SS from '@duplojs/utils/string'; const envVarRegex = /(?[^{}]+)}/g; const escapedDollarRegex = /\\\$/g; function expandValue(value, env, stack = new Set()) { - return S.replace(value, envVarRegex, ({ namedGroups }) => { + return SS.replace(value, envVarRegex, ({ namedGroups }) => { const value = namedGroups.value; const rawEnvValue = env[value]; if (rawEnvValue === undefined || stack.has(value)) { @@ -16,8 +18,8 @@ function expandValue(value, env, stack = new Set()) { }); } function expandEnvironmentVariables(env) { - return G.reduce(O.entries(env), G.reduceFrom(env), ({ element: [key, value], lastValue, nextWithObject }) => nextWithObject(lastValue, { - [key]: S.replaceAll(expandValue(value, lastValue), escapedDollarRegex, "$"), + return GG.reduce(OO.entries(env), GG.reduceFrom(env), ({ element: [key, value], lastValue, nextWithObject }) => nextWithObject(lastValue, { + [key]: SS.replaceAll(expandValue(value, lastValue), escapedDollarRegex, "$"), })); } diff --git a/docs/libs/v0/common/environmentVariable/index.cjs b/docs/libs/v0/dist/common/environmentVariable/index.cjs similarity index 100% rename from docs/libs/v0/common/environmentVariable/index.cjs rename to docs/libs/v0/dist/common/environmentVariable/index.cjs diff --git a/docs/libs/v0/common/environmentVariable/index.d.ts b/docs/libs/v0/dist/common/environmentVariable/index.d.ts similarity index 100% rename from docs/libs/v0/common/environmentVariable/index.d.ts rename to docs/libs/v0/dist/common/environmentVariable/index.d.ts diff --git a/docs/libs/v0/common/environmentVariable/index.mjs b/docs/libs/v0/dist/common/environmentVariable/index.mjs similarity index 100% rename from docs/libs/v0/common/environmentVariable/index.mjs rename to docs/libs/v0/dist/common/environmentVariable/index.mjs diff --git a/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.cjs b/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.cjs new file mode 100644 index 0000000..878f17b --- /dev/null +++ b/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.cjs @@ -0,0 +1,33 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var OO = require('@duplojs/utils/object'); +var AA = require('@duplojs/utils/array'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var OO__namespace = /*#__PURE__*/_interopNamespaceDefault(OO); +var AA__namespace = /*#__PURE__*/_interopNamespaceDefault(AA); + +function overrideEnvironmentVariables(arrayEnv, override) { + return utils.pipe(arrayEnv, AA__namespace.map(OO__namespace.entries), AA__namespace.flat, (entries) => override + ? entries + : AA__namespace.reverse(entries), OO__namespace.fromEntries); +} + +exports.overrideEnvironmentVariables = overrideEnvironmentVariables; diff --git a/docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.d.ts b/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts similarity index 100% rename from docs/libs/v0/common/environmentVariable/overrideEnvironmentVariables.d.ts rename to docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts diff --git a/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.mjs b/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.mjs new file mode 100644 index 0000000..53cbd4a --- /dev/null +++ b/docs/libs/v0/dist/common/environmentVariable/overrideEnvironmentVariables.mjs @@ -0,0 +1,11 @@ +import { pipe } from '@duplojs/utils'; +import * as OO from '@duplojs/utils/object'; +import * as AA from '@duplojs/utils/array'; + +function overrideEnvironmentVariables(arrayEnv, override) { + return pipe(arrayEnv, AA.map(OO.entries), AA.flat, (entries) => override + ? entries + : AA.reverse(entries), OO.fromEntries); +} + +export { overrideEnvironmentVariables }; diff --git a/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.cjs b/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.cjs new file mode 100644 index 0000000..d066dba --- /dev/null +++ b/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.cjs @@ -0,0 +1,57 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var GG = require('@duplojs/utils/generator'); +var SS = require('@duplojs/utils/string'); +var EE = require('@duplojs/utils/either'); +var readTextFile = require('../../file/readTextFile.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var GG__namespace = /*#__PURE__*/_interopNamespaceDefault(GG); +var SS__namespace = /*#__PURE__*/_interopNamespaceDefault(SS); +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +const lineRegex = /^(?:export\s+)?(?[A-Z_][A-Z0-9_]*)=(?'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|`(?:\\`|[^`])*`|[^\s#\r\n][^#\r\n]*|)\s*(?:#.*)?$/mg; +const endLineBreakerRegex = /\r\n?/mg; +const surroundingQuoteRegex = /^(['"`])([\s\S]*)\1$/mg; +const backCartRegex = /\\r/g; +const newLineRegex = /\\n/g; +function parseEnvironmentLine(line) { + return utils.pipe(line, SS__namespace.replace(endLineBreakerRegex, "\n"), SS__namespace.extractAll(lineRegex), GG__namespace.reduce(GG__namespace.reduceFrom({}), ({ element, nextWithObject, lastValue, next }) => { + if (element.namedGroups?.key && element.namedGroups?.value) { + return nextWithObject(lastValue, { + [element.namedGroups.key]: utils.pipe(element.namedGroups.value, (value) => { + const surroundingValue = SS__namespace.replace(value, surroundingQuoteRegex, "$2"); + if (SS__namespace.startsWith(value, "\"")) { + return utils.pipe(surroundingValue, SS__namespace.replace(newLineRegex, "\n"), SS__namespace.replace(backCartRegex, "\r")); + } + return surroundingValue; + }), + }); + } + return next(lastValue); + })); +} +function parseEnvironmentFiles(baseEnv, paths) { + return GG__namespace.asyncReduce(paths, GG__namespace.reduceFrom([baseEnv]), ({ lastValue, element, nextPush, exit }) => readTextFile.readTextFile(element) + .then(utils.innerPipe(EE__namespace.whenIsRight(utils.innerPipe(parseEnvironmentLine, (value) => nextPush(lastValue, value))), utils.when(EE__namespace.isLeft, exit)))); +} + +exports.parseEnvironmentFiles = parseEnvironmentFiles; +exports.parseEnvironmentLine = parseEnvironmentLine; diff --git a/docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.d.ts b/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.d.ts similarity index 100% rename from docs/libs/v0/common/environmentVariable/parseEnvironmentFiles.d.ts rename to docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.d.ts diff --git a/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.mjs b/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.mjs new file mode 100644 index 0000000..14e6984 --- /dev/null +++ b/docs/libs/v0/dist/common/environmentVariable/parseEnvironmentFiles.mjs @@ -0,0 +1,33 @@ +import { innerPipe, when, pipe } from '@duplojs/utils'; +import * as GG from '@duplojs/utils/generator'; +import * as SS from '@duplojs/utils/string'; +import * as EE from '@duplojs/utils/either'; +import { readTextFile } from '../../file/readTextFile.mjs'; + +const lineRegex = /^(?:export\s+)?(?[A-Z_][A-Z0-9_]*)=(?'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|`(?:\\`|[^`])*`|[^\s#\r\n][^#\r\n]*|)\s*(?:#.*)?$/mg; +const endLineBreakerRegex = /\r\n?/mg; +const surroundingQuoteRegex = /^(['"`])([\s\S]*)\1$/mg; +const backCartRegex = /\\r/g; +const newLineRegex = /\\n/g; +function parseEnvironmentLine(line) { + return pipe(line, SS.replace(endLineBreakerRegex, "\n"), SS.extractAll(lineRegex), GG.reduce(GG.reduceFrom({}), ({ element, nextWithObject, lastValue, next }) => { + if (element.namedGroups?.key && element.namedGroups?.value) { + return nextWithObject(lastValue, { + [element.namedGroups.key]: pipe(element.namedGroups.value, (value) => { + const surroundingValue = SS.replace(value, surroundingQuoteRegex, "$2"); + if (SS.startsWith(value, "\"")) { + return pipe(surroundingValue, SS.replace(newLineRegex, "\n"), SS.replace(backCartRegex, "\r")); + } + return surroundingValue; + }), + }); + } + return next(lastValue); + })); +} +function parseEnvironmentFiles(baseEnv, paths) { + return GG.asyncReduce(paths, GG.reduceFrom([baseEnv]), ({ lastValue, element, nextPush, exit }) => readTextFile(element) + .then(innerPipe(EE.whenIsRight(innerPipe(parseEnvironmentLine, (value) => nextPush(lastValue, value))), when(EE.isLeft, exit)))); +} + +export { parseEnvironmentFiles, parseEnvironmentLine }; diff --git a/docs/libs/v0/common/environmentVariableOrThrow.cjs b/docs/libs/v0/dist/common/environmentVariableOrThrow.cjs similarity index 59% rename from docs/libs/v0/common/environmentVariableOrThrow.cjs rename to docs/libs/v0/dist/common/environmentVariableOrThrow.cjs index d6eb757..b45c1f5 100644 --- a/docs/libs/v0/common/environmentVariableOrThrow.cjs +++ b/docs/libs/v0/dist/common/environmentVariableOrThrow.cjs @@ -1,9 +1,29 @@ 'use strict'; var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); var kind = require('../kind.cjs'); var index = require('./environmentVariable/index.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + class EnvironmentVariableError extends utils.kindHeritage("environment-variable-error", kind.createDuplojsServerUtilsKind("environment-variable-error"), Error) { error; constructor(error) { @@ -16,7 +36,7 @@ class EnvironmentVariableError extends utils.kindHeritage("environment-variable- */ async function environmentVariableOrThrow(shape, params) { const result = await index.environmentVariable(shape, params); - if (utils.E.isLeft(result)) { + if (EE__namespace.isLeft(result)) { throw new EnvironmentVariableError(result); } return utils.unwrap(result); diff --git a/docs/libs/v0/common/environmentVariableOrThrow.d.ts b/docs/libs/v0/dist/common/environmentVariableOrThrow.d.ts similarity index 82% rename from docs/libs/v0/common/environmentVariableOrThrow.d.ts rename to docs/libs/v0/dist/common/environmentVariableOrThrow.d.ts index 7b8e9e4..c0a5513 100644 --- a/docs/libs/v0/common/environmentVariableOrThrow.d.ts +++ b/docs/libs/v0/dist/common/environmentVariableOrThrow.d.ts @@ -1,12 +1,13 @@ -import { type DP, E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import type * as DDP from "@duplojs/utils/dataParser"; import type * as SF from "../file"; import { type EnvironmentVariableParams } from "./environmentVariable"; declare const EnvironmentVariableError_base: new (params: { "@DuplojsServerUtils/environment-variable-error"?: unknown; }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind, unknown> & import("@duplojs/utils").Kind, unknown>; export declare class EnvironmentVariableError extends EnvironmentVariableError_base { - error: SF.FileSystemLeft<"read-text-file"> | E.Error; - constructor(error: SF.FileSystemLeft<"read-text-file"> | E.Error); + error: SF.FileSystemLeft<"read-text-file"> | EE.Error; + constructor(error: SF.FileSystemLeft<"read-text-file"> | EE.Error); } /** * Load and validate environment variables or throw. @@ -55,5 +56,5 @@ export declare class EnvironmentVariableError extends EnvironmentVariableError_b * @see https://server-utils.duplojs.dev/en/v0/api/common/environmentVariableOrThrow * @see https://server-utils.duplojs.dev/en/v0/api/common/environmentVariable */ -export declare function environmentVariableOrThrow(shape: GenericShape, params?: EnvironmentVariableParams): Promise>; +export declare function environmentVariableOrThrow(shape: GenericShape, params?: EnvironmentVariableParams): Promise>; export {}; diff --git a/docs/libs/v0/common/environmentVariableOrThrow.mjs b/docs/libs/v0/dist/common/environmentVariableOrThrow.mjs similarity index 86% rename from docs/libs/v0/common/environmentVariableOrThrow.mjs rename to docs/libs/v0/dist/common/environmentVariableOrThrow.mjs index e3af1a2..b45efb5 100644 --- a/docs/libs/v0/common/environmentVariableOrThrow.mjs +++ b/docs/libs/v0/dist/common/environmentVariableOrThrow.mjs @@ -1,4 +1,5 @@ -import { kindHeritage, E, unwrap } from '@duplojs/utils'; +import { kindHeritage, unwrap } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { createDuplojsServerUtilsKind } from '../kind.mjs'; import { environmentVariable } from './environmentVariable/index.mjs'; @@ -14,7 +15,7 @@ class EnvironmentVariableError extends kindHeritage("environment-variable-error" */ async function environmentVariableOrThrow(shape, params) { const result = await environmentVariable(shape, params); - if (E.isLeft(result)) { + if (EE.isLeft(result)) { throw new EnvironmentVariableError(result); } return unwrap(result); diff --git a/docs/libs/v0/common/exitProcess.cjs b/docs/libs/v0/dist/common/exitProcess.cjs similarity index 100% rename from docs/libs/v0/common/exitProcess.cjs rename to docs/libs/v0/dist/common/exitProcess.cjs diff --git a/docs/libs/v0/common/exitProcess.d.ts b/docs/libs/v0/dist/common/exitProcess.d.ts similarity index 100% rename from docs/libs/v0/common/exitProcess.d.ts rename to docs/libs/v0/dist/common/exitProcess.d.ts diff --git a/docs/libs/v0/common/exitProcess.mjs b/docs/libs/v0/dist/common/exitProcess.mjs similarity index 100% rename from docs/libs/v0/common/exitProcess.mjs rename to docs/libs/v0/dist/common/exitProcess.mjs diff --git a/docs/libs/v0/dist/common/getCurrentWorkDirectory.cjs b/docs/libs/v0/dist/common/getCurrentWorkDirectory.cjs new file mode 100644 index 0000000..1444367 --- /dev/null +++ b/docs/libs/v0/dist/common/getCurrentWorkDirectory.cjs @@ -0,0 +1,34 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include common/getCurrentWorkDirectory/index.md} + */ +const getCurrentWorkDirectory = implementor.implementFunction("getCurrentWorkDirectory", { + NODE: () => utils.pipe(EE__namespace.safeCallback(() => EE__namespace.success(process.cwd())), EE__namespace.whenIsLeft(EE__namespace.error)), + DENO: () => utils.pipe(EE__namespace.safeCallback(() => EE__namespace.success(Deno.cwd())), EE__namespace.whenIsLeft(EE__namespace.error)), +}); + +exports.getCurrentWorkDirectory = getCurrentWorkDirectory; diff --git a/docs/libs/v0/common/getCurrentWorkDirectory.d.ts b/docs/libs/v0/dist/common/getCurrentWorkDirectory.d.ts similarity index 77% rename from docs/libs/v0/common/getCurrentWorkDirectory.d.ts rename to docs/libs/v0/dist/common/getCurrentWorkDirectory.d.ts index 71ea30f..1948523 100644 --- a/docs/libs/v0/common/getCurrentWorkDirectory.d.ts +++ b/docs/libs/v0/dist/common/getCurrentWorkDirectory.d.ts @@ -1,7 +1,7 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; declare module "../implementor" { interface ServerUtilsFunction { - getCurrentWorkDirectory(): E.Error | E.Success; + getCurrentWorkDirectory(): EE.Error | EE.Success; getCurrentWorkDirectoryOrThrow(): string; } } @@ -26,4 +26,4 @@ declare module "../implementor" { * @see https://server-utils.duplojs.dev/en/v0/api/common/getCurrentWorkDirectory * */ -export declare const getCurrentWorkDirectory: () => E.Error | E.Success; +export declare const getCurrentWorkDirectory: () => EE.Error | EE.Success; diff --git a/docs/libs/v0/dist/common/getCurrentWorkDirectory.mjs b/docs/libs/v0/dist/common/getCurrentWorkDirectory.mjs new file mode 100644 index 0000000..a917d9f --- /dev/null +++ b/docs/libs/v0/dist/common/getCurrentWorkDirectory.mjs @@ -0,0 +1,13 @@ +import { pipe } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; +import { implementFunction } from '../implementor.mjs'; + +/** + * {@include common/getCurrentWorkDirectory/index.md} + */ +const getCurrentWorkDirectory = implementFunction("getCurrentWorkDirectory", { + NODE: () => pipe(EE.safeCallback(() => EE.success(process.cwd())), EE.whenIsLeft(EE.error)), + DENO: () => pipe(EE.safeCallback(() => EE.success(Deno.cwd())), EE.whenIsLeft(EE.error)), +}); + +export { getCurrentWorkDirectory }; diff --git a/docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.cjs b/docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.cjs similarity index 100% rename from docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.cjs rename to docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.cjs diff --git a/docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.d.ts b/docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.d.ts similarity index 100% rename from docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.d.ts rename to docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.d.ts diff --git a/docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.mjs b/docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.mjs similarity index 100% rename from docs/libs/v0/common/getCurrentWorkDirectoryOrThrow.mjs rename to docs/libs/v0/dist/common/getCurrentWorkDirectoryOrThrow.mjs diff --git a/docs/libs/v0/common/getProcessArguments.cjs b/docs/libs/v0/dist/common/getProcessArguments.cjs similarity index 100% rename from docs/libs/v0/common/getProcessArguments.cjs rename to docs/libs/v0/dist/common/getProcessArguments.cjs diff --git a/docs/libs/v0/common/getProcessArguments.d.ts b/docs/libs/v0/dist/common/getProcessArguments.d.ts similarity index 100% rename from docs/libs/v0/common/getProcessArguments.d.ts rename to docs/libs/v0/dist/common/getProcessArguments.d.ts diff --git a/docs/libs/v0/common/getProcessArguments.mjs b/docs/libs/v0/dist/common/getProcessArguments.mjs similarity index 100% rename from docs/libs/v0/common/getProcessArguments.mjs rename to docs/libs/v0/dist/common/getProcessArguments.mjs diff --git a/docs/libs/v0/common/index.d.ts b/docs/libs/v0/dist/common/index.d.ts similarity index 100% rename from docs/libs/v0/common/index.d.ts rename to docs/libs/v0/dist/common/index.d.ts diff --git a/docs/libs/v0/dist/common/setCurrentWorkingDirectory.cjs b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.cjs new file mode 100644 index 0000000..8e1405d --- /dev/null +++ b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.cjs @@ -0,0 +1,36 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var PP = require('@duplojs/utils/pattern'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var PP__namespace = /*#__PURE__*/_interopNamespaceDefault(PP); + +/** + * {@include common/setCurrentWorkingDirectory/index.md} + */ +const setCurrentWorkingDirectory = implementor.implementFunction("setCurrentWorkingDirectory", { + NODE: (path) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => EE__namespace.safeCallback(() => void process.chdir(path)), PP__namespace.when(EE__namespace.isLeft, EE__namespace.fail), PP__namespace.otherwise(EE__namespace.ok)), + DENO: (path) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => EE__namespace.safeCallback(() => void Deno.chdir(path)), PP__namespace.when(EE__namespace.isLeft, EE__namespace.fail), PP__namespace.otherwise(EE__namespace.ok)), +}); + +exports.setCurrentWorkingDirectory = setCurrentWorkingDirectory; diff --git a/docs/libs/v0/common/setCurrentWorkingDirectory.d.ts b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.d.ts similarity index 86% rename from docs/libs/v0/common/setCurrentWorkingDirectory.d.ts rename to docs/libs/v0/dist/common/setCurrentWorkingDirectory.d.ts index a15decd..094b49b 100644 --- a/docs/libs/v0/common/setCurrentWorkingDirectory.d.ts +++ b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.d.ts @@ -1,7 +1,7 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; declare module "../implementor" { interface ServerUtilsFunction { - setCurrentWorkingDirectory(path: GenericPath): E.Fail | E.Ok; + setCurrentWorkingDirectory(path: GenericPath): EE.Fail | EE.Ok; } } /** @@ -26,4 +26,4 @@ declare module "../implementor" { * @see https://server-utils.duplojs.dev/en/v0/api/common/setCurrentWorkingDirectory * */ -export declare const setCurrentWorkingDirectory: (path: GenericPath) => E.Fail | E.Ok; +export declare const setCurrentWorkingDirectory: (path: GenericPath) => EE.Fail | EE.Ok; diff --git a/docs/libs/v0/dist/common/setCurrentWorkingDirectory.mjs b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.mjs new file mode 100644 index 0000000..159ea4f --- /dev/null +++ b/docs/libs/v0/dist/common/setCurrentWorkingDirectory.mjs @@ -0,0 +1,14 @@ +import { pipe, when, instanceOf } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; +import * as PP from '@duplojs/utils/pattern'; +import { implementFunction } from '../implementor.mjs'; + +/** + * {@include common/setCurrentWorkingDirectory/index.md} + */ +const setCurrentWorkingDirectory = implementFunction("setCurrentWorkingDirectory", { + NODE: (path) => pipe(path, when(instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => EE.safeCallback(() => void process.chdir(path)), PP.when(EE.isLeft, EE.fail), PP.otherwise(EE.ok)), + DENO: (path) => pipe(path, when(instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (path) => EE.safeCallback(() => void Deno.chdir(path)), PP.when(EE.isLeft, EE.fail), PP.otherwise(EE.ok)), +}); + +export { setCurrentWorkingDirectory }; diff --git a/docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.cjs b/docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.cjs similarity index 57% rename from docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.cjs rename to docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.cjs index 381a5af..a928a77 100644 --- a/docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.cjs +++ b/docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.cjs @@ -1,9 +1,29 @@ 'use strict'; var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); var kind = require('../kind.cjs'); var setCurrentWorkingDirectory = require('./setCurrentWorkingDirectory.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + class SetCurrentWorkingDirectoryError extends utils.kindHeritage("set-working-directory-error", kind.createDuplojsServerUtilsKind("set-working-directory-error"), Error) { constructor() { super({}, ["Failed to set current working directory"]); @@ -14,7 +34,7 @@ class SetCurrentWorkingDirectoryError extends utils.kindHeritage("set-working-di */ function setCurrentWorkingDirectoryOrThrow(path) { const result = setCurrentWorkingDirectory.setCurrentWorkingDirectory(path); - if (utils.E.isLeft(result)) { + if (EE__namespace.isLeft(result)) { throw new SetCurrentWorkingDirectoryError(); } return; diff --git a/docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.d.ts b/docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.d.ts similarity index 100% rename from docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.d.ts rename to docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.d.ts diff --git a/docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.mjs b/docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.mjs similarity index 85% rename from docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.mjs rename to docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.mjs index 89fbd9e..5ef9876 100644 --- a/docs/libs/v0/common/setCurrentWorkingDirectoryOrThrow.mjs +++ b/docs/libs/v0/dist/common/setCurrentWorkingDirectoryOrThrow.mjs @@ -1,4 +1,5 @@ -import { kindHeritage, E } from '@duplojs/utils'; +import { kindHeritage } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { createDuplojsServerUtilsKind } from '../kind.mjs'; import { setCurrentWorkingDirectory } from './setCurrentWorkingDirectory.mjs'; @@ -12,7 +13,7 @@ class SetCurrentWorkingDirectoryError extends kindHeritage("set-working-director */ function setCurrentWorkingDirectoryOrThrow(path) { const result = setCurrentWorkingDirectory(path); - if (E.isLeft(result)) { + if (EE.isLeft(result)) { throw new SetCurrentWorkingDirectoryError(); } return; diff --git a/docs/libs/v0/dataParser/extended/coerce/file.cjs b/docs/libs/v0/dist/dataParser/extended/coerce/file.cjs similarity index 100% rename from docs/libs/v0/dataParser/extended/coerce/file.cjs rename to docs/libs/v0/dist/dataParser/extended/coerce/file.cjs diff --git a/docs/libs/v0/dataParser/extended/coerce/file.d.ts b/docs/libs/v0/dist/dataParser/extended/coerce/file.d.ts similarity index 60% rename from docs/libs/v0/dataParser/extended/coerce/file.d.ts rename to docs/libs/v0/dist/dataParser/extended/coerce/file.d.ts index 091136f..ebcc177 100644 --- a/docs/libs/v0/dataParser/extended/coerce/file.d.ts +++ b/docs/libs/v0/dist/dataParser/extended/coerce/file.d.ts @@ -1,6 +1,7 @@ +import type { NeverCoalescing } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; import type * as dataParsers from "../../parsers"; import * as dataParsersExtended from ".."; -import { type DP, type NeverCoalescing } from "@duplojs/utils"; -export declare function file, "mimeType" | "minSize" | "maxSize" | "coerce"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): dataParsersExtended.DataParserFileExtended & { +export declare function file, "mimeType" | "minSize" | "maxSize" | "coerce"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): dataParsersExtended.DataParserFileExtended & { coerce: true; }>>; diff --git a/docs/libs/v0/dataParser/extended/coerce/file.mjs b/docs/libs/v0/dist/dataParser/extended/coerce/file.mjs similarity index 100% rename from docs/libs/v0/dataParser/extended/coerce/file.mjs rename to docs/libs/v0/dist/dataParser/extended/coerce/file.mjs diff --git a/docs/libs/v0/dataParser/extended/coerce/index.cjs b/docs/libs/v0/dist/dataParser/extended/coerce/index.cjs similarity index 100% rename from docs/libs/v0/dataParser/extended/coerce/index.cjs rename to docs/libs/v0/dist/dataParser/extended/coerce/index.cjs diff --git a/docs/libs/v0/dataParser/extended/coerce/index.d.ts b/docs/libs/v0/dist/dataParser/extended/coerce/index.d.ts similarity index 100% rename from docs/libs/v0/dataParser/extended/coerce/index.d.ts rename to docs/libs/v0/dist/dataParser/extended/coerce/index.d.ts diff --git a/docs/libs/v0/dataParser/extended/coerce/index.mjs b/docs/libs/v0/dist/dataParser/extended/coerce/index.mjs similarity index 100% rename from docs/libs/v0/dataParser/extended/coerce/index.mjs rename to docs/libs/v0/dist/dataParser/extended/coerce/index.mjs diff --git a/docs/libs/v0/dataParser/extended/file.cjs b/docs/libs/v0/dist/dataParser/extended/file.cjs similarity index 75% rename from docs/libs/v0/dataParser/extended/file.cjs rename to docs/libs/v0/dist/dataParser/extended/file.cjs index ce4efab..6bd3a7d 100644 --- a/docs/libs/v0/dataParser/extended/file.cjs +++ b/docs/libs/v0/dist/dataParser/extended/file.cjs @@ -1,13 +1,33 @@ 'use strict'; var utils = require('@duplojs/utils'); +var DDP = require('@duplojs/utils/dataParser'); var file$1 = require('../parsers/file.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var DDP__namespace = /*#__PURE__*/_interopNamespaceDefault(DDP); + /** * {@include dataParserExtended/file/index.md} */ function file(params, definition) { - const self = utils.DP.dataParserExtendedInit(file$1.file(params, definition), { + const self = DDP__namespace.dataParserExtendedInit(file$1.file(params, definition), { mimeType(self, value) { return file({ mimeType: value, diff --git a/docs/libs/v0/dataParser/extended/file.d.ts b/docs/libs/v0/dist/dataParser/extended/file.d.ts similarity index 79% rename from docs/libs/v0/dataParser/extended/file.d.ts rename to docs/libs/v0/dist/dataParser/extended/file.d.ts index 703b7a6..932e7a6 100644 --- a/docs/libs/v0/dataParser/extended/file.d.ts +++ b/docs/libs/v0/dist/dataParser/extended/file.d.ts @@ -1,7 +1,8 @@ -import { type AnyTuple, type BytesInString, DP, type FixDeepFunctionInfer, type Kind, type NeverCoalescing } from "@duplojs/utils"; +import { type AnyTuple, type BytesInString, type FixDeepFunctionInfer, type Kind, type NeverCoalescing } from "@duplojs/utils"; +import * as DDP from "@duplojs/utils/dataParser"; import * as dataParsers from "../parsers"; import { type FileInterface } from "../../file"; -type _DataParserFileExtended = (Kind & DP.DataParserExtended); +type _DataParserFileExtended = (Kind & DDP.DataParserExtended); export interface DataParserFileExtended extends _DataParserFileExtended { addChecker(...args: FixDeepFunctionInfer): DataParserFileExtended>; - refine(theFunction: (input: DP.Output) => boolean, definition?: Partial>): DataParserFileExtended>]>>; + ], GenericChecker>): DataParserFileExtended>; + refine(theFunction: (input: DDP.Output) => boolean, definition?: Partial>): DataParserFileExtended>]>>; /** Set a mime type constraint on the parsed file. */ mimeType(value: string | AnyTuple | RegExp): DataParserFileExtended; /** @@ -61,7 +62,7 @@ export interface DataParserFileExtended, "mimeType" | "minSize" | "maxSize"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): DataParserFileExtended>>; +export declare function file, "mimeType" | "minSize" | "maxSize"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): DataParserFileExtended>>; export declare namespace file { var overrideHandler: import("@duplojs/utils").OverrideHandler>; } diff --git a/docs/libs/v0/dataParser/extended/file.mjs b/docs/libs/v0/dist/dataParser/extended/file.mjs similarity index 92% rename from docs/libs/v0/dataParser/extended/file.mjs rename to docs/libs/v0/dist/dataParser/extended/file.mjs index b6e78c9..540d28c 100644 --- a/docs/libs/v0/dataParser/extended/file.mjs +++ b/docs/libs/v0/dist/dataParser/extended/file.mjs @@ -1,11 +1,12 @@ -import { DP, createOverride } from '@duplojs/utils'; +import { createOverride } from '@duplojs/utils'; +import * as DDP from '@duplojs/utils/dataParser'; import { file as file$1 } from '../parsers/file.mjs'; /** * {@include dataParserExtended/file/index.md} */ function file(params, definition) { - const self = DP.dataParserExtendedInit(file$1(params, definition), { + const self = DDP.dataParserExtendedInit(file$1(params, definition), { mimeType(self, value) { return file({ mimeType: value, diff --git a/docs/libs/v0/dataParser/extended/index.cjs b/docs/libs/v0/dist/dataParser/extended/index.cjs similarity index 100% rename from docs/libs/v0/dataParser/extended/index.cjs rename to docs/libs/v0/dist/dataParser/extended/index.cjs diff --git a/docs/libs/v0/dataParser/extended/index.d.ts b/docs/libs/v0/dist/dataParser/extended/index.d.ts similarity index 100% rename from docs/libs/v0/dataParser/extended/index.d.ts rename to docs/libs/v0/dist/dataParser/extended/index.d.ts diff --git a/docs/libs/v0/dataParser/extended/index.mjs b/docs/libs/v0/dist/dataParser/extended/index.mjs similarity index 100% rename from docs/libs/v0/dataParser/extended/index.mjs rename to docs/libs/v0/dist/dataParser/extended/index.mjs diff --git a/docs/libs/v0/dataParser/index.cjs b/docs/libs/v0/dist/dataParser/index.cjs similarity index 100% rename from docs/libs/v0/dataParser/index.cjs rename to docs/libs/v0/dist/dataParser/index.cjs diff --git a/docs/libs/v0/dataParser/index.d.ts b/docs/libs/v0/dist/dataParser/index.d.ts similarity index 100% rename from docs/libs/v0/dataParser/index.d.ts rename to docs/libs/v0/dist/dataParser/index.d.ts diff --git a/docs/libs/v0/dataParser/index.mjs b/docs/libs/v0/dist/dataParser/index.mjs similarity index 100% rename from docs/libs/v0/dataParser/index.mjs rename to docs/libs/v0/dist/dataParser/index.mjs diff --git a/docs/libs/v0/dataParser/kind.cjs b/docs/libs/v0/dist/dataParser/kind.cjs similarity index 100% rename from docs/libs/v0/dataParser/kind.cjs rename to docs/libs/v0/dist/dataParser/kind.cjs diff --git a/docs/libs/v0/dataParser/kind.d.ts b/docs/libs/v0/dist/dataParser/kind.d.ts similarity index 100% rename from docs/libs/v0/dataParser/kind.d.ts rename to docs/libs/v0/dist/dataParser/kind.d.ts diff --git a/docs/libs/v0/dataParser/kind.mjs b/docs/libs/v0/dist/dataParser/kind.mjs similarity index 100% rename from docs/libs/v0/dataParser/kind.mjs rename to docs/libs/v0/dist/dataParser/kind.mjs diff --git a/docs/libs/v0/dataParser/override.d.ts b/docs/libs/v0/dist/dataParser/override.d.ts similarity index 100% rename from docs/libs/v0/dataParser/override.d.ts rename to docs/libs/v0/dist/dataParser/override.d.ts diff --git a/docs/libs/v0/dataParser/parsers/coerce/file.cjs b/docs/libs/v0/dist/dataParser/parsers/coerce/file.cjs similarity index 100% rename from docs/libs/v0/dataParser/parsers/coerce/file.cjs rename to docs/libs/v0/dist/dataParser/parsers/coerce/file.cjs diff --git a/docs/libs/v0/dataParser/parsers/coerce/file.d.ts b/docs/libs/v0/dist/dataParser/parsers/coerce/file.d.ts similarity index 58% rename from docs/libs/v0/dataParser/parsers/coerce/file.d.ts rename to docs/libs/v0/dist/dataParser/parsers/coerce/file.d.ts index ce82f09..3970fb7 100644 --- a/docs/libs/v0/dataParser/parsers/coerce/file.d.ts +++ b/docs/libs/v0/dist/dataParser/parsers/coerce/file.d.ts @@ -1,5 +1,6 @@ +import type { NeverCoalescing } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; import * as dataParsers from "../../parsers"; -import { type DP, type NeverCoalescing } from "@duplojs/utils"; -export declare function file, "mimeType" | "minSize" | "maxSize" | "coerce"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): dataParsers.DataParserFile & { +export declare function file, "mimeType" | "minSize" | "maxSize" | "coerce"> = never>(params?: dataParsers.DataParserFileParams, definition?: GenericDefinition): dataParsers.DataParserFile & { coerce: true; }>>; diff --git a/docs/libs/v0/dataParser/parsers/coerce/file.mjs b/docs/libs/v0/dist/dataParser/parsers/coerce/file.mjs similarity index 100% rename from docs/libs/v0/dataParser/parsers/coerce/file.mjs rename to docs/libs/v0/dist/dataParser/parsers/coerce/file.mjs diff --git a/docs/libs/v0/dataParser/parsers/coerce/index.cjs b/docs/libs/v0/dist/dataParser/parsers/coerce/index.cjs similarity index 100% rename from docs/libs/v0/dataParser/parsers/coerce/index.cjs rename to docs/libs/v0/dist/dataParser/parsers/coerce/index.cjs diff --git a/docs/libs/v0/dataParser/parsers/coerce/index.d.ts b/docs/libs/v0/dist/dataParser/parsers/coerce/index.d.ts similarity index 100% rename from docs/libs/v0/dataParser/parsers/coerce/index.d.ts rename to docs/libs/v0/dist/dataParser/parsers/coerce/index.d.ts diff --git a/docs/libs/v0/dataParser/parsers/coerce/index.mjs b/docs/libs/v0/dist/dataParser/parsers/coerce/index.mjs similarity index 100% rename from docs/libs/v0/dataParser/parsers/coerce/index.mjs rename to docs/libs/v0/dist/dataParser/parsers/coerce/index.mjs diff --git a/docs/libs/v0/dataParser/parsers/file.cjs b/docs/libs/v0/dist/dataParser/parsers/file.cjs similarity index 62% rename from docs/libs/v0/dataParser/parsers/file.cjs rename to docs/libs/v0/dist/dataParser/parsers/file.cjs index 3a222f0..1f966bc 100644 --- a/docs/libs/v0/dataParser/parsers/file.cjs +++ b/docs/libs/v0/dist/dataParser/parsers/file.cjs @@ -1,15 +1,37 @@ 'use strict'; var utils = require('@duplojs/utils'); +var DDP = require('@duplojs/utils/dataParser'); +var EE = require('@duplojs/utils/either'); var kind = require('../kind.cjs'); var fileInterface = require('../../file/fileInterface.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var DDP__namespace = /*#__PURE__*/_interopNamespaceDefault(DDP); +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + const fileKind = kind.createDataParserKind("file"); /** * {@include dataParser/file/index.md} */ function file(params, definition) { - const self = utils.DP.dataParserInit(fileKind, { + const self = DDP__namespace.dataParserInit(fileKind, { errorMessage: definition?.errorMessage, checkers: definition?.checkers ?? [], coerce: definition?.coerce ?? false, @@ -28,21 +50,21 @@ function file(params, definition) { if (self.definition.checkExist || self.definition.maxSize !== undefined || self.definition.minSize !== undefined) { - return utils.DP.addIssue(error, "async data parser", data, self.definition.errorMessage); + return DDP__namespace.addIssue(error, "async data parser", data, self.definition.errorMessage); } let fileInterface$1 = data; if (self.definition.coerce && typeof fileInterface$1 === "string") { fileInterface$1 = fileInterface.createFileInterface(fileInterface$1); } if (!fileInterface.isFileInterface(fileInterface$1)) { - return utils.DP.addIssue(error, "file", data, self.definition.errorMessage); + return DDP__namespace.addIssue(error, "file", data, self.definition.errorMessage); } if (self.definition.mimeType && !self .definition .mimeType .test(fileInterface$1.getMimeType() ?? "")) { - return utils.DP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, data, "Wrong mimeType."); + return DDP__namespace.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, data, "Wrong mimeType."); } return fileInterface$1; }, @@ -52,33 +74,33 @@ function file(params, definition) { fileInterface$1 = fileInterface.createFileInterface(fileInterface$1); } if (!fileInterface.isFileInterface(fileInterface$1)) { - return utils.DP.addIssue(error, "file", data, self.definition.errorMessage); + return DDP__namespace.addIssue(error, "file", data, self.definition.errorMessage); } if (self.definition.mimeType && !self .definition .mimeType .test(fileInterface$1.getMimeType() ?? "")) { - return utils.DP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, fileInterface$1, "Wrong mimeType."); + return DDP__namespace.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, fileInterface$1, "Wrong mimeType."); } if (self.definition.checkExist || self.definition.maxSize !== undefined || self.definition.minSize !== undefined) { const resultStats = await fileInterface$1.stat(); - if (utils.E.isLeft(resultStats)) { - return utils.DP.addIssue(error, "existing file", fileInterface$1, "File not exist."); + if (EE__namespace.isLeft(resultStats)) { + return DDP__namespace.addIssue(error, "existing file", fileInterface$1, "File not exist."); } const stat = utils.unwrap(resultStats); if (!stat.isFile) { - return utils.DP.addIssue(error, "file", stat, "Is not file."); + return DDP__namespace.addIssue(error, "file", stat, "Is not file."); } if (self.definition.maxSize !== undefined && stat.sizeBytes > self.definition.maxSize) { - return utils.DP.addIssue(error, `file with sizeBytes <= ${self.definition.maxSize}`, stat.sizeBytes, "File is to large."); + return DDP__namespace.addIssue(error, `file with sizeBytes <= ${self.definition.maxSize}`, stat.sizeBytes, "File is to large."); } if (self.definition.minSize !== undefined && stat.sizeBytes < self.definition.minSize) { - return utils.DP.addIssue(error, `file with sizeBytes >= ${self.definition.minSize}`, stat.sizeBytes, "File is to small."); + return DDP__namespace.addIssue(error, `file with sizeBytes >= ${self.definition.minSize}`, stat.sizeBytes, "File is to small."); } } return fileInterface$1; diff --git a/docs/libs/v0/dataParser/parsers/file.d.ts b/docs/libs/v0/dist/dataParser/parsers/file.d.ts similarity index 76% rename from docs/libs/v0/dataParser/parsers/file.d.ts rename to docs/libs/v0/dist/dataParser/parsers/file.d.ts index 291a617..8ceab7c 100644 --- a/docs/libs/v0/dataParser/parsers/file.d.ts +++ b/docs/libs/v0/dist/dataParser/parsers/file.d.ts @@ -1,9 +1,11 @@ -import { type BytesInString, DP, type FixDeepFunctionInfer, type Kind, type O, type NeverCoalescing, type AnyTuple } from "@duplojs/utils"; +import { type BytesInString, type FixDeepFunctionInfer, type Kind, type NeverCoalescing, type AnyTuple } from "@duplojs/utils"; +import * as DDP from "@duplojs/utils/dataParser"; +import type * as OO from "@duplojs/utils/object"; import { type FileInterface } from "../../file"; export interface DataParserFileCheckerCustom { } -export type DataParserFileCheckers = (DataParserFileCheckerCustom[O.GetPropsWithValueExtends] | DP.CheckerRefineImplementation); -export interface DataParserDefinitionFile extends DP.DataParserDefinition { +export type DataParserFileCheckers = (DataParserFileCheckerCustom[OO.GetPropsWithValueExtends] | DDP.CheckerRefineImplementation); +export interface DataParserDefinitionFile extends DDP.DataParserDefinition { readonly coerce: boolean; readonly mimeType?: RegExp; readonly minSize?: number; @@ -11,7 +13,7 @@ export interface DataParserDefinitionFile extends DP.DataParserDefinition>; -type _DataParserFile = (DP.DataParser & Kind); +type _DataParserFile = (DDP.DataParser & Kind); export interface DataParserFile extends _DataParserFile { addChecker(...args: FixDeepFunctionInfer): DataParserFile>; + ], GenericChecker>): DataParserFile>; } export interface DataParserFileParams { readonly mimeType?: string | AnyTuple | RegExp; @@ -61,7 +63,7 @@ export interface DataParserFileParams { * @namespace SDP * */ -export declare function file, "mimeType" | "minSize" | "maxSize" | "checkExist"> = never>(params?: DataParserFileParams, definition?: GenericDefinition): DataParserFile>>; +export declare function file, "mimeType" | "minSize" | "maxSize" | "checkExist"> = never>(params?: DataParserFileParams, definition?: GenericDefinition): DataParserFile>>; export declare namespace file { var overrideHandler: import("@duplojs/utils").OverrideHandler>; } diff --git a/docs/libs/v0/dataParser/parsers/file.mjs b/docs/libs/v0/dist/dataParser/parsers/file.mjs similarity index 70% rename from docs/libs/v0/dataParser/parsers/file.mjs rename to docs/libs/v0/dist/dataParser/parsers/file.mjs index 78cf49a..cc4fc77 100644 --- a/docs/libs/v0/dataParser/parsers/file.mjs +++ b/docs/libs/v0/dist/dataParser/parsers/file.mjs @@ -1,4 +1,6 @@ -import { DP, toRegExp, stringToBytes, E, unwrap, createOverride } from '@duplojs/utils'; +import { toRegExp, stringToBytes, unwrap, createOverride } from '@duplojs/utils'; +import * as DDP from '@duplojs/utils/dataParser'; +import * as EE from '@duplojs/utils/either'; import { createDataParserKind } from '../kind.mjs'; import { createFileInterface, isFileInterface } from '../../file/fileInterface.mjs'; @@ -7,7 +9,7 @@ const fileKind = createDataParserKind("file"); * {@include dataParser/file/index.md} */ function file(params, definition) { - const self = DP.dataParserInit(fileKind, { + const self = DDP.dataParserInit(fileKind, { errorMessage: definition?.errorMessage, checkers: definition?.checkers ?? [], coerce: definition?.coerce ?? false, @@ -26,21 +28,21 @@ function file(params, definition) { if (self.definition.checkExist || self.definition.maxSize !== undefined || self.definition.minSize !== undefined) { - return DP.addIssue(error, "async data parser", data, self.definition.errorMessage); + return DDP.addIssue(error, "async data parser", data, self.definition.errorMessage); } let fileInterface = data; if (self.definition.coerce && typeof fileInterface === "string") { fileInterface = createFileInterface(fileInterface); } if (!isFileInterface(fileInterface)) { - return DP.addIssue(error, "file", data, self.definition.errorMessage); + return DDP.addIssue(error, "file", data, self.definition.errorMessage); } if (self.definition.mimeType && !self .definition .mimeType .test(fileInterface.getMimeType() ?? "")) { - return DP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, data, "Wrong mimeType."); + return DDP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, data, "Wrong mimeType."); } return fileInterface; }, @@ -50,33 +52,33 @@ function file(params, definition) { fileInterface = createFileInterface(fileInterface); } if (!isFileInterface(fileInterface)) { - return DP.addIssue(error, "file", data, self.definition.errorMessage); + return DDP.addIssue(error, "file", data, self.definition.errorMessage); } if (self.definition.mimeType && !self .definition .mimeType .test(fileInterface.getMimeType() ?? "")) { - return DP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, fileInterface, "Wrong mimeType."); + return DDP.addIssue(error, `file with mime type matching ${self.definition.mimeType.source}`, fileInterface, "Wrong mimeType."); } if (self.definition.checkExist || self.definition.maxSize !== undefined || self.definition.minSize !== undefined) { const resultStats = await fileInterface.stat(); - if (E.isLeft(resultStats)) { - return DP.addIssue(error, "existing file", fileInterface, "File not exist."); + if (EE.isLeft(resultStats)) { + return DDP.addIssue(error, "existing file", fileInterface, "File not exist."); } const stat = unwrap(resultStats); if (!stat.isFile) { - return DP.addIssue(error, "file", stat, "Is not file."); + return DDP.addIssue(error, "file", stat, "Is not file."); } if (self.definition.maxSize !== undefined && stat.sizeBytes > self.definition.maxSize) { - return DP.addIssue(error, `file with sizeBytes <= ${self.definition.maxSize}`, stat.sizeBytes, "File is to large."); + return DDP.addIssue(error, `file with sizeBytes <= ${self.definition.maxSize}`, stat.sizeBytes, "File is to large."); } if (self.definition.minSize !== undefined && stat.sizeBytes < self.definition.minSize) { - return DP.addIssue(error, `file with sizeBytes >= ${self.definition.minSize}`, stat.sizeBytes, "File is to small."); + return DDP.addIssue(error, `file with sizeBytes >= ${self.definition.minSize}`, stat.sizeBytes, "File is to small."); } } return fileInterface; diff --git a/docs/libs/v0/dataParser/parsers/index.d.ts b/docs/libs/v0/dist/dataParser/parsers/index.d.ts similarity index 100% rename from docs/libs/v0/dataParser/parsers/index.d.ts rename to docs/libs/v0/dist/dataParser/parsers/index.d.ts diff --git a/docs/libs/v0/dist/file/appendFile.cjs b/docs/libs/v0/dist/file/appendFile.cjs new file mode 100644 index 0000000..eaf9161 --- /dev/null +++ b/docs/libs/v0/dist/file/appendFile.cjs @@ -0,0 +1,40 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/appendFile/index.md} + */ +const appendFile = implementor.implementFunction("appendFile", { + NODE: async (path, data) => { + const fs = await implementor.nodeFileSystem.value; + return fs.appendFile(path, data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-append-file", value)); + }, + DENO: (path, data) => Deno.writeFile(path, data, { append: true }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-append-file", value)), +}); + +exports.appendFile = appendFile; diff --git a/docs/libs/v0/file/appendFile.d.ts b/docs/libs/v0/dist/file/appendFile.d.ts similarity index 85% rename from docs/libs/v0/file/appendFile.d.ts rename to docs/libs/v0/dist/file/appendFile.d.ts index 1848bb1..52b2007 100644 --- a/docs/libs/v0/file/appendFile.d.ts +++ b/docs/libs/v0/dist/file/appendFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - appendFile(path: string, data: Uint8Array): Promise | E.Ok>; + appendFile(path: string, data: Uint8Array): Promise | EE.Ok>; } } /** @@ -28,4 +28,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const appendFile: (path: string, data: Uint8Array) => Promise | E.Ok>; +export declare const appendFile: (path: string, data: Uint8Array) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/appendFile.mjs b/docs/libs/v0/dist/file/appendFile.mjs similarity index 63% rename from docs/libs/v0/file/appendFile.mjs rename to docs/libs/v0/dist/file/appendFile.mjs index 33f86ab..1d9e8d6 100644 --- a/docs/libs/v0/file/appendFile.mjs +++ b/docs/libs/v0/dist/file/appendFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,12 +8,12 @@ const appendFile = implementFunction("appendFile", { NODE: async (path, data) => { const fs = await nodeFileSystem.value; return fs.appendFile(path, data) - .then(E.ok) - .catch((value) => E.left("file-system-append-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-append-file", value)); }, DENO: (path, data) => Deno.writeFile(path, data, { append: true }) - .then(E.ok) - .catch((value) => E.left("file-system-append-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-append-file", value)), }); export { appendFile }; diff --git a/docs/libs/v0/dist/file/appendTextFile.cjs b/docs/libs/v0/dist/file/appendTextFile.cjs new file mode 100644 index 0000000..cc68bbf --- /dev/null +++ b/docs/libs/v0/dist/file/appendTextFile.cjs @@ -0,0 +1,40 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/appendTextFile/index.md} + */ +const appendTextFile = implementor.implementFunction("appendTextFile", { + NODE: async (path, data) => { + const fs = await implementor.nodeFileSystem.value; + return fs.appendFile(path, data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-append-text-file", value)); + }, + DENO: (path, data) => Deno.writeTextFile(path, data, { append: true }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-append-text-file", value)), +}); + +exports.appendTextFile = appendTextFile; diff --git a/docs/libs/v0/file/appendTextFile.d.ts b/docs/libs/v0/dist/file/appendTextFile.d.ts similarity index 84% rename from docs/libs/v0/file/appendTextFile.d.ts rename to docs/libs/v0/dist/file/appendTextFile.d.ts index 094241a..06bfde5 100644 --- a/docs/libs/v0/file/appendTextFile.d.ts +++ b/docs/libs/v0/dist/file/appendTextFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - appendTextFile(path: string, data: string): Promise | E.Ok>; + appendTextFile(path: string, data: string): Promise | EE.Ok>; } } /** @@ -26,4 +26,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const appendTextFile: (path: string, data: string) => Promise | E.Ok>; +export declare const appendTextFile: (path: string, data: string) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/appendTextFile.mjs b/docs/libs/v0/dist/file/appendTextFile.mjs similarity index 63% rename from docs/libs/v0/file/appendTextFile.mjs rename to docs/libs/v0/dist/file/appendTextFile.mjs index 60f6460..d1b0f85 100644 --- a/docs/libs/v0/file/appendTextFile.mjs +++ b/docs/libs/v0/dist/file/appendTextFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,12 +8,12 @@ const appendTextFile = implementFunction("appendTextFile", { NODE: async (path, data) => { const fs = await nodeFileSystem.value; return fs.appendFile(path, data) - .then(E.ok) - .catch((value) => E.left("file-system-append-text-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-append-text-file", value)); }, DENO: (path, data) => Deno.writeTextFile(path, data, { append: true }) - .then(E.ok) - .catch((value) => E.left("file-system-append-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-append-text-file", value)), }); export { appendTextFile }; diff --git a/docs/libs/v0/dist/file/copy.cjs b/docs/libs/v0/dist/file/copy.cjs new file mode 100644 index 0000000..947e9ed --- /dev/null +++ b/docs/libs/v0/dist/file/copy.cjs @@ -0,0 +1,37 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/copy/index.md} + */ +const copy = implementor.implementFunction("copy", { + NODE: async (fromPath, toPath) => { + const fs = await implementor.nodeFileSystem.value; + return fs.cp(fromPath, toPath, { recursive: true }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-copy", value)); + }, +}); + +exports.copy = copy; diff --git a/docs/libs/v0/file/copy.d.ts b/docs/libs/v0/dist/file/copy.d.ts similarity index 85% rename from docs/libs/v0/file/copy.d.ts rename to docs/libs/v0/dist/file/copy.d.ts index a150455..e0f17c9 100644 --- a/docs/libs/v0/file/copy.d.ts +++ b/docs/libs/v0/dist/file/copy.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - copy(fromPath: string, toPath: string): Promise | E.Ok>; + copy(fromPath: string, toPath: string): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const copy: (fromPath: string, toPath: string) => Promise | E.Ok>; +export declare const copy: (fromPath: string, toPath: string) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/copy.mjs b/docs/libs/v0/dist/file/copy.mjs similarity index 70% rename from docs/libs/v0/file/copy.mjs rename to docs/libs/v0/dist/file/copy.mjs index b114e7f..3c2af58 100644 --- a/docs/libs/v0/file/copy.mjs +++ b/docs/libs/v0/dist/file/copy.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,8 +8,8 @@ const copy = implementFunction("copy", { NODE: async (fromPath, toPath) => { const fs = await nodeFileSystem.value; return fs.cp(fromPath, toPath, { recursive: true }) - .then(E.ok) - .catch((value) => E.left("file-system-copy", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-copy", value)); }, }); diff --git a/docs/libs/v0/dist/file/ensureDirectory.cjs b/docs/libs/v0/dist/file/ensureDirectory.cjs new file mode 100644 index 0000000..08bf674 --- /dev/null +++ b/docs/libs/v0/dist/file/ensureDirectory.cjs @@ -0,0 +1,44 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/ensureDirectory/index.md} + */ +const ensureDirectory = implementor.implementFunction("ensureDirectory", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.mkdir(path, { + recursive: true, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-ensure-directory", value)); + }, + DENO: (path) => Deno.mkdir(path, { + recursive: true, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-ensure-directory", value)), +}); + +exports.ensureDirectory = ensureDirectory; diff --git a/docs/libs/v0/file/ensureDirectory.d.ts b/docs/libs/v0/dist/file/ensureDirectory.d.ts similarity index 85% rename from docs/libs/v0/file/ensureDirectory.d.ts rename to docs/libs/v0/dist/file/ensureDirectory.d.ts index 8af96cc..fceaf5c 100644 --- a/docs/libs/v0/file/ensureDirectory.d.ts +++ b/docs/libs/v0/dist/file/ensureDirectory.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - ensureDirectory(path: GenericPath): Promise | E.Ok>; + ensureDirectory(path: GenericPath): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const ensureDirectory: (path: GenericPath) => Promise | E.Ok>; +export declare const ensureDirectory: (path: GenericPath) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/ensureDirectory.mjs b/docs/libs/v0/dist/file/ensureDirectory.mjs similarity index 64% rename from docs/libs/v0/file/ensureDirectory.mjs rename to docs/libs/v0/dist/file/ensureDirectory.mjs index 576fb4b..ac6185b 100644 --- a/docs/libs/v0/file/ensureDirectory.mjs +++ b/docs/libs/v0/dist/file/ensureDirectory.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -10,14 +10,14 @@ const ensureDirectory = implementFunction("ensureDirectory", { return fs.mkdir(path, { recursive: true, }) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-directory", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-directory", value)); }, DENO: (path) => Deno.mkdir(path, { recursive: true, }) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-directory", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-directory", value)), }); export { ensureDirectory }; diff --git a/docs/libs/v0/dist/file/ensureFile.cjs b/docs/libs/v0/dist/file/ensureFile.cjs new file mode 100644 index 0000000..9c7d8a2 --- /dev/null +++ b/docs/libs/v0/dist/file/ensureFile.cjs @@ -0,0 +1,46 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/ensureFile/index.md} + */ +const ensureFile = implementor.implementFunction("ensureFile", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.open(path, "a") + .then((fh) => fh.close()) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-ensure-file", value)); + }, + DENO: (path) => Deno.open(path, { + write: true, + create: true, + append: true, + }) + .then((fh) => void fh.close()) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-ensure-file", value)), +}); + +exports.ensureFile = ensureFile; diff --git a/docs/libs/v0/file/ensureFile.d.ts b/docs/libs/v0/dist/file/ensureFile.d.ts similarity index 79% rename from docs/libs/v0/file/ensureFile.d.ts rename to docs/libs/v0/dist/file/ensureFile.d.ts index 01d5405..afebdcc 100644 --- a/docs/libs/v0/file/ensureFile.d.ts +++ b/docs/libs/v0/dist/file/ensureFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - ensureFile(path: GenericPath): Promise | E.Ok>; + ensureFile(path: GenericPath): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const ensureFile: (path: GenericPath) => Promise | E.Ok>; +export declare const ensureFile: (path: GenericPath) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/ensureFile.mjs b/docs/libs/v0/dist/file/ensureFile.mjs similarity index 68% rename from docs/libs/v0/file/ensureFile.mjs rename to docs/libs/v0/dist/file/ensureFile.mjs index a3c8e9d..a9bf2b2 100644 --- a/docs/libs/v0/file/ensureFile.mjs +++ b/docs/libs/v0/dist/file/ensureFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -9,8 +9,8 @@ const ensureFile = implementFunction("ensureFile", { const fs = await nodeFileSystem.value; return fs.open(path, "a") .then((fh) => fh.close()) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-file", value)); }, DENO: (path) => Deno.open(path, { write: true, @@ -18,8 +18,8 @@ const ensureFile = implementFunction("ensureFile", { append: true, }) .then((fh) => void fh.close()) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-file", value)), }); export { ensureFile }; diff --git a/docs/libs/v0/dist/file/exists.cjs b/docs/libs/v0/dist/file/exists.cjs new file mode 100644 index 0000000..dfef156 --- /dev/null +++ b/docs/libs/v0/dist/file/exists.cjs @@ -0,0 +1,47 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/exists/index.md} + */ +const exists = implementor.implementFunction("exists", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.access(path) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-exists", value)); + }, + DENO: (path) => Deno + .stat(path) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-exists", value)), + BUN: (path) => Bun.file(path) + .exists() + .then((value) => value + ? EE__namespace.ok() + : EE__namespace.left("file-system-exists", new Error("Path does not exist"))) + .catch((value) => EE__namespace.left("file-system-exists", value)), +}); + +exports.exists = exists; diff --git a/docs/libs/v0/file/exists.d.ts b/docs/libs/v0/dist/file/exists.d.ts similarity index 81% rename from docs/libs/v0/file/exists.d.ts rename to docs/libs/v0/dist/file/exists.d.ts index 7fffa5d..bdd60b7 100644 --- a/docs/libs/v0/file/exists.d.ts +++ b/docs/libs/v0/dist/file/exists.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - exists(path: GenericPath): Promise | E.Ok>; + exists(path: GenericPath): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const exists: (path: GenericPath) => Promise | E.Ok>; +export declare const exists: (path: GenericPath) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/exists.mjs b/docs/libs/v0/dist/file/exists.mjs similarity index 52% rename from docs/libs/v0/file/exists.mjs rename to docs/libs/v0/dist/file/exists.mjs index 3ef3ed3..83588a1 100644 --- a/docs/libs/v0/file/exists.mjs +++ b/docs/libs/v0/dist/file/exists.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,19 +8,19 @@ const exists = implementFunction("exists", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.access(path) - .then(E.ok) - .catch((value) => E.left("file-system-exists", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-exists", value)); }, DENO: (path) => Deno .stat(path) - .then(E.ok) - .catch((value) => E.left("file-system-exists", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-exists", value)), BUN: (path) => Bun.file(path) .exists() .then((value) => value - ? E.ok() - : E.left("file-system-exists", new Error("Path does not exist"))) - .catch((value) => E.left("file-system-exists", value)), + ? EE.ok() + : EE.left("file-system-exists", new Error("Path does not exist"))) + .catch((value) => EE.left("file-system-exists", value)), }); export { exists }; diff --git a/docs/libs/v0/file/fileInterface.cjs b/docs/libs/v0/dist/file/fileInterface.cjs similarity index 65% rename from docs/libs/v0/file/fileInterface.cjs rename to docs/libs/v0/dist/file/fileInterface.cjs index 63d532c..c92e1f3 100644 --- a/docs/libs/v0/file/fileInterface.cjs +++ b/docs/libs/v0/dist/file/fileInterface.cjs @@ -1,7 +1,8 @@ 'use strict'; -var kind = require('../kind.cjs'); var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var kind = require('../kind.cjs'); var rename = require('./rename.cjs'); var exists = require('./exists.cjs'); var move = require('./move.cjs'); @@ -9,6 +10,25 @@ var remove = require('./remove.cjs'); var stat = require('./stat.cjs'); var relocate = require('./relocate.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + const fileInterfaceKind = kind.createDuplojsServerUtilsKind("fileInterface"); /** * {@include file/createFileInterface/index.md} @@ -34,13 +54,13 @@ function createFileInterface(path) { return exists.exists(path); } function localRename(newName) { - return utils.asyncPipe(rename.rename(path, newName), utils.E.whenIsRight(utils.innerPipe(createFileInterface, utils.E.success))); + return utils.asyncPipe(rename.rename(path, newName), EE__namespace.whenIsRight(utils.innerPipe(createFileInterface, EE__namespace.success))); } function localRelocate(newParentPath) { - return utils.asyncPipe(relocate.relocate(path, newParentPath), utils.E.whenIsRight(utils.innerPipe(createFileInterface, utils.E.success))); + return utils.asyncPipe(relocate.relocate(path, newParentPath), EE__namespace.whenIsRight(utils.innerPipe(createFileInterface, EE__namespace.success))); } function localMove(newPath) { - return utils.asyncPipe(move.move(path, newPath), utils.E.whenIsRight(() => utils.E.success(createFileInterface(newPath)))); + return utils.asyncPipe(move.move(path, newPath), EE__namespace.whenIsRight(() => EE__namespace.success(createFileInterface(newPath)))); } function localRemove() { return remove.remove(path); diff --git a/docs/libs/v0/file/fileInterface.d.ts b/docs/libs/v0/dist/file/fileInterface.d.ts similarity index 82% rename from docs/libs/v0/file/fileInterface.d.ts rename to docs/libs/v0/dist/file/fileInterface.d.ts index 3f92cc4..43de70a 100644 --- a/docs/libs/v0/file/fileInterface.d.ts +++ b/docs/libs/v0/dist/file/fileInterface.d.ts @@ -1,4 +1,5 @@ -import { type Kind, E, Path } from "@duplojs/utils"; +import { type Kind, Path } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { type StatInfo } from "./stat"; import type { FileSystemLeft } from "./types"; declare const fileInterfaceKind: import("@duplojs/utils").KindHandler>; @@ -8,12 +9,12 @@ export interface FileInterface extends Kind getMimeType(): string | null; getExtension(params?: Path.GetExtensionNameParams): string | null; getParentPath(): string | null; - rename(newName: string): Promise | E.Success>; - relocate(parentPath: string): Promise | E.Success>; - move(newPath: string): Promise | E.Success>; - exists(): Promise | E.Ok>; - remove(): Promise | E.Ok>; - stat(): Promise | E.Success>; + rename(newName: string): Promise | EE.Success>; + relocate(parentPath: string): Promise | EE.Success>; + move(newPath: string): Promise | EE.Success>; + exists(): Promise | EE.Ok>; + remove(): Promise | EE.Ok>; + stat(): Promise | EE.Success>; } /** * Create a file interface with helper methods. diff --git a/docs/libs/v0/file/fileInterface.mjs b/docs/libs/v0/dist/file/fileInterface.mjs similarity index 78% rename from docs/libs/v0/file/fileInterface.mjs rename to docs/libs/v0/dist/file/fileInterface.mjs index 980e043..d9983af 100644 --- a/docs/libs/v0/file/fileInterface.mjs +++ b/docs/libs/v0/dist/file/fileInterface.mjs @@ -1,5 +1,6 @@ +import { asyncPipe, innerPipe, Path, mimeType } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { createDuplojsServerUtilsKind } from '../kind.mjs'; -import { asyncPipe, E, innerPipe, Path, mimeType } from '@duplojs/utils'; import { rename } from './rename.mjs'; import { exists } from './exists.mjs'; import { move } from './move.mjs'; @@ -32,13 +33,13 @@ function createFileInterface(path) { return exists(path); } function localRename(newName) { - return asyncPipe(rename(path, newName), E.whenIsRight(innerPipe(createFileInterface, E.success))); + return asyncPipe(rename(path, newName), EE.whenIsRight(innerPipe(createFileInterface, EE.success))); } function localRelocate(newParentPath) { - return asyncPipe(relocate(path, newParentPath), E.whenIsRight(innerPipe(createFileInterface, E.success))); + return asyncPipe(relocate(path, newParentPath), EE.whenIsRight(innerPipe(createFileInterface, EE.success))); } function localMove(newPath) { - return asyncPipe(move(path, newPath), E.whenIsRight(() => E.success(createFileInterface(newPath)))); + return asyncPipe(move(path, newPath), EE.whenIsRight(() => EE.success(createFileInterface(newPath)))); } function localRemove() { return remove(path); diff --git a/docs/libs/v0/file/folderInterface.cjs b/docs/libs/v0/dist/file/folderInterface.cjs similarity index 65% rename from docs/libs/v0/file/folderInterface.cjs rename to docs/libs/v0/dist/file/folderInterface.cjs index 76a7d42..9576e80 100644 --- a/docs/libs/v0/file/folderInterface.cjs +++ b/docs/libs/v0/dist/file/folderInterface.cjs @@ -1,6 +1,7 @@ 'use strict'; var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); var kind = require('../kind.cjs'); var move = require('./move.cjs'); var exists = require('./exists.cjs'); @@ -11,6 +12,25 @@ var stat = require('./stat.cjs'); var walkDirectory = require('./walkDirectory.cjs'); var relocate = require('./relocate.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + const folderInterfaceKind = kind.createDuplojsServerUtilsKind("folderInterface"); /** * {@include file/createFolderInterface/index.md} @@ -23,13 +43,13 @@ function createFolderInterface(path) { return utils.Path.getParentFolderPath(path); } function localRename(newName) { - return utils.asyncPipe(rename.rename(path, newName), utils.E.whenIsRight(utils.innerPipe(createFolderInterface, utils.E.success))); + return utils.asyncPipe(rename.rename(path, newName), EE__namespace.whenIsRight(utils.innerPipe(createFolderInterface, EE__namespace.success))); } function localRelocate(newParentPath) { - return utils.asyncPipe(relocate.relocate(path, newParentPath), utils.E.whenIsRight(utils.innerPipe(createFolderInterface, utils.E.success))); + return utils.asyncPipe(relocate.relocate(path, newParentPath), EE__namespace.whenIsRight(utils.innerPipe(createFolderInterface, EE__namespace.success))); } function localMove(newPath) { - return utils.asyncPipe(move.move(path, newPath), utils.E.whenIsRight(() => utils.E.success(createFolderInterface(newPath)))); + return utils.asyncPipe(move.move(path, newPath), EE__namespace.whenIsRight(() => EE__namespace.success(createFolderInterface(newPath)))); } function localExists() { return exists.exists(path); diff --git a/docs/libs/v0/file/folderInterface.d.ts b/docs/libs/v0/dist/file/folderInterface.d.ts similarity index 75% rename from docs/libs/v0/file/folderInterface.d.ts rename to docs/libs/v0/dist/file/folderInterface.d.ts index f2f1912..2bdc610 100644 --- a/docs/libs/v0/file/folderInterface.d.ts +++ b/docs/libs/v0/dist/file/folderInterface.d.ts @@ -1,4 +1,5 @@ -import { E, type Kind } from "@duplojs/utils"; +import { type Kind } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { type StatInfo } from "./stat"; import type { FileInterface } from "./fileInterface"; import type { UnknownInterface } from "./unknownInterface"; @@ -8,14 +9,14 @@ export interface FolderInterface extends Kind | E.Success>; - exists(): Promise | E.Ok>; - relocate(parentPath: string): Promise | E.Success>; - move(newPath: string): Promise | E.Success>; - remove(): Promise | E.Ok>; - getChildren(): Promise | E.Success>; - stat(): Promise | E.Success>; - walk(): Promise | E.Success>>; + rename(newName: string): Promise | EE.Success>; + exists(): Promise | EE.Ok>; + relocate(parentPath: string): Promise | EE.Success>; + move(newPath: string): Promise | EE.Success>; + remove(): Promise | EE.Ok>; + getChildren(): Promise | EE.Success>; + stat(): Promise | EE.Success>; + walk(): Promise | EE.Success>>; } /** * Create a folder interface with helper methods. diff --git a/docs/libs/v0/file/folderInterface.mjs b/docs/libs/v0/dist/file/folderInterface.mjs similarity index 78% rename from docs/libs/v0/file/folderInterface.mjs rename to docs/libs/v0/dist/file/folderInterface.mjs index 332c1c2..f5deb73 100644 --- a/docs/libs/v0/file/folderInterface.mjs +++ b/docs/libs/v0/dist/file/folderInterface.mjs @@ -1,4 +1,5 @@ -import { asyncPipe, E, innerPipe, Path } from '@duplojs/utils'; +import { asyncPipe, innerPipe, Path } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { createDuplojsServerUtilsKind } from '../kind.mjs'; import { move } from './move.mjs'; import { exists } from './exists.mjs'; @@ -21,13 +22,13 @@ function createFolderInterface(path) { return Path.getParentFolderPath(path); } function localRename(newName) { - return asyncPipe(rename(path, newName), E.whenIsRight(innerPipe(createFolderInterface, E.success))); + return asyncPipe(rename(path, newName), EE.whenIsRight(innerPipe(createFolderInterface, EE.success))); } function localRelocate(newParentPath) { - return asyncPipe(relocate(path, newParentPath), E.whenIsRight(innerPipe(createFolderInterface, E.success))); + return asyncPipe(relocate(path, newParentPath), EE.whenIsRight(innerPipe(createFolderInterface, EE.success))); } function localMove(newPath) { - return asyncPipe(move(path, newPath), E.whenIsRight(() => E.success(createFolderInterface(newPath)))); + return asyncPipe(move(path, newPath), EE.whenIsRight(() => EE.success(createFolderInterface(newPath)))); } function localExists() { return exists(path); diff --git a/docs/libs/v0/file/index.cjs b/docs/libs/v0/dist/file/index.cjs similarity index 100% rename from docs/libs/v0/file/index.cjs rename to docs/libs/v0/dist/file/index.cjs diff --git a/docs/libs/v0/file/index.d.ts b/docs/libs/v0/dist/file/index.d.ts similarity index 100% rename from docs/libs/v0/file/index.d.ts rename to docs/libs/v0/dist/file/index.d.ts diff --git a/docs/libs/v0/file/index.mjs b/docs/libs/v0/dist/file/index.mjs similarity index 100% rename from docs/libs/v0/file/index.mjs rename to docs/libs/v0/dist/file/index.mjs diff --git a/docs/libs/v0/dist/file/link.cjs b/docs/libs/v0/dist/file/link.cjs new file mode 100644 index 0000000..b07f58f --- /dev/null +++ b/docs/libs/v0/dist/file/link.cjs @@ -0,0 +1,41 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/link/index.md} + */ +const link = implementor.implementFunction("link", { + NODE: async (existingPath, newPath) => { + const fs = await implementor.nodeFileSystem.value; + return fs.link(existingPath, newPath) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-link", value)); + }, + DENO: (existingPath, newPath) => Deno + .link(existingPath, newPath) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-link", value)), +}); + +exports.link = link; diff --git a/docs/libs/v0/file/link.d.ts b/docs/libs/v0/dist/file/link.d.ts similarity index 83% rename from docs/libs/v0/file/link.d.ts rename to docs/libs/v0/dist/file/link.d.ts index b085550..1687a75 100644 --- a/docs/libs/v0/file/link.d.ts +++ b/docs/libs/v0/dist/file/link.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - link(existingPath: string, newPath: string): Promise | E.Ok>; + link(existingPath: string, newPath: string): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const link: (existingPath: string, newPath: string) => Promise | E.Ok>; +export declare const link: (existingPath: string, newPath: string) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/link.mjs b/docs/libs/v0/dist/file/link.mjs similarity index 64% rename from docs/libs/v0/file/link.mjs rename to docs/libs/v0/dist/file/link.mjs index 4df1911..df9aac5 100644 --- a/docs/libs/v0/file/link.mjs +++ b/docs/libs/v0/dist/file/link.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +8,13 @@ const link = implementFunction("link", { NODE: async (existingPath, newPath) => { const fs = await nodeFileSystem.value; return fs.link(existingPath, newPath) - .then(E.ok) - .catch((value) => E.left("file-system-link", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-link", value)); }, DENO: (existingPath, newPath) => Deno .link(existingPath, newPath) - .then(E.ok) - .catch((value) => E.left("file-system-link", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-link", value)), }); export { link }; diff --git a/docs/libs/v0/dist/file/linkStat.cjs b/docs/libs/v0/dist/file/linkStat.cjs new file mode 100644 index 0000000..c54cd5b --- /dev/null +++ b/docs/libs/v0/dist/file/linkStat.cjs @@ -0,0 +1,106 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var DD = require('@duplojs/utils/date'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var DD__namespace = /*#__PURE__*/_interopNamespaceDefault(DD); + +function createStatInfoWithFsSource(source) { + return { + isFile: source.isFile(), + isDirectory: source.isDirectory(), + isSymlink: source.isSymbolicLink(), + sizeBytes: source.size, + modifiedAt: DD__namespace.isSafeTimestamp(source.mtime.getTime()) ? DD__namespace.createOrThrow(source.mtime) : null, + accessedAt: DD__namespace.isSafeTimestamp(source.atime.getTime()) ? DD__namespace.createOrThrow(source.atime) : null, + createdAt: DD__namespace.isSafeTimestamp(source.birthtime.getTime()) ? DD__namespace.createOrThrow(source.birthtime) : null, + changedAt: DD__namespace.isSafeTimestamp(source.ctime.getTime()) ? DD__namespace.createOrThrow(source.ctime) : null, + deviceId: source.dev, + inode: source.ino, + permissionsMode: source.mode, + hardLinkCount: source.nlink, + ownerUserId: source.uid, + ownerGroupId: source.gid, + specialDeviceId: source.rdev, + ioBlockSize: source.blksize, + allocatedBlockCount: source.blocks, + isBlockDevice: source.isBlockDevice(), + isCharacterDevice: source.isCharacterDevice(), + isFifo: source.isFIFO(), + isSocket: source.isSocket(), + }; +} +function createStatInfoWithDeno(source) { + return { + isFile: source.isFile, + isDirectory: source.isDirectory, + isSymlink: source.isSymlink, + sizeBytes: source.size, + modifiedAt: source.mtime + && DD__namespace.isSafeTimestamp(source.mtime.getTime()) + ? DD__namespace.createOrThrow(source.mtime) + : null, + accessedAt: source.atime + && DD__namespace.isSafeTimestamp(source.atime.getTime()) + ? DD__namespace.createOrThrow(source.atime) + : null, + createdAt: source.birthtime + && DD__namespace.isSafeTimestamp(source.birthtime.getTime()) + ? DD__namespace.createOrThrow(source.birthtime) + : null, + changedAt: source.ctime + && DD__namespace.isSafeTimestamp(source.ctime.getTime()) + ? DD__namespace.createOrThrow(source.ctime) + : null, + deviceId: source.dev, + inode: source.ino, + permissionsMode: source.mode, + hardLinkCount: source.nlink, + ownerUserId: source.uid, + ownerGroupId: source.gid, + specialDeviceId: source.rdev, + ioBlockSize: source.blksize, + allocatedBlockCount: source.blocks, + isBlockDevice: source.isBlockDevice, + isCharacterDevice: source.isCharDevice, + isFifo: source.isFifo, + isSocket: source.isSocket, + }; +} +/** + * {@include file/linkStat/index.md} + */ +const linkStat = implementor.implementFunction("linkStat", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.lstat(path) + .then(utils.innerPipe(createStatInfoWithFsSource, EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-link-stat", value)); + }, + DENO: (path) => Deno + .lstat(path) + .then(utils.innerPipe(createStatInfoWithDeno, EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-link-stat", value)), +}); + +exports.linkStat = linkStat; diff --git a/docs/libs/v0/file/linkStat.d.ts b/docs/libs/v0/dist/file/linkStat.d.ts similarity index 78% rename from docs/libs/v0/file/linkStat.d.ts rename to docs/libs/v0/dist/file/linkStat.d.ts index 9f4c3ce..e8c1a71 100644 --- a/docs/libs/v0/file/linkStat.d.ts +++ b/docs/libs/v0/dist/file/linkStat.d.ts @@ -1,9 +1,9 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { StatInfo } from "./stat"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - linkStat(path: GenericPath): Promise | E.Success>; + linkStat(path: GenericPath): Promise | EE.Success>; } } /** @@ -22,4 +22,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const linkStat: (path: GenericPath) => Promise | E.Success>; +export declare const linkStat: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/linkStat.mjs b/docs/libs/v0/dist/file/linkStat.mjs similarity index 61% rename from docs/libs/v0/file/linkStat.mjs rename to docs/libs/v0/dist/file/linkStat.mjs index 80e24ee..1163e2a 100644 --- a/docs/libs/v0/file/linkStat.mjs +++ b/docs/libs/v0/dist/file/linkStat.mjs @@ -1,4 +1,6 @@ -import { innerPipe, E, D } from '@duplojs/utils'; +import { innerPipe } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; +import * as DD from '@duplojs/utils/date'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; function createStatInfoWithFsSource(source) { @@ -7,10 +9,10 @@ function createStatInfoWithFsSource(source) { isDirectory: source.isDirectory(), isSymlink: source.isSymbolicLink(), sizeBytes: source.size, - modifiedAt: D.isSafeTimestamp(source.mtime.getTime()) ? D.createOrThrow(source.mtime) : null, - accessedAt: D.isSafeTimestamp(source.atime.getTime()) ? D.createOrThrow(source.atime) : null, - createdAt: D.isSafeTimestamp(source.birthtime.getTime()) ? D.createOrThrow(source.birthtime) : null, - changedAt: D.isSafeTimestamp(source.ctime.getTime()) ? D.createOrThrow(source.ctime) : null, + modifiedAt: DD.isSafeTimestamp(source.mtime.getTime()) ? DD.createOrThrow(source.mtime) : null, + accessedAt: DD.isSafeTimestamp(source.atime.getTime()) ? DD.createOrThrow(source.atime) : null, + createdAt: DD.isSafeTimestamp(source.birthtime.getTime()) ? DD.createOrThrow(source.birthtime) : null, + changedAt: DD.isSafeTimestamp(source.ctime.getTime()) ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, permissionsMode: source.mode, @@ -33,20 +35,20 @@ function createStatInfoWithDeno(source) { isSymlink: source.isSymlink, sizeBytes: source.size, modifiedAt: source.mtime - && D.isSafeTimestamp(source.mtime.getTime()) - ? D.createOrThrow(source.mtime) + && DD.isSafeTimestamp(source.mtime.getTime()) + ? DD.createOrThrow(source.mtime) : null, accessedAt: source.atime - && D.isSafeTimestamp(source.atime.getTime()) - ? D.createOrThrow(source.atime) + && DD.isSafeTimestamp(source.atime.getTime()) + ? DD.createOrThrow(source.atime) : null, createdAt: source.birthtime - && D.isSafeTimestamp(source.birthtime.getTime()) - ? D.createOrThrow(source.birthtime) + && DD.isSafeTimestamp(source.birthtime.getTime()) + ? DD.createOrThrow(source.birthtime) : null, changedAt: source.ctime - && D.isSafeTimestamp(source.ctime.getTime()) - ? D.createOrThrow(source.ctime) + && DD.isSafeTimestamp(source.ctime.getTime()) + ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, @@ -70,13 +72,13 @@ const linkStat = implementFunction("linkStat", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.lstat(path) - .then(innerPipe(createStatInfoWithFsSource, E.success)) - .catch((value) => E.left("file-system-link-stat", value)); + .then(innerPipe(createStatInfoWithFsSource, EE.success)) + .catch((value) => EE.left("file-system-link-stat", value)); }, DENO: (path) => Deno .lstat(path) - .then(innerPipe(createStatInfoWithDeno, E.success)) - .catch((value) => E.left("file-system-link-stat", value)), + .then(innerPipe(createStatInfoWithDeno, EE.success)) + .catch((value) => EE.left("file-system-link-stat", value)), }); export { linkStat }; diff --git a/docs/libs/v0/dist/file/makeDirectory.cjs b/docs/libs/v0/dist/file/makeDirectory.cjs new file mode 100644 index 0000000..b1055d5 --- /dev/null +++ b/docs/libs/v0/dist/file/makeDirectory.cjs @@ -0,0 +1,44 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/makeDirectory/index.md} + */ +const makeDirectory = implementor.implementFunction("makeDirectory", { + NODE: async (path, params) => { + const fs = await implementor.nodeFileSystem.value; + return fs.mkdir(path, { + recursive: params?.recursive, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-make-directory", value)); + }, + DENO: (path, params) => Deno.mkdir(path, { + recursive: params?.recursive, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-make-directory", value)), +}); + +exports.makeDirectory = makeDirectory; diff --git a/docs/libs/v0/file/makeDirectory.d.ts b/docs/libs/v0/dist/file/makeDirectory.d.ts similarity index 88% rename from docs/libs/v0/file/makeDirectory.d.ts rename to docs/libs/v0/dist/file/makeDirectory.d.ts index a22dccb..ff75cd9 100644 --- a/docs/libs/v0/file/makeDirectory.d.ts +++ b/docs/libs/v0/dist/file/makeDirectory.d.ts @@ -1,11 +1,11 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface MakeDirectoryParams { recursive?: boolean; } declare module "../implementor" { interface ServerUtilsFunction { - makeDirectory(path: GenericPath, params?: MakeDirectoryParams): Promise | E.Ok>; + makeDirectory(path: GenericPath, params?: MakeDirectoryParams): Promise | EE.Ok>; } } /** @@ -24,5 +24,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const makeDirectory: (path: GenericPath, params?: MakeDirectoryParams) => Promise | E.Ok>; +export declare const makeDirectory: (path: GenericPath, params?: MakeDirectoryParams) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/file/makeDirectory.mjs b/docs/libs/v0/dist/file/makeDirectory.mjs similarity index 66% rename from docs/libs/v0/file/makeDirectory.mjs rename to docs/libs/v0/dist/file/makeDirectory.mjs index 73a331e..8c5bff6 100644 --- a/docs/libs/v0/file/makeDirectory.mjs +++ b/docs/libs/v0/dist/file/makeDirectory.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -10,14 +10,14 @@ const makeDirectory = implementFunction("makeDirectory", { return fs.mkdir(path, { recursive: params?.recursive, }) - .then(E.ok) - .catch((value) => E.left("file-system-make-directory", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-make-directory", value)); }, DENO: (path, params) => Deno.mkdir(path, { recursive: params?.recursive, }) - .then(E.ok) - .catch((value) => E.left("file-system-make-directory", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-make-directory", value)), }); export { makeDirectory }; diff --git a/docs/libs/v0/dist/file/makeTemporaryDirectory.cjs b/docs/libs/v0/dist/file/makeTemporaryDirectory.cjs new file mode 100644 index 0000000..f2804ff --- /dev/null +++ b/docs/libs/v0/dist/file/makeTemporaryDirectory.cjs @@ -0,0 +1,40 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/makeTemporaryDirectory/index.md} + */ +const makeTemporaryDirectory = implementor.implementFunction("makeTemporaryDirectory", { + NODE: async (prefix) => { + const fs = await implementor.nodeFileSystem.value; + return fs.mkdtemp(prefix) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-make-temporary-directory", value)); + }, + DENO: (prefix) => Deno.makeTempDir({ prefix }) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-make-temporary-directory", value)), +}); + +exports.makeTemporaryDirectory = makeTemporaryDirectory; diff --git a/docs/libs/v0/file/makeTemporaryDirectory.d.ts b/docs/libs/v0/dist/file/makeTemporaryDirectory.d.ts similarity index 79% rename from docs/libs/v0/file/makeTemporaryDirectory.d.ts rename to docs/libs/v0/dist/file/makeTemporaryDirectory.d.ts index ea21d7d..4445018 100644 --- a/docs/libs/v0/file/makeTemporaryDirectory.d.ts +++ b/docs/libs/v0/dist/file/makeTemporaryDirectory.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - makeTemporaryDirectory(prefix: string): Promise | E.Success>; + makeTemporaryDirectory(prefix: string): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const makeTemporaryDirectory: (prefix: string) => Promise | E.Success>; +export declare const makeTemporaryDirectory: (prefix: string) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/makeTemporaryDirectory.mjs b/docs/libs/v0/dist/file/makeTemporaryDirectory.mjs similarity index 60% rename from docs/libs/v0/file/makeTemporaryDirectory.mjs rename to docs/libs/v0/dist/file/makeTemporaryDirectory.mjs index 327f69a..ec41f54 100644 --- a/docs/libs/v0/file/makeTemporaryDirectory.mjs +++ b/docs/libs/v0/dist/file/makeTemporaryDirectory.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,12 +8,12 @@ const makeTemporaryDirectory = implementFunction("makeTemporaryDirectory", { NODE: async (prefix) => { const fs = await nodeFileSystem.value; return fs.mkdtemp(prefix) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-directory", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-directory", value)); }, DENO: (prefix) => Deno.makeTempDir({ prefix }) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-directory", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-directory", value)), }); export { makeTemporaryDirectory }; diff --git a/docs/libs/v0/dist/file/makeTemporaryFile.cjs b/docs/libs/v0/dist/file/makeTemporaryFile.cjs new file mode 100644 index 0000000..37a0655 --- /dev/null +++ b/docs/libs/v0/dist/file/makeTemporaryFile.cjs @@ -0,0 +1,51 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/makeTemporaryFile/index.md} + */ +const makeTemporaryFile = implementor.implementFunction("makeTemporaryFile", { + NODE: async (prefix, suffix) => { + const fs = await implementor.nodeFileSystem.value; + const os = await implementor.nodeOs.value; + const crypto = await implementor.nodeCrypto.value; + const fileTemporaryPath = utils.Path.resolveRelative([ + os.tmpdir(), + `${prefix}${crypto.randomUUID()}${suffix ?? ""}`, + ]); + return fs.open(fileTemporaryPath, "wx") + .then((fh) => fh.close()) + .then(() => EE__namespace.success(fileTemporaryPath)) + .catch((value) => EE__namespace.left("file-system-make-temporary-file", value)); + }, + DENO: (prefix, suffix) => Deno.makeTempFile({ + prefix, + suffix, + }) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-make-temporary-file", value)), +}); + +exports.makeTemporaryFile = makeTemporaryFile; diff --git a/docs/libs/v0/file/makeTemporaryFile.d.ts b/docs/libs/v0/dist/file/makeTemporaryFile.d.ts similarity index 78% rename from docs/libs/v0/file/makeTemporaryFile.d.ts rename to docs/libs/v0/dist/file/makeTemporaryFile.d.ts index 3e47231..2fdfd69 100644 --- a/docs/libs/v0/file/makeTemporaryFile.d.ts +++ b/docs/libs/v0/dist/file/makeTemporaryFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - makeTemporaryFile(prefix: string, suffix?: string): Promise | E.Success>; + makeTemporaryFile(prefix: string, suffix?: string): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const makeTemporaryFile: (prefix: string, suffix?: string) => Promise | E.Success>; +export declare const makeTemporaryFile: (prefix: string, suffix?: string) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/makeTemporaryFile.mjs b/docs/libs/v0/dist/file/makeTemporaryFile.mjs similarity index 69% rename from docs/libs/v0/file/makeTemporaryFile.mjs rename to docs/libs/v0/dist/file/makeTemporaryFile.mjs index 98a3927..a213fd9 100644 --- a/docs/libs/v0/file/makeTemporaryFile.mjs +++ b/docs/libs/v0/dist/file/makeTemporaryFile.mjs @@ -1,4 +1,5 @@ -import { E, Path } from '@duplojs/utils'; +import { Path } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem, nodeOs, nodeCrypto } from '../implementor.mjs'; /** @@ -15,15 +16,15 @@ const makeTemporaryFile = implementFunction("makeTemporaryFile", { ]); return fs.open(fileTemporaryPath, "wx") .then((fh) => fh.close()) - .then(() => E.success(fileTemporaryPath)) - .catch((value) => E.left("file-system-make-temporary-file", value)); + .then(() => EE.success(fileTemporaryPath)) + .catch((value) => EE.left("file-system-make-temporary-file", value)); }, DENO: (prefix, suffix) => Deno.makeTempFile({ prefix, suffix, }) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-file", value)), }); export { makeTemporaryFile }; diff --git a/docs/libs/v0/dist/file/move.cjs b/docs/libs/v0/dist/file/move.cjs new file mode 100644 index 0000000..9c31f82 --- /dev/null +++ b/docs/libs/v0/dist/file/move.cjs @@ -0,0 +1,40 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/move/index.md} + */ +const move = implementor.implementFunction("move", { + NODE: async (fromPath, toPath) => { + const fs = await implementor.nodeFileSystem.value; + return fs.rename(fromPath, toPath) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-move", value)); + }, + DENO: (fromPath, toPath) => Deno.rename(fromPath, toPath) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-move", value)), +}); + +exports.move = move; diff --git a/docs/libs/v0/file/move.d.ts b/docs/libs/v0/dist/file/move.d.ts similarity index 84% rename from docs/libs/v0/file/move.d.ts rename to docs/libs/v0/dist/file/move.d.ts index 654f0a7..118aaeb 100644 --- a/docs/libs/v0/file/move.d.ts +++ b/docs/libs/v0/dist/file/move.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - move(fromPath: string, toPath: string): Promise | E.Ok>; + move(fromPath: string, toPath: string): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const move: (fromPath: string, toPath: string) => Promise | E.Ok>; +export declare const move: (fromPath: string, toPath: string) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/move.mjs b/docs/libs/v0/dist/file/move.mjs similarity index 62% rename from docs/libs/v0/file/move.mjs rename to docs/libs/v0/dist/file/move.mjs index 5a4dda6..771988f 100644 --- a/docs/libs/v0/file/move.mjs +++ b/docs/libs/v0/dist/file/move.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,12 +8,12 @@ const move = implementFunction("move", { NODE: async (fromPath, toPath) => { const fs = await nodeFileSystem.value; return fs.rename(fromPath, toPath) - .then(E.ok) - .catch((value) => E.left("file-system-move", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-move", value)); }, DENO: (fromPath, toPath) => Deno.rename(fromPath, toPath) - .then(E.ok) - .catch((value) => E.left("file-system-move", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-move", value)), }); export { move }; diff --git a/docs/libs/v0/dist/file/readDirectory.cjs b/docs/libs/v0/dist/file/readDirectory.cjs new file mode 100644 index 0000000..6d868f5 --- /dev/null +++ b/docs/libs/v0/dist/file/readDirectory.cjs @@ -0,0 +1,37 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/readDirectory/index.md} + */ +const readDirectory = implementor.implementFunction("readDirectory", { + NODE: async (path, params) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readdir(path, { recursive: params?.recursive }) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-directory", value)); + }, +}); + +exports.readDirectory = readDirectory; diff --git a/docs/libs/v0/file/readDirectory.d.ts b/docs/libs/v0/dist/file/readDirectory.d.ts similarity index 86% rename from docs/libs/v0/file/readDirectory.d.ts rename to docs/libs/v0/dist/file/readDirectory.d.ts index 7d06c2e..76c7a5a 100644 --- a/docs/libs/v0/file/readDirectory.d.ts +++ b/docs/libs/v0/dist/file/readDirectory.d.ts @@ -1,11 +1,11 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface ReadDirectoryParams { recursive?: boolean; } declare module "../implementor" { interface ServerUtilsFunction { - readDirectory(path: GenericPath, params?: ReadDirectoryParams): Promise | E.Success>; + readDirectory(path: GenericPath, params?: ReadDirectoryParams): Promise | EE.Success>; } } /** @@ -24,5 +24,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const readDirectory: (path: GenericPath, params?: ReadDirectoryParams) => Promise | E.Success>; +export declare const readDirectory: (path: GenericPath, params?: ReadDirectoryParams) => Promise | EE.Success>; export {}; diff --git a/docs/libs/v0/file/readDirectory.mjs b/docs/libs/v0/dist/file/readDirectory.mjs similarity index 70% rename from docs/libs/v0/file/readDirectory.mjs rename to docs/libs/v0/dist/file/readDirectory.mjs index 71e6fee..e6848c6 100644 --- a/docs/libs/v0/file/readDirectory.mjs +++ b/docs/libs/v0/dist/file/readDirectory.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,8 +8,8 @@ const readDirectory = implementFunction("readDirectory", { NODE: async (path, params) => { const fs = await nodeFileSystem.value; return fs.readdir(path, { recursive: params?.recursive }) - .then(E.success) - .catch((value) => E.left("file-system-read-directory", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-directory", value)); }, }); diff --git a/docs/libs/v0/dist/file/readFile.cjs b/docs/libs/v0/dist/file/readFile.cjs new file mode 100644 index 0000000..95378d2 --- /dev/null +++ b/docs/libs/v0/dist/file/readFile.cjs @@ -0,0 +1,45 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/readFile/index.md} + */ +const readFile = implementor.implementFunction("readFile", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readFile(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-file", value)); + }, + DENO: (path) => Deno + .readFile(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-file", value)), + BUN: (path) => Bun.file(path) + .bytes() + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-file", value)), +}); + +exports.readFile = readFile; diff --git a/docs/libs/v0/file/readFile.d.ts b/docs/libs/v0/dist/file/readFile.d.ts similarity index 77% rename from docs/libs/v0/file/readFile.d.ts rename to docs/libs/v0/dist/file/readFile.d.ts index 84ef0cc..64f904f 100644 --- a/docs/libs/v0/file/readFile.d.ts +++ b/docs/libs/v0/dist/file/readFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - readFile(path: GenericPath): Promise | E.Success>; + readFile(path: GenericPath): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const readFile: (path: GenericPath) => Promise | E.Success>; +export declare const readFile: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/readFile.mjs b/docs/libs/v0/dist/file/readFile.mjs similarity index 54% rename from docs/libs/v0/file/readFile.mjs rename to docs/libs/v0/dist/file/readFile.mjs index 9998b3a..8b31966 100644 --- a/docs/libs/v0/file/readFile.mjs +++ b/docs/libs/v0/dist/file/readFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,17 +8,17 @@ const readFile = implementFunction("readFile", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.readFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)); }, DENO: (path) => Deno .readFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)), BUN: (path) => Bun.file(path) .bytes() - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)), }); export { readFile }; diff --git a/docs/libs/v0/dist/file/readJsonFile.cjs b/docs/libs/v0/dist/file/readJsonFile.cjs new file mode 100644 index 0000000..1f79b86 --- /dev/null +++ b/docs/libs/v0/dist/file/readJsonFile.cjs @@ -0,0 +1,47 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/readJsonFile/index.md} + */ +const readJsonFile = implementor.implementFunction("readJsonFile", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readFile(path, { encoding: "utf-8" }) + .then(JSON.parse) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-json-file", value)); + }, + DENO: (path) => Deno.readTextFile(path) + .then(JSON.parse) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-json-file", value)), + BUN: (path) => Bun.file(path) + .text() + .then(JSON.parse) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-json-file", value)), +}); + +exports.readJsonFile = readJsonFile; diff --git a/docs/libs/v0/file/readJsonFile.d.ts b/docs/libs/v0/dist/file/readJsonFile.d.ts similarity index 82% rename from docs/libs/v0/file/readJsonFile.d.ts rename to docs/libs/v0/dist/file/readJsonFile.d.ts index 4da8a74..2500960 100644 --- a/docs/libs/v0/file/readJsonFile.d.ts +++ b/docs/libs/v0/dist/file/readJsonFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - readJsonFile(path: GenericPath): Promise | E.Success>; + readJsonFile(path: GenericPath): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const readJsonFile: (path: GenericPath) => Promise | E.Success>; +export declare const readJsonFile: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/readJsonFile.mjs b/docs/libs/v0/dist/file/readJsonFile.mjs similarity index 59% rename from docs/libs/v0/file/readJsonFile.mjs rename to docs/libs/v0/dist/file/readJsonFile.mjs index 05b3b5e..8adc4f4 100644 --- a/docs/libs/v0/file/readJsonFile.mjs +++ b/docs/libs/v0/dist/file/readJsonFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -9,18 +9,18 @@ const readJsonFile = implementFunction("readJsonFile", { const fs = await nodeFileSystem.value; return fs.readFile(path, { encoding: "utf-8" }) .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)); }, DENO: (path) => Deno.readTextFile(path) .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)), BUN: (path) => Bun.file(path) .text() .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)), }); export { readJsonFile }; diff --git a/docs/libs/v0/dist/file/readLink.cjs b/docs/libs/v0/dist/file/readLink.cjs new file mode 100644 index 0000000..3f91d1a --- /dev/null +++ b/docs/libs/v0/dist/file/readLink.cjs @@ -0,0 +1,41 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/readLink/index.md} + */ +const readLink = implementor.implementFunction("readLink", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readlink(path, { encoding: "utf-8" }) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-link", value)); + }, + DENO: (path) => Deno + .readLink(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-link", value)), +}); + +exports.readLink = readLink; diff --git a/docs/libs/v0/file/readLink.d.ts b/docs/libs/v0/dist/file/readLink.d.ts similarity index 77% rename from docs/libs/v0/file/readLink.d.ts rename to docs/libs/v0/dist/file/readLink.d.ts index 1804b72..aac8fce 100644 --- a/docs/libs/v0/file/readLink.d.ts +++ b/docs/libs/v0/dist/file/readLink.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - readLink(path: GenericPath): Promise | E.Success>; + readLink(path: GenericPath): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const readLink: (path: GenericPath) => Promise | E.Success>; +export declare const readLink: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/readLink.mjs b/docs/libs/v0/dist/file/readLink.mjs similarity index 61% rename from docs/libs/v0/file/readLink.mjs rename to docs/libs/v0/dist/file/readLink.mjs index 9a33f39..ee9a52f 100644 --- a/docs/libs/v0/file/readLink.mjs +++ b/docs/libs/v0/dist/file/readLink.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +8,13 @@ const readLink = implementFunction("readLink", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.readlink(path, { encoding: "utf-8" }) - .then(E.success) - .catch((value) => E.left("file-system-read-link", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-link", value)); }, DENO: (path) => Deno .readLink(path) - .then(E.success) - .catch((value) => E.left("file-system-read-link", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-link", value)), }); export { readLink }; diff --git a/docs/libs/v0/dist/file/readTextFile.cjs b/docs/libs/v0/dist/file/readTextFile.cjs new file mode 100644 index 0000000..2145798 --- /dev/null +++ b/docs/libs/v0/dist/file/readTextFile.cjs @@ -0,0 +1,45 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/readTextFile/index.md} + */ +const readTextFile = implementor.implementFunction("readTextFile", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readFile(path, { encoding: "utf-8" }) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-text-file", value)); + }, + DENO: (path) => Deno + .readTextFile(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-text-file", value)), + BUN: (path) => Bun.file(path) + .text() + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-read-text-file", value)), +}); + +exports.readTextFile = readTextFile; diff --git a/docs/libs/v0/file/readTextFile.d.ts b/docs/libs/v0/dist/file/readTextFile.d.ts similarity index 84% rename from docs/libs/v0/file/readTextFile.d.ts rename to docs/libs/v0/dist/file/readTextFile.d.ts index aa8b48f..59d54cf 100644 --- a/docs/libs/v0/file/readTextFile.d.ts +++ b/docs/libs/v0/dist/file/readTextFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - readTextFile(path: GenericPath): Promise | E.Success>; + readTextFile(path: GenericPath): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const readTextFile: (path: GenericPath) => Promise | E.Success>; +export declare const readTextFile: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/readTextFile.mjs b/docs/libs/v0/dist/file/readTextFile.mjs similarity index 56% rename from docs/libs/v0/file/readTextFile.mjs rename to docs/libs/v0/dist/file/readTextFile.mjs index 239b84b..c6d5be2 100644 --- a/docs/libs/v0/file/readTextFile.mjs +++ b/docs/libs/v0/dist/file/readTextFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,17 +8,17 @@ const readTextFile = implementFunction("readTextFile", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.readFile(path, { encoding: "utf-8" }) - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)); }, DENO: (path) => Deno .readTextFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)), BUN: (path) => Bun.file(path) .text() - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)), }); export { readTextFile }; diff --git a/docs/libs/v0/dist/file/realPath.cjs b/docs/libs/v0/dist/file/realPath.cjs new file mode 100644 index 0000000..5cdb609 --- /dev/null +++ b/docs/libs/v0/dist/file/realPath.cjs @@ -0,0 +1,41 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/realPath/index.md} + */ +const realPath = implementor.implementFunction("realPath", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.realpath(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-real-path", value)); + }, + DENO: (path) => Deno + .realPath(path) + .then(EE__namespace.success) + .catch((value) => EE__namespace.left("file-system-real-path", value)), +}); + +exports.realPath = realPath; diff --git a/docs/libs/v0/file/realPath.d.ts b/docs/libs/v0/dist/file/realPath.d.ts similarity index 78% rename from docs/libs/v0/file/realPath.d.ts rename to docs/libs/v0/dist/file/realPath.d.ts index 765acfc..f668abf 100644 --- a/docs/libs/v0/file/realPath.d.ts +++ b/docs/libs/v0/dist/file/realPath.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - realPath(path: GenericPath): Promise | E.Success>; + realPath(path: GenericPath): Promise | EE.Success>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const realPath: (path: GenericPath) => Promise | E.Success>; +export declare const realPath: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/realPath.mjs b/docs/libs/v0/dist/file/realPath.mjs similarity index 59% rename from docs/libs/v0/file/realPath.mjs rename to docs/libs/v0/dist/file/realPath.mjs index db257b6..e46ea63 100644 --- a/docs/libs/v0/file/realPath.mjs +++ b/docs/libs/v0/dist/file/realPath.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +8,13 @@ const realPath = implementFunction("realPath", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.realpath(path) - .then(E.success) - .catch((value) => E.left("file-system-real-path", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-real-path", value)); }, DENO: (path) => Deno .realPath(path) - .then(E.success) - .catch((value) => E.left("file-system-real-path", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-real-path", value)), }); export { realPath }; diff --git a/docs/libs/v0/dist/file/relocate.cjs b/docs/libs/v0/dist/file/relocate.cjs new file mode 100644 index 0000000..7878813 --- /dev/null +++ b/docs/libs/v0/dist/file/relocate.cjs @@ -0,0 +1,53 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/relocate/index.md} + */ +const relocate = implementor.implementFunction("relocate", { + NODE: async (fromPath, newParentPath) => { + const fs = await implementor.nodeFileSystem.value; + const baseName = utils.Path.getBaseName(fromPath); + if (!baseName) { + return EE__namespace.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); + } + const newPath = utils.Path.resolveRelative([newParentPath, baseName]); + return fs.rename(fromPath, newPath) + .then(() => EE__namespace.success(newPath)) + .catch((value) => EE__namespace.left("file-system-relocate", value)); + }, + DENO: (fromPath, newParentPath) => { + const baseName = utils.Path.getBaseName(fromPath); + if (!baseName) { + return Promise.resolve(EE__namespace.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); + } + const newPath = utils.Path.resolveRelative([newParentPath, baseName]); + return Deno.rename(fromPath, newPath) + .then(() => EE__namespace.success(newPath)) + .catch((value) => EE__namespace.left("file-system-relocate", value)); + }, +}); + +exports.relocate = relocate; diff --git a/docs/libs/v0/file/relocate.d.ts b/docs/libs/v0/dist/file/relocate.d.ts similarity index 86% rename from docs/libs/v0/file/relocate.d.ts rename to docs/libs/v0/dist/file/relocate.d.ts index a0c8524..77c0f45 100644 --- a/docs/libs/v0/file/relocate.d.ts +++ b/docs/libs/v0/dist/file/relocate.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - relocate(fromPath: string, toPath: string): Promise | E.Success>; + relocate(fromPath: string, toPath: string): Promise | EE.Success>; } } /** @@ -31,4 +31,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const relocate: (fromPath: string, toPath: string) => Promise | E.Success>; +export declare const relocate: (fromPath: string, toPath: string) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/relocate.mjs b/docs/libs/v0/dist/file/relocate.mjs similarity index 58% rename from docs/libs/v0/file/relocate.mjs rename to docs/libs/v0/dist/file/relocate.mjs index bdb72b2..8586a9f 100644 --- a/docs/libs/v0/file/relocate.mjs +++ b/docs/libs/v0/dist/file/relocate.mjs @@ -1,4 +1,5 @@ -import { Path, E } from '@duplojs/utils'; +import { Path } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -9,22 +10,22 @@ const relocate = implementFunction("relocate", { const fs = await nodeFileSystem.value; const baseName = Path.getBaseName(fromPath); if (!baseName) { - return E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); + return EE.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); } const newPath = Path.resolveRelative([newParentPath, baseName]); return fs.rename(fromPath, newPath) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-relocate", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-relocate", value)); }, DENO: (fromPath, newParentPath) => { const baseName = Path.getBaseName(fromPath); if (!baseName) { - return Promise.resolve(E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); + return Promise.resolve(EE.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); } const newPath = Path.resolveRelative([newParentPath, baseName]); return Deno.rename(fromPath, newPath) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-relocate", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-relocate", value)); }, }); diff --git a/docs/libs/v0/dist/file/remove.cjs b/docs/libs/v0/dist/file/remove.cjs new file mode 100644 index 0000000..38c3bb7 --- /dev/null +++ b/docs/libs/v0/dist/file/remove.cjs @@ -0,0 +1,45 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/remove/index.md} + */ +const remove = implementor.implementFunction("remove", { + NODE: async (path, params) => { + const fs = await implementor.nodeFileSystem.value; + return fs.rm(path, { + recursive: params?.recursive ?? false, + force: true, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-remove", value)); + }, + DENO: (path, params) => Deno.remove(path, { + recursive: params?.recursive, + }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-remove", value)), +}); + +exports.remove = remove; diff --git a/docs/libs/v0/file/remove.d.ts b/docs/libs/v0/dist/file/remove.d.ts similarity index 91% rename from docs/libs/v0/file/remove.d.ts rename to docs/libs/v0/dist/file/remove.d.ts index 6829c8d..685566b 100644 --- a/docs/libs/v0/file/remove.d.ts +++ b/docs/libs/v0/dist/file/remove.d.ts @@ -1,11 +1,11 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface RemoveDirectoryParams { recursive?: boolean; } declare module "../implementor" { interface ServerUtilsFunction { - remove(path: GenericPath, params?: RemoveDirectoryParams): Promise | E.Ok>; + remove(path: GenericPath, params?: RemoveDirectoryParams): Promise | EE.Ok>; } } /** @@ -24,5 +24,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const remove: (path: GenericPath, params?: RemoveDirectoryParams) => Promise | E.Ok>; +export declare const remove: (path: GenericPath, params?: RemoveDirectoryParams) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/file/remove.mjs b/docs/libs/v0/dist/file/remove.mjs similarity index 68% rename from docs/libs/v0/file/remove.mjs rename to docs/libs/v0/dist/file/remove.mjs index fd39353..4028b58 100644 --- a/docs/libs/v0/file/remove.mjs +++ b/docs/libs/v0/dist/file/remove.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -11,14 +11,14 @@ const remove = implementFunction("remove", { recursive: params?.recursive ?? false, force: true, }) - .then(E.ok) - .catch((value) => E.left("file-system-remove", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-remove", value)); }, DENO: (path, params) => Deno.remove(path, { recursive: params?.recursive, }) - .then(E.ok) - .catch((value) => E.left("file-system-remove", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-remove", value)), }); export { remove }; diff --git a/docs/libs/v0/dist/file/rename.cjs b/docs/libs/v0/dist/file/rename.cjs new file mode 100644 index 0000000..3d9fec9 --- /dev/null +++ b/docs/libs/v0/dist/file/rename.cjs @@ -0,0 +1,59 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/rename/index.md} + */ +const rename = implementor.implementFunction("rename", { + NODE: async (path, newName) => { + const fs = await implementor.nodeFileSystem.value; + const parentPath = utils.Path.getParentFolderPath(path); + if (!parentPath) { + return EE__namespace.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); + } + if (newName.includes("/")) { + return EE__namespace.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); + } + const newPath = utils.Path.resolveRelative([parentPath, newName]); + return fs.rename(path, newPath) + .then(() => EE__namespace.success(newPath)) + .catch((value) => EE__namespace.left("file-system-rename", value)); + }, + DENO: (path, newName) => { + const parentPath = utils.Path.getParentFolderPath(path); + if (!parentPath) { + return Promise.resolve(EE__namespace.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); + } + if (newName.includes("/")) { + return Promise.resolve(EE__namespace.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); + } + const newPath = utils.Path.resolveRelative([parentPath, newName]); + return Deno.rename(path, newPath) + .then(() => EE__namespace.success(newPath)) + .catch((value) => EE__namespace.left("file-system-rename", value)); + }, +}); + +exports.rename = rename; diff --git a/docs/libs/v0/file/rename.d.ts b/docs/libs/v0/dist/file/rename.d.ts similarity index 85% rename from docs/libs/v0/file/rename.d.ts rename to docs/libs/v0/dist/file/rename.d.ts index 512b49b..ac08853 100644 --- a/docs/libs/v0/file/rename.d.ts +++ b/docs/libs/v0/dist/file/rename.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - rename(path: string, newName: string): Promise | E.Success>; + rename(path: string, newName: string): Promise | EE.Success>; } } /** @@ -26,4 +26,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const rename: (path: string, newName: string) => Promise | E.Success>; +export declare const rename: (path: string, newName: string) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/rename.mjs b/docs/libs/v0/dist/file/rename.mjs similarity index 52% rename from docs/libs/v0/file/rename.mjs rename to docs/libs/v0/dist/file/rename.mjs index 35b23c3..b64a284 100644 --- a/docs/libs/v0/file/rename.mjs +++ b/docs/libs/v0/dist/file/rename.mjs @@ -1,4 +1,5 @@ -import { Path, E } from '@duplojs/utils'; +import { Path } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -9,28 +10,28 @@ const rename = implementFunction("rename", { const fs = await nodeFileSystem.value; const parentPath = Path.getParentFolderPath(path); if (!parentPath) { - return E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); + return EE.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); } if (newName.includes("/")) { - return E.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); + return EE.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); } const newPath = Path.resolveRelative([parentPath, newName]); return fs.rename(path, newPath) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-rename", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-rename", value)); }, DENO: (path, newName) => { const parentPath = Path.getParentFolderPath(path); if (!parentPath) { - return Promise.resolve(E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); + return Promise.resolve(EE.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); } if (newName.includes("/")) { - return Promise.resolve(E.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); + return Promise.resolve(EE.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); } const newPath = Path.resolveRelative([parentPath, newName]); return Deno.rename(path, newPath) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-rename", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-rename", value)); }, }); diff --git a/docs/libs/v0/file/setMode.cjs b/docs/libs/v0/dist/file/setMode.cjs similarity index 57% rename from docs/libs/v0/file/setMode.cjs rename to docs/libs/v0/dist/file/setMode.cjs index 29adefc..af02b8a 100644 --- a/docs/libs/v0/file/setMode.cjs +++ b/docs/libs/v0/dist/file/setMode.cjs @@ -1,8 +1,28 @@ 'use strict'; var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); var implementor = require('../implementor.cjs'); +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + function calculatePermissions(permissions) { if (!permissions) { return 0; @@ -30,13 +50,13 @@ const setMode = implementor.implementFunction("setMode", { NODE: async (path, mode) => { const fs = await implementor.nodeFileSystem.value; return fs.chmod(path, toMode(mode)) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-mode", value)); + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-mode", value)); }, DENO: (path, mode) => Deno .chmod(path, toMode(mode)) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-mode", value)), + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-mode", value)), }); exports.setMode = setMode; diff --git a/docs/libs/v0/file/setMode.d.ts b/docs/libs/v0/dist/file/setMode.d.ts similarity index 90% rename from docs/libs/v0/file/setMode.d.ts rename to docs/libs/v0/dist/file/setMode.d.ts index a613d9a..2e41a95 100644 --- a/docs/libs/v0/file/setMode.d.ts +++ b/docs/libs/v0/dist/file/setMode.d.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface Permissions { read?: boolean; @@ -16,7 +16,7 @@ interface ModeObject { type SetMode = ModeObject | number; declare module "../implementor" { interface ServerUtilsFunction { - setMode(path: string, mode: SetMode): Promise | E.Ok>; + setMode(path: string, mode: SetMode): Promise | EE.Ok>; } } /** @@ -42,5 +42,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const setMode: (path: string, mode: SetMode) => Promise | E.Ok>; +export declare const setMode: (path: string, mode: SetMode) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/file/setMode.mjs b/docs/libs/v0/dist/file/setMode.mjs similarity index 78% rename from docs/libs/v0/file/setMode.mjs rename to docs/libs/v0/dist/file/setMode.mjs index 6271f46..24af8d6 100644 --- a/docs/libs/v0/file/setMode.mjs +++ b/docs/libs/v0/dist/file/setMode.mjs @@ -1,4 +1,5 @@ -import { E, isType } from '@duplojs/utils'; +import { isType } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; function calculatePermissions(permissions) { @@ -28,13 +29,13 @@ const setMode = implementFunction("setMode", { NODE: async (path, mode) => { const fs = await nodeFileSystem.value; return fs.chmod(path, toMode(mode)) - .then(E.ok) - .catch((value) => E.left("file-system-set-mode", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-set-mode", value)); }, DENO: (path, mode) => Deno .chmod(path, toMode(mode)) - .then(E.ok) - .catch((value) => E.left("file-system-set-mode", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-set-mode", value)), }); export { setMode }; diff --git a/docs/libs/v0/dist/file/setOwner.cjs b/docs/libs/v0/dist/file/setOwner.cjs new file mode 100644 index 0000000..d18fb60 --- /dev/null +++ b/docs/libs/v0/dist/file/setOwner.cjs @@ -0,0 +1,41 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/setOwner/index.md} + */ +const setOwner = implementor.implementFunction("setOwner", { + NODE: async (path, { userId, groupId }) => { + const fs = await implementor.nodeFileSystem.value; + return fs.chown(path, userId, groupId) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-owner", value)); + }, + DENO: (path, { userId, groupId }) => Deno + .chown(path, userId, groupId) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-owner", value)), +}); + +exports.setOwner = setOwner; diff --git a/docs/libs/v0/file/setOwner.d.ts b/docs/libs/v0/dist/file/setOwner.d.ts similarity index 84% rename from docs/libs/v0/file/setOwner.d.ts rename to docs/libs/v0/dist/file/setOwner.d.ts index 18cb623..857e761 100644 --- a/docs/libs/v0/file/setOwner.d.ts +++ b/docs/libs/v0/dist/file/setOwner.d.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface SetOwnerParams { userId: number; @@ -6,7 +6,7 @@ interface SetOwnerParams { } declare module "../implementor" { interface ServerUtilsFunction { - setOwner(path: string, params: SetOwnerParams): Promise | E.Ok>; + setOwner(path: string, params: SetOwnerParams): Promise | EE.Ok>; } } /** @@ -31,5 +31,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const setOwner: (path: string, params: SetOwnerParams) => Promise | E.Ok>; +export declare const setOwner: (path: string, params: SetOwnerParams) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/file/setOwner.mjs b/docs/libs/v0/dist/file/setOwner.mjs similarity index 64% rename from docs/libs/v0/file/setOwner.mjs rename to docs/libs/v0/dist/file/setOwner.mjs index 823cd69..270b8da 100644 --- a/docs/libs/v0/file/setOwner.mjs +++ b/docs/libs/v0/dist/file/setOwner.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +8,13 @@ const setOwner = implementFunction("setOwner", { NODE: async (path, { userId, groupId }) => { const fs = await nodeFileSystem.value; return fs.chown(path, userId, groupId) - .then(E.ok) - .catch((value) => E.left("file-system-set-owner", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-set-owner", value)); }, DENO: (path, { userId, groupId }) => Deno .chown(path, userId, groupId) - .then(E.ok) - .catch((value) => E.left("file-system-set-owner", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-set-owner", value)), }); export { setOwner }; diff --git a/docs/libs/v0/dist/file/setTime.cjs b/docs/libs/v0/dist/file/setTime.cjs new file mode 100644 index 0000000..d426170 --- /dev/null +++ b/docs/libs/v0/dist/file/setTime.cjs @@ -0,0 +1,43 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var DD = require('@duplojs/utils/date'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var DD__namespace = /*#__PURE__*/_interopNamespaceDefault(DD); + +/** + * {@include file/setTime/index.md} + */ +const setTime = implementor.implementFunction("setTime", { + NODE: async (path, { accessTime, modifiedTime }) => { + const fs = await implementor.nodeFileSystem.value; + return fs.utimes(path, DD__namespace.toTimestamp(accessTime), DD__namespace.toTimestamp(modifiedTime)) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-time", value)); + }, + DENO: (path, { accessTime, modifiedTime }) => Deno + .utime(path, DD__namespace.toTimestamp(accessTime), DD__namespace.toTimestamp(modifiedTime)) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-set-time", value)), +}); + +exports.setTime = setTime; diff --git a/docs/libs/v0/file/setTime.d.ts b/docs/libs/v0/dist/file/setTime.d.ts similarity index 79% rename from docs/libs/v0/file/setTime.d.ts rename to docs/libs/v0/dist/file/setTime.d.ts index d24946b..3d6403c 100644 --- a/docs/libs/v0/file/setTime.d.ts +++ b/docs/libs/v0/dist/file/setTime.d.ts @@ -1,12 +1,13 @@ -import { D, E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as DD from "@duplojs/utils/date"; import type { FileSystemLeft } from "./types"; interface SetTimeParams { - accessTime: D.TheDate; - modifiedTime: D.TheDate; + accessTime: DD.TheDate; + modifiedTime: DD.TheDate; } declare module "../implementor" { interface ServerUtilsFunction { - setTime(path: string, params: SetTimeParams): Promise | E.Ok>; + setTime(path: string, params: SetTimeParams): Promise | EE.Ok>; } } /** @@ -34,5 +35,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const setTime: (path: string, params: SetTimeParams) => Promise | E.Ok>; +export declare const setTime: (path: string, params: SetTimeParams) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/dist/file/setTime.mjs b/docs/libs/v0/dist/file/setTime.mjs new file mode 100644 index 0000000..7dd2c04 --- /dev/null +++ b/docs/libs/v0/dist/file/setTime.mjs @@ -0,0 +1,21 @@ +import * as EE from '@duplojs/utils/either'; +import * as DD from '@duplojs/utils/date'; +import { implementFunction, nodeFileSystem } from '../implementor.mjs'; + +/** + * {@include file/setTime/index.md} + */ +const setTime = implementFunction("setTime", { + NODE: async (path, { accessTime, modifiedTime }) => { + const fs = await nodeFileSystem.value; + return fs.utimes(path, DD.toTimestamp(accessTime), DD.toTimestamp(modifiedTime)) + .then(EE.ok) + .catch((value) => EE.left("file-system-set-time", value)); + }, + DENO: (path, { accessTime, modifiedTime }) => Deno + .utime(path, DD.toTimestamp(accessTime), DD.toTimestamp(modifiedTime)) + .then(EE.ok) + .catch((value) => EE.left("file-system-set-time", value)), +}); + +export { setTime }; diff --git a/docs/libs/v0/dist/file/stat.cjs b/docs/libs/v0/dist/file/stat.cjs new file mode 100644 index 0000000..aeb1cf2 --- /dev/null +++ b/docs/libs/v0/dist/file/stat.cjs @@ -0,0 +1,110 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var DD = require('@duplojs/utils/date'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var DD__namespace = /*#__PURE__*/_interopNamespaceDefault(DD); + +function createStatInfoWithFsSource(source) { + return { + isFile: source.isFile(), + isDirectory: source.isDirectory(), + isSymlink: source.isSymbolicLink(), + sizeBytes: source.size, + modifiedAt: DD__namespace.isSafeTimestamp(source.mtime.getTime()) ? DD__namespace.createOrThrow(source.mtime) : null, + accessedAt: DD__namespace.isSafeTimestamp(source.atime.getTime()) ? DD__namespace.createOrThrow(source.atime) : null, + createdAt: DD__namespace.isSafeTimestamp(source.birthtime.getTime()) ? DD__namespace.createOrThrow(source.birthtime) : null, + changedAt: DD__namespace.isSafeTimestamp(source.ctime.getTime()) ? DD__namespace.createOrThrow(source.ctime) : null, + deviceId: source.dev, + inode: source.ino, + permissionsMode: source.mode, + hardLinkCount: source.nlink, + ownerUserId: source.uid, + ownerGroupId: source.gid, + specialDeviceId: source.rdev, + ioBlockSize: source.blksize, + allocatedBlockCount: source.blocks, + isBlockDevice: source.isBlockDevice(), + isCharacterDevice: source.isCharacterDevice(), + isFifo: source.isFIFO(), + isSocket: source.isSocket(), + }; +} +function createStatInfoWithDeno(source) { + return { + isFile: source.isFile, + isDirectory: source.isDirectory, + isSymlink: source.isSymlink, + sizeBytes: source.size, + modifiedAt: source.mtime + && DD__namespace.isSafeTimestamp(source.mtime.getTime()) + ? DD__namespace.createOrThrow(source.mtime) + : null, + accessedAt: source.atime + && DD__namespace.isSafeTimestamp(source.atime.getTime()) + ? DD__namespace.createOrThrow(source.atime) + : null, + createdAt: source.birthtime + && DD__namespace.isSafeTimestamp(source.birthtime.getTime()) + ? DD__namespace.createOrThrow(source.birthtime) + : null, + changedAt: source.ctime + && DD__namespace.isSafeTimestamp(source.ctime.getTime()) + ? DD__namespace.createOrThrow(source.ctime) + : null, + deviceId: source.dev, + inode: source.ino, + permissionsMode: source.mode, + hardLinkCount: source.nlink, + ownerUserId: source.uid, + ownerGroupId: source.gid, + specialDeviceId: source.rdev, + ioBlockSize: source.blksize, + allocatedBlockCount: source.blocks, + isBlockDevice: source.isBlockDevice, + isCharacterDevice: source.isCharDevice, + isFifo: source.isFifo, + isSocket: source.isSocket, + }; +} +/** + * {@include file/stat/index.md} + */ +const stat = implementor.implementFunction("stat", { + NODE: async (path) => { + const fs = await implementor.nodeFileSystem.value; + return fs.stat(path) + .then(utils.innerPipe(createStatInfoWithFsSource, EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-stat", value)); + }, + DENO: (path) => Deno + .stat(path) + .then(utils.innerPipe(createStatInfoWithDeno, EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-stat", value)), + BUN: (path) => Bun.file(path) + .stat() + .then(utils.innerPipe(createStatInfoWithFsSource, EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-stat", value)), +}); + +exports.stat = stat; diff --git a/docs/libs/v0/file/stat.d.ts b/docs/libs/v0/dist/file/stat.d.ts similarity index 80% rename from docs/libs/v0/file/stat.d.ts rename to docs/libs/v0/dist/file/stat.d.ts index d2d6ac5..2ae7fa8 100644 --- a/docs/libs/v0/file/stat.d.ts +++ b/docs/libs/v0/dist/file/stat.d.ts @@ -1,4 +1,5 @@ -import { D, E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as DD from "@duplojs/utils/date"; import type { FileSystemLeft } from "./types"; export interface StatInfo { /** Type of entry */ @@ -8,10 +9,10 @@ export interface StatInfo { /** Size in bytes */ sizeBytes: number; /** Timestamps */ - modifiedAt: D.TheDate | null; - accessedAt: D.TheDate | null; - createdAt: D.TheDate | null; - changedAt: D.TheDate | null; + modifiedAt: DD.TheDate | null; + accessedAt: DD.TheDate | null; + createdAt: DD.TheDate | null; + changedAt: DD.TheDate | null; /** Unix/FS identifiers */ deviceId: number; inode: number | null; @@ -33,7 +34,7 @@ export interface StatInfo { } declare module "../implementor" { interface ServerUtilsFunction { - stat(path: GenericPath): Promise | E.Success>; + stat(path: GenericPath): Promise | EE.Success>; } } /** @@ -52,4 +53,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const stat: (path: GenericPath) => Promise | E.Success>; +export declare const stat: (path: GenericPath) => Promise | EE.Success>; diff --git a/docs/libs/v0/file/stat.mjs b/docs/libs/v0/dist/file/stat.mjs similarity index 59% rename from docs/libs/v0/file/stat.mjs rename to docs/libs/v0/dist/file/stat.mjs index 94f3123..2d09c4f 100644 --- a/docs/libs/v0/file/stat.mjs +++ b/docs/libs/v0/dist/file/stat.mjs @@ -1,4 +1,6 @@ -import { innerPipe, E, D } from '@duplojs/utils'; +import { innerPipe } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; +import * as DD from '@duplojs/utils/date'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; function createStatInfoWithFsSource(source) { @@ -7,10 +9,10 @@ function createStatInfoWithFsSource(source) { isDirectory: source.isDirectory(), isSymlink: source.isSymbolicLink(), sizeBytes: source.size, - modifiedAt: D.isSafeTimestamp(source.mtime.getTime()) ? D.createOrThrow(source.mtime) : null, - accessedAt: D.isSafeTimestamp(source.atime.getTime()) ? D.createOrThrow(source.atime) : null, - createdAt: D.isSafeTimestamp(source.birthtime.getTime()) ? D.createOrThrow(source.birthtime) : null, - changedAt: D.isSafeTimestamp(source.ctime.getTime()) ? D.createOrThrow(source.ctime) : null, + modifiedAt: DD.isSafeTimestamp(source.mtime.getTime()) ? DD.createOrThrow(source.mtime) : null, + accessedAt: DD.isSafeTimestamp(source.atime.getTime()) ? DD.createOrThrow(source.atime) : null, + createdAt: DD.isSafeTimestamp(source.birthtime.getTime()) ? DD.createOrThrow(source.birthtime) : null, + changedAt: DD.isSafeTimestamp(source.ctime.getTime()) ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, permissionsMode: source.mode, @@ -33,20 +35,20 @@ function createStatInfoWithDeno(source) { isSymlink: source.isSymlink, sizeBytes: source.size, modifiedAt: source.mtime - && D.isSafeTimestamp(source.mtime.getTime()) - ? D.createOrThrow(source.mtime) + && DD.isSafeTimestamp(source.mtime.getTime()) + ? DD.createOrThrow(source.mtime) : null, accessedAt: source.atime - && D.isSafeTimestamp(source.atime.getTime()) - ? D.createOrThrow(source.atime) + && DD.isSafeTimestamp(source.atime.getTime()) + ? DD.createOrThrow(source.atime) : null, createdAt: source.birthtime - && D.isSafeTimestamp(source.birthtime.getTime()) - ? D.createOrThrow(source.birthtime) + && DD.isSafeTimestamp(source.birthtime.getTime()) + ? DD.createOrThrow(source.birthtime) : null, changedAt: source.ctime - && D.isSafeTimestamp(source.ctime.getTime()) - ? D.createOrThrow(source.ctime) + && DD.isSafeTimestamp(source.ctime.getTime()) + ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, @@ -70,17 +72,17 @@ const stat = implementFunction("stat", { NODE: async (path) => { const fs = await nodeFileSystem.value; return fs.stat(path) - .then(innerPipe(createStatInfoWithFsSource, E.success)) - .catch((value) => E.left("file-system-stat", value)); + .then(innerPipe(createStatInfoWithFsSource, EE.success)) + .catch((value) => EE.left("file-system-stat", value)); }, DENO: (path) => Deno .stat(path) - .then(innerPipe(createStatInfoWithDeno, E.success)) - .catch((value) => E.left("file-system-stat", value)), + .then(innerPipe(createStatInfoWithDeno, EE.success)) + .catch((value) => EE.left("file-system-stat", value)), BUN: (path) => Bun.file(path) .stat() - .then(innerPipe(createStatInfoWithFsSource, E.success)) - .catch((value) => E.left("file-system-stat", value)), + .then(innerPipe(createStatInfoWithFsSource, EE.success)) + .catch((value) => EE.left("file-system-stat", value)), }); export { stat }; diff --git a/docs/libs/v0/dist/file/symlink.cjs b/docs/libs/v0/dist/file/symlink.cjs new file mode 100644 index 0000000..f4afe9a --- /dev/null +++ b/docs/libs/v0/dist/file/symlink.cjs @@ -0,0 +1,41 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/symlink/index.md} + */ +const symlink = implementor.implementFunction("symlink", { + NODE: async (oldPath, newPath, params) => { + const fs = await implementor.nodeFileSystem.value; + return fs.symlink(oldPath, newPath, params?.type) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-symlink", value)); + }, + DENO: (oldPath, newPath, params) => Deno + .symlink(oldPath, newPath, params) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-symlink", value)), +}); + +exports.symlink = symlink; diff --git a/docs/libs/v0/file/symlink.d.ts b/docs/libs/v0/dist/file/symlink.d.ts similarity index 90% rename from docs/libs/v0/file/symlink.d.ts rename to docs/libs/v0/dist/file/symlink.d.ts index 81d4d19..a6c296a 100644 --- a/docs/libs/v0/file/symlink.d.ts +++ b/docs/libs/v0/dist/file/symlink.d.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; export interface SymlinkParams { /** @@ -10,7 +10,7 @@ export interface SymlinkParams { } declare module "../implementor" { interface ServerUtilsFunction { - symlink(oldPath: string, newPath: string, params?: SymlinkParams): Promise | E.Ok>; + symlink(oldPath: string, newPath: string, params?: SymlinkParams): Promise | EE.Ok>; } } /** @@ -31,4 +31,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const symlink: (oldPath: string, newPath: string, params?: SymlinkParams) => Promise | E.Ok>; +export declare const symlink: (oldPath: string, newPath: string, params?: SymlinkParams) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/symlink.mjs b/docs/libs/v0/dist/file/symlink.mjs similarity index 65% rename from docs/libs/v0/file/symlink.mjs rename to docs/libs/v0/dist/file/symlink.mjs index 0b74263..8699574 100644 --- a/docs/libs/v0/file/symlink.mjs +++ b/docs/libs/v0/dist/file/symlink.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +8,13 @@ const symlink = implementFunction("symlink", { NODE: async (oldPath, newPath, params) => { const fs = await nodeFileSystem.value; return fs.symlink(oldPath, newPath, params?.type) - .then(E.ok) - .catch((value) => E.left("file-system-symlink", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-symlink", value)); }, DENO: (oldPath, newPath, params) => Deno .symlink(oldPath, newPath, params) - .then(E.ok) - .catch((value) => E.left("file-system-symlink", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-symlink", value)), }); export { symlink }; diff --git a/docs/libs/v0/dist/file/truncate.cjs b/docs/libs/v0/dist/file/truncate.cjs new file mode 100644 index 0000000..959605e --- /dev/null +++ b/docs/libs/v0/dist/file/truncate.cjs @@ -0,0 +1,42 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/truncate/index.md} + */ +const truncate = implementor.implementFunction("truncate", { + NODE: async (path, size) => { + const fs = await implementor.nodeFileSystem.value; + return fs.truncate(path, size) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-truncate", value)); + }, + DENO: (path, size) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (stringPath) => Deno + .truncate(stringPath, size) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-truncate", value))), +}); + +exports.truncate = truncate; diff --git a/docs/libs/v0/file/truncate.d.ts b/docs/libs/v0/dist/file/truncate.d.ts similarity index 85% rename from docs/libs/v0/file/truncate.d.ts rename to docs/libs/v0/dist/file/truncate.d.ts index 84e6b40..665155b 100644 --- a/docs/libs/v0/file/truncate.d.ts +++ b/docs/libs/v0/dist/file/truncate.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - truncate(path: GenericPath, size?: number): Promise | E.Ok>; + truncate(path: GenericPath, size?: number): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const truncate: (path: GenericPath, size?: number) => Promise | E.Ok>; +export declare const truncate: (path: GenericPath, size?: number) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/truncate.mjs b/docs/libs/v0/dist/file/truncate.mjs similarity index 62% rename from docs/libs/v0/file/truncate.mjs rename to docs/libs/v0/dist/file/truncate.mjs index c217f7a..c009b43 100644 --- a/docs/libs/v0/file/truncate.mjs +++ b/docs/libs/v0/dist/file/truncate.mjs @@ -1,4 +1,5 @@ -import { pipe, when, instanceOf, E } from '@duplojs/utils'; +import { pipe, when, instanceOf } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,13 +9,13 @@ const truncate = implementFunction("truncate", { NODE: async (path, size) => { const fs = await nodeFileSystem.value; return fs.truncate(path, size) - .then(E.ok) - .catch((value) => E.left("file-system-truncate", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-truncate", value)); }, DENO: (path, size) => pipe(path, when(instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (stringPath) => Deno .truncate(stringPath, size) - .then(E.ok) - .catch((value) => E.left("file-system-truncate", value))), + .then(EE.ok) + .catch((value) => EE.left("file-system-truncate", value))), }); export { truncate }; diff --git a/docs/libs/v0/dist/file/types/fileSystemLeft.d.ts b/docs/libs/v0/dist/file/types/fileSystemLeft.d.ts new file mode 100644 index 0000000..d875e98 --- /dev/null +++ b/docs/libs/v0/dist/file/types/fileSystemLeft.d.ts @@ -0,0 +1,2 @@ +import type * as EE from "@duplojs/utils/either"; +export type FileSystemLeft = EE.Left<`file-system-${GenericName}`, unknown>; diff --git a/docs/libs/v0/file/types/index.d.ts b/docs/libs/v0/dist/file/types/index.d.ts similarity index 100% rename from docs/libs/v0/file/types/index.d.ts rename to docs/libs/v0/dist/file/types/index.d.ts diff --git a/docs/libs/v0/file/unknownInterface.cjs b/docs/libs/v0/dist/file/unknownInterface.cjs similarity index 100% rename from docs/libs/v0/file/unknownInterface.cjs rename to docs/libs/v0/dist/file/unknownInterface.cjs diff --git a/docs/libs/v0/file/unknownInterface.d.ts b/docs/libs/v0/dist/file/unknownInterface.d.ts similarity index 88% rename from docs/libs/v0/file/unknownInterface.d.ts rename to docs/libs/v0/dist/file/unknownInterface.d.ts index 4443e09..d3a9ec7 100644 --- a/docs/libs/v0/file/unknownInterface.d.ts +++ b/docs/libs/v0/dist/file/unknownInterface.d.ts @@ -1,4 +1,5 @@ -import { type E, type Kind } from "@duplojs/utils"; +import { type Kind } from "@duplojs/utils"; +import type * as EE from "@duplojs/utils/either"; import { type StatInfo } from "./stat"; import type { FileSystemLeft } from "./types"; declare const unknownInterfaceKind: import("@duplojs/utils").KindHandler>; @@ -6,8 +7,8 @@ export interface UnknownInterface extends Kind | E.Success>; - exist(): Promise | E.Ok>; + stat(): Promise | EE.Success>; + exist(): Promise | EE.Ok>; } /** * Create an interface for an unknown path type. diff --git a/docs/libs/v0/file/unknownInterface.mjs b/docs/libs/v0/dist/file/unknownInterface.mjs similarity index 100% rename from docs/libs/v0/file/unknownInterface.mjs rename to docs/libs/v0/dist/file/unknownInterface.mjs diff --git a/docs/libs/v0/dist/file/walkDirectory.cjs b/docs/libs/v0/dist/file/walkDirectory.cjs new file mode 100644 index 0000000..668fd72 --- /dev/null +++ b/docs/libs/v0/dist/file/walkDirectory.cjs @@ -0,0 +1,48 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var GG = require('@duplojs/utils/generator'); +var EE = require('@duplojs/utils/either'); +var PP = require('@duplojs/utils/pattern'); +var implementor = require('../implementor.cjs'); +var fileInterface = require('./fileInterface.cjs'); +var folderInterface = require('./folderInterface.cjs'); +var unknownInterface = require('./unknownInterface.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var GG__namespace = /*#__PURE__*/_interopNamespaceDefault(GG); +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); +var PP__namespace = /*#__PURE__*/_interopNamespaceDefault(PP); + +/** + * {@include file/walkDirectory/index.md} + */ +const walkDirectory = implementor.implementFunction("walkDirectory", { + NODE: async (path, params) => { + const fs = await implementor.nodeFileSystem.value; + return fs.readdir(path, { + recursive: params?.recursive ?? false, + withFileTypes: true, + }) + .then(utils.innerPipe(GG__namespace.map(utils.innerPipe(PP__namespace.when((dirent) => dirent.isFile(), ({ parentPath, name }) => fileInterface.createFileInterface(`${parentPath}/${name}`)), PP__namespace.when((dirent) => dirent.isDirectory(), ({ parentPath, name }) => folderInterface.createFolderInterface(`${parentPath}/${name}`)), PP__namespace.otherwise(({ parentPath, name }) => unknownInterface.createUnknownInterface(`${parentPath}/${name}`)))), EE__namespace.success)) + .catch((value) => EE__namespace.left("file-system-walk-directory", value)); + }, +}); + +exports.walkDirectory = walkDirectory; diff --git a/docs/libs/v0/file/walkDirectory.d.ts b/docs/libs/v0/dist/file/walkDirectory.d.ts similarity index 80% rename from docs/libs/v0/file/walkDirectory.d.ts rename to docs/libs/v0/dist/file/walkDirectory.d.ts index 79a052f..6f7bdcc 100644 --- a/docs/libs/v0/file/walkDirectory.d.ts +++ b/docs/libs/v0/dist/file/walkDirectory.d.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { type FileInterface } from "./fileInterface"; import { type FolderInterface } from "./folderInterface"; import { type UnknownInterface } from "./unknownInterface"; @@ -8,7 +8,7 @@ interface WalkDirectoryParams { } declare module "../implementor" { interface ServerUtilsFunction { - walkDirectory(path: GenericPath, params?: WalkDirectoryParams): Promise | E.Success>>; + walkDirectory(path: GenericPath, params?: WalkDirectoryParams): Promise | EE.Success>>; } } /** @@ -27,5 +27,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const walkDirectory: (path: GenericPath, params?: WalkDirectoryParams) => Promise | E.Success>>; +export declare const walkDirectory: (path: GenericPath, params?: WalkDirectoryParams) => Promise | EE.Success>>; export {}; diff --git a/docs/libs/v0/dist/file/walkDirectory.mjs b/docs/libs/v0/dist/file/walkDirectory.mjs new file mode 100644 index 0000000..b5046fa --- /dev/null +++ b/docs/libs/v0/dist/file/walkDirectory.mjs @@ -0,0 +1,25 @@ +import { innerPipe } from '@duplojs/utils'; +import * as GG from '@duplojs/utils/generator'; +import * as EE from '@duplojs/utils/either'; +import * as PP from '@duplojs/utils/pattern'; +import { implementFunction, nodeFileSystem } from '../implementor.mjs'; +import { createFileInterface } from './fileInterface.mjs'; +import { createFolderInterface } from './folderInterface.mjs'; +import { createUnknownInterface } from './unknownInterface.mjs'; + +/** + * {@include file/walkDirectory/index.md} + */ +const walkDirectory = implementFunction("walkDirectory", { + NODE: async (path, params) => { + const fs = await nodeFileSystem.value; + return fs.readdir(path, { + recursive: params?.recursive ?? false, + withFileTypes: true, + }) + .then(innerPipe(GG.map(innerPipe(PP.when((dirent) => dirent.isFile(), ({ parentPath, name }) => createFileInterface(`${parentPath}/${name}`)), PP.when((dirent) => dirent.isDirectory(), ({ parentPath, name }) => createFolderInterface(`${parentPath}/${name}`)), PP.otherwise(({ parentPath, name }) => createUnknownInterface(`${parentPath}/${name}`)))), EE.success)) + .catch((value) => EE.left("file-system-walk-directory", value)); + }, +}); + +export { walkDirectory }; diff --git a/docs/libs/v0/dist/file/writeFile.cjs b/docs/libs/v0/dist/file/writeFile.cjs new file mode 100644 index 0000000..07cd0cb --- /dev/null +++ b/docs/libs/v0/dist/file/writeFile.cjs @@ -0,0 +1,46 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/writeFile/index.md} + */ +const writeFile = implementor.implementFunction("writeFile", { + NODE: async (path, data) => { + const fs = await implementor.nodeFileSystem.value; + return fs.writeFile(path, data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-file", value)); + }, + DENO: (path, data) => Deno + .writeFile(path, data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-file", value)), + BUN: (path, data) => Bun + .file(path) + .write(data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-file", value)), +}); + +exports.writeFile = writeFile; diff --git a/docs/libs/v0/file/writeFile.d.ts b/docs/libs/v0/dist/file/writeFile.d.ts similarity index 84% rename from docs/libs/v0/file/writeFile.d.ts rename to docs/libs/v0/dist/file/writeFile.d.ts index b9d7600..f470937 100644 --- a/docs/libs/v0/file/writeFile.d.ts +++ b/docs/libs/v0/dist/file/writeFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - writeFile(path: string, data: Uint8Array): Promise | E.Ok>; + writeFile(path: string, data: Uint8Array): Promise | EE.Ok>; } } /** @@ -22,4 +22,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const writeFile: (path: string, data: Uint8Array) => Promise | E.Ok>; +export declare const writeFile: (path: string, data: Uint8Array) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/writeFile.mjs b/docs/libs/v0/dist/file/writeFile.mjs similarity index 58% rename from docs/libs/v0/file/writeFile.mjs rename to docs/libs/v0/dist/file/writeFile.mjs index 3ffccca..d4d2580 100644 --- a/docs/libs/v0/file/writeFile.mjs +++ b/docs/libs/v0/dist/file/writeFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,18 +8,18 @@ const writeFile = implementFunction("writeFile", { NODE: async (path, data) => { const fs = await nodeFileSystem.value; return fs.writeFile(path, data) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)); }, DENO: (path, data) => Deno .writeFile(path, data) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)), BUN: (path, data) => Bun .file(path) .write(data) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)), }); export { writeFile }; diff --git a/docs/libs/v0/dist/file/writeJsonFile.cjs b/docs/libs/v0/dist/file/writeJsonFile.cjs new file mode 100644 index 0000000..accd26a --- /dev/null +++ b/docs/libs/v0/dist/file/writeJsonFile.cjs @@ -0,0 +1,45 @@ +'use strict'; + +var utils = require('@duplojs/utils'); +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/writeJsonFile/index.md} + */ +const writeJsonFile = implementor.implementFunction("writeJsonFile", { + NODE: async (path, data, params) => { + const fs = await implementor.nodeFileSystem.value; + return utils.pipe(EE__namespace.safeCallback(() => JSON.stringify(data, null, params?.space)), EE__namespace.whenIsRight((value) => fs.writeFile(path, value, { encoding: "utf-8" }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-json-file", value))), EE__namespace.whenIsLeft((value) => EE__namespace.left("file-system-write-json-file", value))); + }, + DENO: (path, data, params) => utils.asyncPipe(EE__namespace.safeCallback(() => JSON.stringify(data, null, params?.space)), EE__namespace.whenIsRight((value) => Deno.writeTextFile(path, value) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-json-file", value))), EE__namespace.whenIsLeft((value) => EE__namespace.left("file-system-write-json-file", value))), + BUN: (path, data, params) => utils.asyncPipe(EE__namespace.safeCallback(() => JSON.stringify(data, null, params?.space)), EE__namespace.whenIsRight((value) => Bun.file(path) + .write(value) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-json-file", value))), EE__namespace.whenIsLeft((value) => EE__namespace.left("file-system-write-json-file", value))), +}); + +exports.writeJsonFile = writeJsonFile; diff --git a/docs/libs/v0/file/writeJsonFile.d.ts b/docs/libs/v0/dist/file/writeJsonFile.d.ts similarity index 87% rename from docs/libs/v0/file/writeJsonFile.d.ts rename to docs/libs/v0/dist/file/writeJsonFile.d.ts index f64836f..e3d75c0 100644 --- a/docs/libs/v0/file/writeJsonFile.d.ts +++ b/docs/libs/v0/dist/file/writeJsonFile.d.ts @@ -1,11 +1,11 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; interface WriteJsonFile { space?: number; } declare module "../implementor" { interface ServerUtilsFunction { - writeJsonFile(path: string, data: unknown, params?: WriteJsonFile): Promise | E.Ok>; + writeJsonFile(path: string, data: unknown, params?: WriteJsonFile): Promise | EE.Ok>; } } /** @@ -26,5 +26,5 @@ declare module "../implementor" { * @namespace SF * */ -export declare const writeJsonFile: (path: string, data: unknown, params?: WriteJsonFile) => Promise | E.Ok>; +export declare const writeJsonFile: (path: string, data: unknown, params?: WriteJsonFile) => Promise | EE.Ok>; export {}; diff --git a/docs/libs/v0/dist/file/writeJsonFile.mjs b/docs/libs/v0/dist/file/writeJsonFile.mjs new file mode 100644 index 0000000..9411680 --- /dev/null +++ b/docs/libs/v0/dist/file/writeJsonFile.mjs @@ -0,0 +1,24 @@ +import { asyncPipe, pipe } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; +import { implementFunction, nodeFileSystem } from '../implementor.mjs'; + +/** + * {@include file/writeJsonFile/index.md} + */ +const writeJsonFile = implementFunction("writeJsonFile", { + NODE: async (path, data, params) => { + const fs = await nodeFileSystem.value; + return pipe(EE.safeCallback(() => JSON.stringify(data, null, params?.space)), EE.whenIsRight((value) => fs.writeFile(path, value, { encoding: "utf-8" }) + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value))), EE.whenIsLeft((value) => EE.left("file-system-write-json-file", value))); + }, + DENO: (path, data, params) => asyncPipe(EE.safeCallback(() => JSON.stringify(data, null, params?.space)), EE.whenIsRight((value) => Deno.writeTextFile(path, value) + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value))), EE.whenIsLeft((value) => EE.left("file-system-write-json-file", value))), + BUN: (path, data, params) => asyncPipe(EE.safeCallback(() => JSON.stringify(data, null, params?.space)), EE.whenIsRight((value) => Bun.file(path) + .write(value) + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value))), EE.whenIsLeft((value) => EE.left("file-system-write-json-file", value))), +}); + +export { writeJsonFile }; diff --git a/docs/libs/v0/dist/file/writeTextFile.cjs b/docs/libs/v0/dist/file/writeTextFile.cjs new file mode 100644 index 0000000..d5663ac --- /dev/null +++ b/docs/libs/v0/dist/file/writeTextFile.cjs @@ -0,0 +1,46 @@ +'use strict'; + +var EE = require('@duplojs/utils/either'); +var implementor = require('../implementor.cjs'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var EE__namespace = /*#__PURE__*/_interopNamespaceDefault(EE); + +/** + * {@include file/writeTextFile/index.md} + */ +const writeTextFile = implementor.implementFunction("writeTextFile", { + NODE: async (path, data) => { + const fs = await implementor.nodeFileSystem.value; + return fs.writeFile(path, data, { encoding: "utf-8" }) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-text-file", value)); + }, + DENO: (path, data) => Deno + .writeTextFile(path, data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-text-file", value)), + BUN: (path, data) => Bun + .file(path) + .write(data) + .then(EE__namespace.ok) + .catch((value) => EE__namespace.left("file-system-write-text-file", value)), +}); + +exports.writeTextFile = writeTextFile; diff --git a/docs/libs/v0/file/writeTextFile.d.ts b/docs/libs/v0/dist/file/writeTextFile.d.ts similarity index 82% rename from docs/libs/v0/file/writeTextFile.d.ts rename to docs/libs/v0/dist/file/writeTextFile.d.ts index ab6b4c4..7f1a12f 100644 --- a/docs/libs/v0/file/writeTextFile.d.ts +++ b/docs/libs/v0/dist/file/writeTextFile.d.ts @@ -1,8 +1,8 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import type { FileSystemLeft } from "./types"; declare module "../implementor" { interface ServerUtilsFunction { - writeTextFile(path: string, data: string): Promise | E.Ok>; + writeTextFile(path: string, data: string): Promise | EE.Ok>; } } /** @@ -21,4 +21,4 @@ declare module "../implementor" { * @namespace SF * */ -export declare const writeTextFile: (path: string, data: string) => Promise | E.Ok>; +export declare const writeTextFile: (path: string, data: string) => Promise | EE.Ok>; diff --git a/docs/libs/v0/file/writeTextFile.mjs b/docs/libs/v0/dist/file/writeTextFile.mjs similarity index 59% rename from docs/libs/v0/file/writeTextFile.mjs rename to docs/libs/v0/dist/file/writeTextFile.mjs index 88d6a6a..e0159de 100644 --- a/docs/libs/v0/file/writeTextFile.mjs +++ b/docs/libs/v0/dist/file/writeTextFile.mjs @@ -1,4 +1,4 @@ -import { E } from '@duplojs/utils'; +import * as EE from '@duplojs/utils/either'; import { implementFunction, nodeFileSystem } from '../implementor.mjs'; /** @@ -8,18 +8,18 @@ const writeTextFile = implementFunction("writeTextFile", { NODE: async (path, data) => { const fs = await nodeFileSystem.value; return fs.writeFile(path, data, { encoding: "utf-8" }) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)); }, DENO: (path, data) => Deno .writeTextFile(path, data) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)), BUN: (path, data) => Bun .file(path) .write(data) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)), }); export { writeTextFile }; diff --git a/docs/libs/v0/implementor.cjs b/docs/libs/v0/dist/implementor.cjs similarity index 100% rename from docs/libs/v0/implementor.cjs rename to docs/libs/v0/dist/implementor.cjs diff --git a/docs/libs/v0/implementor.d.ts b/docs/libs/v0/dist/implementor.d.ts similarity index 100% rename from docs/libs/v0/implementor.d.ts rename to docs/libs/v0/dist/implementor.d.ts diff --git a/docs/libs/v0/implementor.mjs b/docs/libs/v0/dist/implementor.mjs similarity index 100% rename from docs/libs/v0/implementor.mjs rename to docs/libs/v0/dist/implementor.mjs diff --git a/docs/libs/v0/index.cjs b/docs/libs/v0/dist/index.cjs similarity index 100% rename from docs/libs/v0/index.cjs rename to docs/libs/v0/dist/index.cjs diff --git a/docs/libs/v0/index.d.ts b/docs/libs/v0/dist/index.d.ts similarity index 100% rename from docs/libs/v0/index.d.ts rename to docs/libs/v0/dist/index.d.ts diff --git a/docs/libs/v0/index.mjs b/docs/libs/v0/dist/index.mjs similarity index 100% rename from docs/libs/v0/index.mjs rename to docs/libs/v0/dist/index.mjs diff --git a/docs/libs/v0/kind.cjs b/docs/libs/v0/dist/kind.cjs similarity index 100% rename from docs/libs/v0/kind.cjs rename to docs/libs/v0/dist/kind.cjs diff --git a/docs/libs/v0/kind.d.ts b/docs/libs/v0/dist/kind.d.ts similarity index 100% rename from docs/libs/v0/kind.d.ts rename to docs/libs/v0/dist/kind.d.ts diff --git a/docs/libs/v0/kind.mjs b/docs/libs/v0/dist/kind.mjs similarity index 100% rename from docs/libs/v0/kind.mjs rename to docs/libs/v0/dist/kind.mjs diff --git a/docs/libs/v0/file/appendFile.cjs b/docs/libs/v0/file/appendFile.cjs deleted file mode 100644 index b404a29..0000000 --- a/docs/libs/v0/file/appendFile.cjs +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/appendFile/index.md} - */ -const appendFile = implementor.implementFunction("appendFile", { - NODE: async (path, data) => { - const fs = await implementor.nodeFileSystem.value; - return fs.appendFile(path, data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-append-file", value)); - }, - DENO: (path, data) => Deno.writeFile(path, data, { append: true }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-append-file", value)), -}); - -exports.appendFile = appendFile; diff --git a/docs/libs/v0/file/appendTextFile.cjs b/docs/libs/v0/file/appendTextFile.cjs deleted file mode 100644 index 66b6946..0000000 --- a/docs/libs/v0/file/appendTextFile.cjs +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/appendTextFile/index.md} - */ -const appendTextFile = implementor.implementFunction("appendTextFile", { - NODE: async (path, data) => { - const fs = await implementor.nodeFileSystem.value; - return fs.appendFile(path, data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-append-text-file", value)); - }, - DENO: (path, data) => Deno.writeTextFile(path, data, { append: true }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-append-text-file", value)), -}); - -exports.appendTextFile = appendTextFile; diff --git a/docs/libs/v0/file/copy.cjs b/docs/libs/v0/file/copy.cjs deleted file mode 100644 index 8ea6f9e..0000000 --- a/docs/libs/v0/file/copy.cjs +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/copy/index.md} - */ -const copy = implementor.implementFunction("copy", { - NODE: async (fromPath, toPath) => { - const fs = await implementor.nodeFileSystem.value; - return fs.cp(fromPath, toPath, { recursive: true }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-copy", value)); - }, -}); - -exports.copy = copy; diff --git a/docs/libs/v0/file/ensureDirectory.cjs b/docs/libs/v0/file/ensureDirectory.cjs deleted file mode 100644 index cc22207..0000000 --- a/docs/libs/v0/file/ensureDirectory.cjs +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/ensureDirectory/index.md} - */ -const ensureDirectory = implementor.implementFunction("ensureDirectory", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.mkdir(path, { - recursive: true, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-ensure-directory", value)); - }, - DENO: (path) => Deno.mkdir(path, { - recursive: true, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-ensure-directory", value)), -}); - -exports.ensureDirectory = ensureDirectory; diff --git a/docs/libs/v0/file/ensureFile.cjs b/docs/libs/v0/file/ensureFile.cjs deleted file mode 100644 index a0da8b2..0000000 --- a/docs/libs/v0/file/ensureFile.cjs +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/ensureFile/index.md} - */ -const ensureFile = implementor.implementFunction("ensureFile", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.open(path, "a") - .then((fh) => fh.close()) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-ensure-file", value)); - }, - DENO: (path) => Deno.open(path, { - write: true, - create: true, - append: true, - }) - .then((fh) => void fh.close()) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-ensure-file", value)), -}); - -exports.ensureFile = ensureFile; diff --git a/docs/libs/v0/file/exists.cjs b/docs/libs/v0/file/exists.cjs deleted file mode 100644 index f4be82c..0000000 --- a/docs/libs/v0/file/exists.cjs +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/exists/index.md} - */ -const exists = implementor.implementFunction("exists", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.access(path) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-exists", value)); - }, - DENO: (path) => Deno - .stat(path) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-exists", value)), - BUN: (path) => Bun.file(path) - .exists() - .then((value) => value - ? utils.E.ok() - : utils.E.left("file-system-exists", new Error("Path does not exist"))) - .catch((value) => utils.E.left("file-system-exists", value)), -}); - -exports.exists = exists; diff --git a/docs/libs/v0/file/link.cjs b/docs/libs/v0/file/link.cjs deleted file mode 100644 index 6d82c63..0000000 --- a/docs/libs/v0/file/link.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/link/index.md} - */ -const link = implementor.implementFunction("link", { - NODE: async (existingPath, newPath) => { - const fs = await implementor.nodeFileSystem.value; - return fs.link(existingPath, newPath) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-link", value)); - }, - DENO: (existingPath, newPath) => Deno - .link(existingPath, newPath) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-link", value)), -}); - -exports.link = link; diff --git a/docs/libs/v0/file/linkStat.cjs b/docs/libs/v0/file/linkStat.cjs deleted file mode 100644 index e9478b2..0000000 --- a/docs/libs/v0/file/linkStat.cjs +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -function createStatInfoWithFsSource(source) { - return { - isFile: source.isFile(), - isDirectory: source.isDirectory(), - isSymlink: source.isSymbolicLink(), - sizeBytes: source.size, - modifiedAt: utils.D.isSafeTimestamp(source.mtime.getTime()) ? utils.D.createOrThrow(source.mtime) : null, - accessedAt: utils.D.isSafeTimestamp(source.atime.getTime()) ? utils.D.createOrThrow(source.atime) : null, - createdAt: utils.D.isSafeTimestamp(source.birthtime.getTime()) ? utils.D.createOrThrow(source.birthtime) : null, - changedAt: utils.D.isSafeTimestamp(source.ctime.getTime()) ? utils.D.createOrThrow(source.ctime) : null, - deviceId: source.dev, - inode: source.ino, - permissionsMode: source.mode, - hardLinkCount: source.nlink, - ownerUserId: source.uid, - ownerGroupId: source.gid, - specialDeviceId: source.rdev, - ioBlockSize: source.blksize, - allocatedBlockCount: source.blocks, - isBlockDevice: source.isBlockDevice(), - isCharacterDevice: source.isCharacterDevice(), - isFifo: source.isFIFO(), - isSocket: source.isSocket(), - }; -} -function createStatInfoWithDeno(source) { - return { - isFile: source.isFile, - isDirectory: source.isDirectory, - isSymlink: source.isSymlink, - sizeBytes: source.size, - modifiedAt: source.mtime - && utils.D.isSafeTimestamp(source.mtime.getTime()) - ? utils.D.createOrThrow(source.mtime) - : null, - accessedAt: source.atime - && utils.D.isSafeTimestamp(source.atime.getTime()) - ? utils.D.createOrThrow(source.atime) - : null, - createdAt: source.birthtime - && utils.D.isSafeTimestamp(source.birthtime.getTime()) - ? utils.D.createOrThrow(source.birthtime) - : null, - changedAt: source.ctime - && utils.D.isSafeTimestamp(source.ctime.getTime()) - ? utils.D.createOrThrow(source.ctime) - : null, - deviceId: source.dev, - inode: source.ino, - permissionsMode: source.mode, - hardLinkCount: source.nlink, - ownerUserId: source.uid, - ownerGroupId: source.gid, - specialDeviceId: source.rdev, - ioBlockSize: source.blksize, - allocatedBlockCount: source.blocks, - isBlockDevice: source.isBlockDevice, - isCharacterDevice: source.isCharDevice, - isFifo: source.isFifo, - isSocket: source.isSocket, - }; -} -/** - * {@include file/linkStat/index.md} - */ -const linkStat = implementor.implementFunction("linkStat", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.lstat(path) - .then(utils.innerPipe(createStatInfoWithFsSource, utils.E.success)) - .catch((value) => utils.E.left("file-system-link-stat", value)); - }, - DENO: (path) => Deno - .lstat(path) - .then(utils.innerPipe(createStatInfoWithDeno, utils.E.success)) - .catch((value) => utils.E.left("file-system-link-stat", value)), -}); - -exports.linkStat = linkStat; diff --git a/docs/libs/v0/file/makeDirectory.cjs b/docs/libs/v0/file/makeDirectory.cjs deleted file mode 100644 index af0bf06..0000000 --- a/docs/libs/v0/file/makeDirectory.cjs +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/makeDirectory/index.md} - */ -const makeDirectory = implementor.implementFunction("makeDirectory", { - NODE: async (path, params) => { - const fs = await implementor.nodeFileSystem.value; - return fs.mkdir(path, { - recursive: params?.recursive, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-make-directory", value)); - }, - DENO: (path, params) => Deno.mkdir(path, { - recursive: params?.recursive, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-make-directory", value)), -}); - -exports.makeDirectory = makeDirectory; diff --git a/docs/libs/v0/file/makeTemporaryDirectory.cjs b/docs/libs/v0/file/makeTemporaryDirectory.cjs deleted file mode 100644 index 2c77e3f..0000000 --- a/docs/libs/v0/file/makeTemporaryDirectory.cjs +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/makeTemporaryDirectory/index.md} - */ -const makeTemporaryDirectory = implementor.implementFunction("makeTemporaryDirectory", { - NODE: async (prefix) => { - const fs = await implementor.nodeFileSystem.value; - return fs.mkdtemp(prefix) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-make-temporary-directory", value)); - }, - DENO: (prefix) => Deno.makeTempDir({ prefix }) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-make-temporary-directory", value)), -}); - -exports.makeTemporaryDirectory = makeTemporaryDirectory; diff --git a/docs/libs/v0/file/makeTemporaryFile.cjs b/docs/libs/v0/file/makeTemporaryFile.cjs deleted file mode 100644 index 0490822..0000000 --- a/docs/libs/v0/file/makeTemporaryFile.cjs +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/makeTemporaryFile/index.md} - */ -const makeTemporaryFile = implementor.implementFunction("makeTemporaryFile", { - NODE: async (prefix, suffix) => { - const fs = await implementor.nodeFileSystem.value; - const os = await implementor.nodeOs.value; - const crypto = await implementor.nodeCrypto.value; - const fileTemporaryPath = utils.Path.resolveRelative([ - os.tmpdir(), - `${prefix}${crypto.randomUUID()}${suffix ?? ""}`, - ]); - return fs.open(fileTemporaryPath, "wx") - .then((fh) => fh.close()) - .then(() => utils.E.success(fileTemporaryPath)) - .catch((value) => utils.E.left("file-system-make-temporary-file", value)); - }, - DENO: (prefix, suffix) => Deno.makeTempFile({ - prefix, - suffix, - }) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-make-temporary-file", value)), -}); - -exports.makeTemporaryFile = makeTemporaryFile; diff --git a/docs/libs/v0/file/move.cjs b/docs/libs/v0/file/move.cjs deleted file mode 100644 index b10cee0..0000000 --- a/docs/libs/v0/file/move.cjs +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/move/index.md} - */ -const move = implementor.implementFunction("move", { - NODE: async (fromPath, toPath) => { - const fs = await implementor.nodeFileSystem.value; - return fs.rename(fromPath, toPath) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-move", value)); - }, - DENO: (fromPath, toPath) => Deno.rename(fromPath, toPath) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-move", value)), -}); - -exports.move = move; diff --git a/docs/libs/v0/file/readDirectory.cjs b/docs/libs/v0/file/readDirectory.cjs deleted file mode 100644 index 92e960e..0000000 --- a/docs/libs/v0/file/readDirectory.cjs +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/readDirectory/index.md} - */ -const readDirectory = implementor.implementFunction("readDirectory", { - NODE: async (path, params) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readdir(path, { recursive: params?.recursive }) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-directory", value)); - }, -}); - -exports.readDirectory = readDirectory; diff --git a/docs/libs/v0/file/readFile.cjs b/docs/libs/v0/file/readFile.cjs deleted file mode 100644 index e42fb65..0000000 --- a/docs/libs/v0/file/readFile.cjs +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/readFile/index.md} - */ -const readFile = implementor.implementFunction("readFile", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readFile(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-file", value)); - }, - DENO: (path) => Deno - .readFile(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-file", value)), - BUN: (path) => Bun.file(path) - .bytes() - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-file", value)), -}); - -exports.readFile = readFile; diff --git a/docs/libs/v0/file/readJsonFile.cjs b/docs/libs/v0/file/readJsonFile.cjs deleted file mode 100644 index 7bb2fb1..0000000 --- a/docs/libs/v0/file/readJsonFile.cjs +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/readJsonFile/index.md} - */ -const readJsonFile = implementor.implementFunction("readJsonFile", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readFile(path, { encoding: "utf-8" }) - .then(JSON.parse) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-json-file", value)); - }, - DENO: (path) => Deno.readTextFile(path) - .then(JSON.parse) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-json-file", value)), - BUN: (path) => Bun.file(path) - .text() - .then(JSON.parse) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-json-file", value)), -}); - -exports.readJsonFile = readJsonFile; diff --git a/docs/libs/v0/file/readLink.cjs b/docs/libs/v0/file/readLink.cjs deleted file mode 100644 index c95b228..0000000 --- a/docs/libs/v0/file/readLink.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/readLink/index.md} - */ -const readLink = implementor.implementFunction("readLink", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readlink(path, { encoding: "utf-8" }) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-link", value)); - }, - DENO: (path) => Deno - .readLink(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-link", value)), -}); - -exports.readLink = readLink; diff --git a/docs/libs/v0/file/readTextFile.cjs b/docs/libs/v0/file/readTextFile.cjs deleted file mode 100644 index 6a61476..0000000 --- a/docs/libs/v0/file/readTextFile.cjs +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/readTextFile/index.md} - */ -const readTextFile = implementor.implementFunction("readTextFile", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readFile(path, { encoding: "utf-8" }) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-text-file", value)); - }, - DENO: (path) => Deno - .readTextFile(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-text-file", value)), - BUN: (path) => Bun.file(path) - .text() - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-read-text-file", value)), -}); - -exports.readTextFile = readTextFile; diff --git a/docs/libs/v0/file/realPath.cjs b/docs/libs/v0/file/realPath.cjs deleted file mode 100644 index fb69a0a..0000000 --- a/docs/libs/v0/file/realPath.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/realPath/index.md} - */ -const realPath = implementor.implementFunction("realPath", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.realpath(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-real-path", value)); - }, - DENO: (path) => Deno - .realPath(path) - .then(utils.E.success) - .catch((value) => utils.E.left("file-system-real-path", value)), -}); - -exports.realPath = realPath; diff --git a/docs/libs/v0/file/relocate.cjs b/docs/libs/v0/file/relocate.cjs deleted file mode 100644 index c38d70f..0000000 --- a/docs/libs/v0/file/relocate.cjs +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/relocate/index.md} - */ -const relocate = implementor.implementFunction("relocate", { - NODE: async (fromPath, newParentPath) => { - const fs = await implementor.nodeFileSystem.value; - const baseName = utils.Path.getBaseName(fromPath); - if (!baseName) { - return utils.E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); - } - const newPath = utils.Path.resolveRelative([newParentPath, baseName]); - return fs.rename(fromPath, newPath) - .then(() => utils.E.success(newPath)) - .catch((value) => utils.E.left("file-system-relocate", value)); - }, - DENO: (fromPath, newParentPath) => { - const baseName = utils.Path.getBaseName(fromPath); - if (!baseName) { - return Promise.resolve(utils.E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); - } - const newPath = utils.Path.resolveRelative([newParentPath, baseName]); - return Deno.rename(fromPath, newPath) - .then(() => utils.E.success(newPath)) - .catch((value) => utils.E.left("file-system-relocate", value)); - }, -}); - -exports.relocate = relocate; diff --git a/docs/libs/v0/file/remove.cjs b/docs/libs/v0/file/remove.cjs deleted file mode 100644 index 293e29a..0000000 --- a/docs/libs/v0/file/remove.cjs +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/remove/index.md} - */ -const remove = implementor.implementFunction("remove", { - NODE: async (path, params) => { - const fs = await implementor.nodeFileSystem.value; - return fs.rm(path, { - recursive: params?.recursive ?? false, - force: true, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-remove", value)); - }, - DENO: (path, params) => Deno.remove(path, { - recursive: params?.recursive, - }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-remove", value)), -}); - -exports.remove = remove; diff --git a/docs/libs/v0/file/rename.cjs b/docs/libs/v0/file/rename.cjs deleted file mode 100644 index 5960fb0..0000000 --- a/docs/libs/v0/file/rename.cjs +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/rename/index.md} - */ -const rename = implementor.implementFunction("rename", { - NODE: async (path, newName) => { - const fs = await implementor.nodeFileSystem.value; - const parentPath = utils.Path.getParentFolderPath(path); - if (!parentPath) { - return utils.E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); - } - if (newName.includes("/")) { - return utils.E.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); - } - const newPath = utils.Path.resolveRelative([parentPath, newName]); - return fs.rename(path, newPath) - .then(() => utils.E.success(newPath)) - .catch((value) => utils.E.left("file-system-rename", value)); - }, - DENO: (path, newName) => { - const parentPath = utils.Path.getParentFolderPath(path); - if (!parentPath) { - return Promise.resolve(utils.E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); - } - if (newName.includes("/")) { - return Promise.resolve(utils.E.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); - } - const newPath = utils.Path.resolveRelative([parentPath, newName]); - return Deno.rename(path, newPath) - .then(() => utils.E.success(newPath)) - .catch((value) => utils.E.left("file-system-rename", value)); - }, -}); - -exports.rename = rename; diff --git a/docs/libs/v0/file/setOwner.cjs b/docs/libs/v0/file/setOwner.cjs deleted file mode 100644 index dfc52b1..0000000 --- a/docs/libs/v0/file/setOwner.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/setOwner/index.md} - */ -const setOwner = implementor.implementFunction("setOwner", { - NODE: async (path, { userId, groupId }) => { - const fs = await implementor.nodeFileSystem.value; - return fs.chown(path, userId, groupId) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-owner", value)); - }, - DENO: (path, { userId, groupId }) => Deno - .chown(path, userId, groupId) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-owner", value)), -}); - -exports.setOwner = setOwner; diff --git a/docs/libs/v0/file/setTime.cjs b/docs/libs/v0/file/setTime.cjs deleted file mode 100644 index ff517e9..0000000 --- a/docs/libs/v0/file/setTime.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/setTime/index.md} - */ -const setTime = implementor.implementFunction("setTime", { - NODE: async (path, { accessTime, modifiedTime }) => { - const fs = await implementor.nodeFileSystem.value; - return fs.utimes(path, utils.D.toTimestamp(accessTime), utils.D.toTimestamp(modifiedTime)) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-time", value)); - }, - DENO: (path, { accessTime, modifiedTime }) => Deno - .utime(path, utils.D.toTimestamp(accessTime), utils.D.toTimestamp(modifiedTime)) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-set-time", value)), -}); - -exports.setTime = setTime; diff --git a/docs/libs/v0/file/setTime.mjs b/docs/libs/v0/file/setTime.mjs deleted file mode 100644 index 63d9063..0000000 --- a/docs/libs/v0/file/setTime.mjs +++ /dev/null @@ -1,20 +0,0 @@ -import { D, E } from '@duplojs/utils'; -import { implementFunction, nodeFileSystem } from '../implementor.mjs'; - -/** - * {@include file/setTime/index.md} - */ -const setTime = implementFunction("setTime", { - NODE: async (path, { accessTime, modifiedTime }) => { - const fs = await nodeFileSystem.value; - return fs.utimes(path, D.toTimestamp(accessTime), D.toTimestamp(modifiedTime)) - .then(E.ok) - .catch((value) => E.left("file-system-set-time", value)); - }, - DENO: (path, { accessTime, modifiedTime }) => Deno - .utime(path, D.toTimestamp(accessTime), D.toTimestamp(modifiedTime)) - .then(E.ok) - .catch((value) => E.left("file-system-set-time", value)), -}); - -export { setTime }; diff --git a/docs/libs/v0/file/stat.cjs b/docs/libs/v0/file/stat.cjs deleted file mode 100644 index 6b0fa6b..0000000 --- a/docs/libs/v0/file/stat.cjs +++ /dev/null @@ -1,88 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -function createStatInfoWithFsSource(source) { - return { - isFile: source.isFile(), - isDirectory: source.isDirectory(), - isSymlink: source.isSymbolicLink(), - sizeBytes: source.size, - modifiedAt: utils.D.isSafeTimestamp(source.mtime.getTime()) ? utils.D.createOrThrow(source.mtime) : null, - accessedAt: utils.D.isSafeTimestamp(source.atime.getTime()) ? utils.D.createOrThrow(source.atime) : null, - createdAt: utils.D.isSafeTimestamp(source.birthtime.getTime()) ? utils.D.createOrThrow(source.birthtime) : null, - changedAt: utils.D.isSafeTimestamp(source.ctime.getTime()) ? utils.D.createOrThrow(source.ctime) : null, - deviceId: source.dev, - inode: source.ino, - permissionsMode: source.mode, - hardLinkCount: source.nlink, - ownerUserId: source.uid, - ownerGroupId: source.gid, - specialDeviceId: source.rdev, - ioBlockSize: source.blksize, - allocatedBlockCount: source.blocks, - isBlockDevice: source.isBlockDevice(), - isCharacterDevice: source.isCharacterDevice(), - isFifo: source.isFIFO(), - isSocket: source.isSocket(), - }; -} -function createStatInfoWithDeno(source) { - return { - isFile: source.isFile, - isDirectory: source.isDirectory, - isSymlink: source.isSymlink, - sizeBytes: source.size, - modifiedAt: source.mtime - && utils.D.isSafeTimestamp(source.mtime.getTime()) - ? utils.D.createOrThrow(source.mtime) - : null, - accessedAt: source.atime - && utils.D.isSafeTimestamp(source.atime.getTime()) - ? utils.D.createOrThrow(source.atime) - : null, - createdAt: source.birthtime - && utils.D.isSafeTimestamp(source.birthtime.getTime()) - ? utils.D.createOrThrow(source.birthtime) - : null, - changedAt: source.ctime - && utils.D.isSafeTimestamp(source.ctime.getTime()) - ? utils.D.createOrThrow(source.ctime) - : null, - deviceId: source.dev, - inode: source.ino, - permissionsMode: source.mode, - hardLinkCount: source.nlink, - ownerUserId: source.uid, - ownerGroupId: source.gid, - specialDeviceId: source.rdev, - ioBlockSize: source.blksize, - allocatedBlockCount: source.blocks, - isBlockDevice: source.isBlockDevice, - isCharacterDevice: source.isCharDevice, - isFifo: source.isFifo, - isSocket: source.isSocket, - }; -} -/** - * {@include file/stat/index.md} - */ -const stat = implementor.implementFunction("stat", { - NODE: async (path) => { - const fs = await implementor.nodeFileSystem.value; - return fs.stat(path) - .then(utils.innerPipe(createStatInfoWithFsSource, utils.E.success)) - .catch((value) => utils.E.left("file-system-stat", value)); - }, - DENO: (path) => Deno - .stat(path) - .then(utils.innerPipe(createStatInfoWithDeno, utils.E.success)) - .catch((value) => utils.E.left("file-system-stat", value)), - BUN: (path) => Bun.file(path) - .stat() - .then(utils.innerPipe(createStatInfoWithFsSource, utils.E.success)) - .catch((value) => utils.E.left("file-system-stat", value)), -}); - -exports.stat = stat; diff --git a/docs/libs/v0/file/symlink.cjs b/docs/libs/v0/file/symlink.cjs deleted file mode 100644 index 86f94d5..0000000 --- a/docs/libs/v0/file/symlink.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/symlink/index.md} - */ -const symlink = implementor.implementFunction("symlink", { - NODE: async (oldPath, newPath, params) => { - const fs = await implementor.nodeFileSystem.value; - return fs.symlink(oldPath, newPath, params?.type) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-symlink", value)); - }, - DENO: (oldPath, newPath, params) => Deno - .symlink(oldPath, newPath, params) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-symlink", value)), -}); - -exports.symlink = symlink; diff --git a/docs/libs/v0/file/truncate.cjs b/docs/libs/v0/file/truncate.cjs deleted file mode 100644 index 48d9e7c..0000000 --- a/docs/libs/v0/file/truncate.cjs +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/truncate/index.md} - */ -const truncate = implementor.implementFunction("truncate", { - NODE: async (path, size) => { - const fs = await implementor.nodeFileSystem.value; - return fs.truncate(path, size) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-truncate", value)); - }, - DENO: (path, size) => utils.pipe(path, utils.when(utils.instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname)), (stringPath) => Deno - .truncate(stringPath, size) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-truncate", value))), -}); - -exports.truncate = truncate; diff --git a/docs/libs/v0/file/types/fileSystemLeft.d.ts b/docs/libs/v0/file/types/fileSystemLeft.d.ts deleted file mode 100644 index 5ca2232..0000000 --- a/docs/libs/v0/file/types/fileSystemLeft.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { E } from "@duplojs/utils"; -export type FileSystemLeft = E.Left<`file-system-${GenericName}`, unknown>; diff --git a/docs/libs/v0/file/walkDirectory.cjs b/docs/libs/v0/file/walkDirectory.cjs deleted file mode 100644 index 960110f..0000000 --- a/docs/libs/v0/file/walkDirectory.cjs +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); -var fileInterface = require('./fileInterface.cjs'); -var folderInterface = require('./folderInterface.cjs'); -var unknownInterface = require('./unknownInterface.cjs'); - -/** - * {@include file/walkDirectory/index.md} - */ -const walkDirectory = implementor.implementFunction("walkDirectory", { - NODE: async (path, params) => { - const fs = await implementor.nodeFileSystem.value; - return fs.readdir(path, { - recursive: params?.recursive ?? false, - withFileTypes: true, - }) - .then(utils.innerPipe(utils.G.map(utils.innerPipe(utils.P.when((dirent) => dirent.isFile(), ({ parentPath, name }) => fileInterface.createFileInterface(`${parentPath}/${name}`)), utils.P.when((dirent) => dirent.isDirectory(), ({ parentPath, name }) => folderInterface.createFolderInterface(`${parentPath}/${name}`)), utils.P.otherwise(({ parentPath, name }) => unknownInterface.createUnknownInterface(`${parentPath}/${name}`)))), utils.E.success)) - .catch((value) => utils.E.left("file-system-walk-directory", value)); - }, -}); - -exports.walkDirectory = walkDirectory; diff --git a/docs/libs/v0/file/walkDirectory.mjs b/docs/libs/v0/file/walkDirectory.mjs deleted file mode 100644 index 8c293bc..0000000 --- a/docs/libs/v0/file/walkDirectory.mjs +++ /dev/null @@ -1,22 +0,0 @@ -import { innerPipe, G, P, E } from '@duplojs/utils'; -import { implementFunction, nodeFileSystem } from '../implementor.mjs'; -import { createFileInterface } from './fileInterface.mjs'; -import { createFolderInterface } from './folderInterface.mjs'; -import { createUnknownInterface } from './unknownInterface.mjs'; - -/** - * {@include file/walkDirectory/index.md} - */ -const walkDirectory = implementFunction("walkDirectory", { - NODE: async (path, params) => { - const fs = await nodeFileSystem.value; - return fs.readdir(path, { - recursive: params?.recursive ?? false, - withFileTypes: true, - }) - .then(innerPipe(G.map(innerPipe(P.when((dirent) => dirent.isFile(), ({ parentPath, name }) => createFileInterface(`${parentPath}/${name}`)), P.when((dirent) => dirent.isDirectory(), ({ parentPath, name }) => createFolderInterface(`${parentPath}/${name}`)), P.otherwise(({ parentPath, name }) => createUnknownInterface(`${parentPath}/${name}`)))), E.success)) - .catch((value) => E.left("file-system-walk-directory", value)); - }, -}); - -export { walkDirectory }; diff --git a/docs/libs/v0/file/writeFile.cjs b/docs/libs/v0/file/writeFile.cjs deleted file mode 100644 index 975ec27..0000000 --- a/docs/libs/v0/file/writeFile.cjs +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/writeFile/index.md} - */ -const writeFile = implementor.implementFunction("writeFile", { - NODE: async (path, data) => { - const fs = await implementor.nodeFileSystem.value; - return fs.writeFile(path, data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-file", value)); - }, - DENO: (path, data) => Deno - .writeFile(path, data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-file", value)), - BUN: (path, data) => Bun - .file(path) - .write(data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-file", value)), -}); - -exports.writeFile = writeFile; diff --git a/docs/libs/v0/file/writeJsonFile.cjs b/docs/libs/v0/file/writeJsonFile.cjs deleted file mode 100644 index 017de44..0000000 --- a/docs/libs/v0/file/writeJsonFile.cjs +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/writeJsonFile/index.md} - */ -const writeJsonFile = implementor.implementFunction("writeJsonFile", { - NODE: async (path, data, params) => { - const fs = await implementor.nodeFileSystem.value; - return utils.pipe(utils.E.safeCallback(() => JSON.stringify(data, null, params?.space)), utils.E.whenIsRight((value) => fs.writeFile(path, value, { encoding: "utf-8" }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-json-file", value))), utils.E.whenIsLeft((value) => utils.E.left("file-system-write-json-file", value))); - }, - DENO: (path, data, params) => utils.asyncPipe(utils.E.safeCallback(() => JSON.stringify(data, null, params?.space)), utils.E.whenIsRight((value) => Deno.writeTextFile(path, value) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-json-file", value))), utils.E.whenIsLeft((value) => utils.E.left("file-system-write-json-file", value))), - BUN: (path, data, params) => utils.asyncPipe(utils.E.safeCallback(() => JSON.stringify(data, null, params?.space)), utils.E.whenIsRight((value) => Bun.file(path) - .write(value) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-json-file", value))), utils.E.whenIsLeft((value) => utils.E.left("file-system-write-json-file", value))), -}); - -exports.writeJsonFile = writeJsonFile; diff --git a/docs/libs/v0/file/writeJsonFile.mjs b/docs/libs/v0/file/writeJsonFile.mjs deleted file mode 100644 index 8a186b3..0000000 --- a/docs/libs/v0/file/writeJsonFile.mjs +++ /dev/null @@ -1,23 +0,0 @@ -import { asyncPipe, E, pipe } from '@duplojs/utils'; -import { implementFunction, nodeFileSystem } from '../implementor.mjs'; - -/** - * {@include file/writeJsonFile/index.md} - */ -const writeJsonFile = implementFunction("writeJsonFile", { - NODE: async (path, data, params) => { - const fs = await nodeFileSystem.value; - return pipe(E.safeCallback(() => JSON.stringify(data, null, params?.space)), E.whenIsRight((value) => fs.writeFile(path, value, { encoding: "utf-8" }) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value))), E.whenIsLeft((value) => E.left("file-system-write-json-file", value))); - }, - DENO: (path, data, params) => asyncPipe(E.safeCallback(() => JSON.stringify(data, null, params?.space)), E.whenIsRight((value) => Deno.writeTextFile(path, value) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value))), E.whenIsLeft((value) => E.left("file-system-write-json-file", value))), - BUN: (path, data, params) => asyncPipe(E.safeCallback(() => JSON.stringify(data, null, params?.space)), E.whenIsRight((value) => Bun.file(path) - .write(value) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value))), E.whenIsLeft((value) => E.left("file-system-write-json-file", value))), -}); - -export { writeJsonFile }; diff --git a/docs/libs/v0/file/writeTextFile.cjs b/docs/libs/v0/file/writeTextFile.cjs deleted file mode 100644 index 581a3af..0000000 --- a/docs/libs/v0/file/writeTextFile.cjs +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -var utils = require('@duplojs/utils'); -var implementor = require('../implementor.cjs'); - -/** - * {@include file/writeTextFile/index.md} - */ -const writeTextFile = implementor.implementFunction("writeTextFile", { - NODE: async (path, data) => { - const fs = await implementor.nodeFileSystem.value; - return fs.writeFile(path, data, { encoding: "utf-8" }) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-text-file", value)); - }, - DENO: (path, data) => Deno - .writeTextFile(path, data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-text-file", value)), - BUN: (path, data) => Bun - .file(path) - .write(data) - .then(utils.E.ok) - .catch((value) => utils.E.left("file-system-write-text-file", value)), -}); - -exports.writeTextFile = writeTextFile; diff --git a/docs/libs/v0/package.json b/docs/libs/v0/package.json new file mode 100644 index 0000000..43df381 --- /dev/null +++ b/docs/libs/v0/package.json @@ -0,0 +1,44 @@ +{ + "name": "v0", + "type": "module", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs", + "types": "./dist/index.d.ts" + }, + "./file": { + "import": "./dist/file/index.mjs", + "require": "./dist/file/index.cjs", + "types": "./dist/file/index.d.ts" + }, + "./common": { + "import": "./dist/common/index.mjs", + "require": "./dist/common/index.cjs", + "types": "./dist/common/index.d.ts" + }, + "./dataParser": { + "import": "./dist/dataParser/index.mjs", + "require": "./dist/dataParser/index.cjs", + "types": "./dist/dataParser/index.d.ts" + }, + "./dataParserCoerce": { + "import": "./dist/dataParser/parsers/coerce/index.mjs", + "require": "./dist/dataParser/parsers/coerce/index.cjs", + "types": "./dist/dataParser/parsers/coerce/index.d.ts" + }, + "./dataParserExtended": { + "import": "./dist/dataParser/extended/index.mjs", + "require": "./dist/dataParser/extended/index.cjs", + "types": "./dist/dataParser/extended/index.d.ts" + }, + "./command": { + "import": "./dist/command/index.mjs", + "require": "./dist/command/index.cjs", + "types": "./dist/command/index.d.ts" + } + }, + "peerDependencies": { + "@duplojs/utils": ">=1.6.5 <2.0.0" + } +} diff --git a/docs/package.json b/docs/package.json index 027a47e..eba0cba 100644 --- a/docs/package.json +++ b/docs/package.json @@ -4,13 +4,20 @@ "scripts": { "docs:dev": "vitepress dev", "docs:build": "vitepress build", - "docs:preview": "vitepress preview" + "docs:preview": "vitepress preview", + "test:types": "./.commands/test-types.sh" }, + "workspaces": [ + "libs/**" + ], "devDependencies": { "@shikijs/vitepress-twoslash": "3.21.0", + "@types/web": "^0.0.344", "@vue/tsconfig": "0.8.1", - "vitepress": "^2.0.0-alpha.15", + "vitepress": "^2.0.0-alpha.16", + "@server-utils/v0": "file:libs/v0", "vitepress-plugin-group-icons": "1.7.1", "vue": "3.5.27" } } + \ No newline at end of file diff --git a/jsDoc/command/create/example.ts b/jsDoc/command/create/example.ts index ae01bab..8b046a5 100644 --- a/jsDoc/command/create/example.ts +++ b/jsDoc/command/create/example.ts @@ -1,5 +1,5 @@ import { SC } from "@scripts"; -import { DP } from "@duplojs/utils"; +import { C, DP } from "@duplojs/utils"; const ping = SC.create( "ping", @@ -8,13 +8,17 @@ const ping = SC.create( }, ); +const UserId = C.createNewType("user-id", DP.number(), C.Positive); + const greet = SC.create( "greet", { - options: [SC.createOption("name", DP.string(), { required: true })], + options: [SC.createOption("email", C.Email)], + subject: UserId, }, - ({ options: { name } }) => { - // name: string + ({ options: { email }, subject }) => { + // email: C.Email | undefined + // subject: C.GetNewType }, ); diff --git a/jsDoc/command/create/index.md b/jsDoc/command/create/index.md index 9def702..42ae004 100644 --- a/jsDoc/command/create/index.md +++ b/jsDoc/command/create/index.md @@ -1,13 +1,13 @@ Create a command node. -Use this builder to define a command name, its optional options/subject, and the execute handler called after parsing. +Use this builder to define a command name, optional options, an optional subject, and the execute handler called after parsing. ```ts -{@include command/create/example.ts[4,36]} +{@include command/create/example.ts[4,40]} ``` @remarks -`create` supports child commands by setting `subject` to an array of commands. +`subject` can be a parser-like contract for positional arguments, or an array of child commands for nested command trees. @see https://server-utils.duplojs.dev/en/v0/api/command/create @namespace SC diff --git a/jsDoc/command/createArrayOption/example.ts b/jsDoc/command/createArrayOption/example.ts index 904d614..c9caa37 100644 --- a/jsDoc/command/createArrayOption/example.ts +++ b/jsDoc/command/createArrayOption/example.ts @@ -1,11 +1,9 @@ import { SC } from "@scripts"; -import { DP } from "@duplojs/utils"; - -const tags = SC.createArrayOption("tags", DP.string()); +import { C, DP } from "@duplojs/utils"; const ids = SC.createArrayOption( "ids", - DP.string(), + DP.number(), { required: true, min: 1, @@ -18,14 +16,22 @@ const paths = SC.createArrayOption( { separator: ";" }, ); +const UserId = C.createNewType("user-id", DP.number(), C.Positive); +const userIds = SC.createArrayOption("userIds", UserId); + +const tags = SC.createArrayOption("tags", DP.string()); +const emails = SC.createArrayOption("emails", C.Email); + SC.create( "batch", { - options: [tags, ids, paths], + options: [tags, ids, paths, emails, userIds], }, - ({ options: { ids, tags, paths } }) => { - // ids: [string, ...string[]] + ({ options: { ids, tags, paths, emails, userIds } }) => { + // ids: [number, ...number[]] // tags: string[] | undefined // paths: string[] | undefined + // emails: C.Email[] | undefined + // userIds: C.GetNewType[] | undefined }, ); diff --git a/jsDoc/command/createArrayOption/index.md b/jsDoc/command/createArrayOption/index.md index 68b1e17..910d131 100644 --- a/jsDoc/command/createArrayOption/index.md +++ b/jsDoc/command/createArrayOption/index.md @@ -1,13 +1,13 @@ Create an option that parses an array of values. -This option parses a delimited string value into an array and validates each element with the provided DataParser schema. +This option parses a delimited string value into an array and validates each element with the provided DataParser or clean contract. ```ts -{@include command/createArrayOption/example.ts[4,31]} +{@include command/createArrayOption/example.ts[4,37]} ``` @remarks -The default separator is `,`. You can customize it with `separator`. +The default separator is `,`. You can customize it with `separator`, and primitive elements are coerced from CLI string input. @see https://server-utils.duplojs.dev/en/v0/api/command/createArrayOption @namespace SC diff --git a/jsDoc/command/createOption/example.ts b/jsDoc/command/createOption/example.ts index 5d296cd..4bc2145 100644 --- a/jsDoc/command/createOption/example.ts +++ b/jsDoc/command/createOption/example.ts @@ -1,7 +1,5 @@ import { SC } from "@scripts"; -import { DP } from "@duplojs/utils"; - -const port = SC.createOption("port", DP.string()); +import { C, DP } from "@duplojs/utils"; const name = SC.createOption( "name", @@ -17,14 +15,22 @@ const mode = SC.createOption( DP.literal(["dev", "prod"]), ); +const UserId = C.createNewType("user-id", DP.number(), C.Positive); +const userId = SC.createOption("userId", UserId); + +const port = SC.createOption("port", DP.number()); +const email = SC.createOption("email", C.Email); + SC.create( "serve", { - options: [port, name, mode], + options: [port, name, mode, email, userId], }, - ({ options: { port, name, mode } }) => { - // port: string | undefined + ({ options: { port, name, mode, email, userId } }) => { + // port: number | undefined // name: string // mode: "dev" | "prod" | undefined + // email: C.Email | undefined + // userId: C.GetNewType | undefined }, ); diff --git a/jsDoc/command/createOption/index.md b/jsDoc/command/createOption/index.md index c4a987d..1d59c10 100644 --- a/jsDoc/command/createOption/index.md +++ b/jsDoc/command/createOption/index.md @@ -1,13 +1,13 @@ Create an option with a single parsed value. -Use a DataParser schema to parse and validate the option value from `--name=value` or `--name value`. +Use a DataParser or a clean contract to parse and validate the option value from `--name=value` or `--name value`. ```ts -{@include command/createOption/example.ts[4,27]} +{@include command/createOption/example.ts[4,36]} ``` @remarks -Set `required: true` to throw when the option is missing. +Primitive parsers and clean primitive contracts are coerced from CLI string input automatically. @see https://server-utils.duplojs.dev/en/v0/api/command/createOption @namespace SC diff --git a/package-lock.json b/package-lock.json index 0e6a749..ea62dc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,14 +42,25 @@ } }, "docs": { + "workspaces": [ + "libs/**" + ], "devDependencies": { + "@server-utils/v0": "file:libs/v0", "@shikijs/vitepress-twoslash": "3.21.0", + "@types/web": "^0.0.344", "@vue/tsconfig": "0.8.1", - "vitepress": "^2.0.0-alpha.15", + "vitepress": "^2.0.0-alpha.16", "vitepress-plugin-group-icons": "1.7.1", "vue": "3.5.27" } }, + "docs/libs/v0": { + "dev": true, + "peerDependencies": { + "@duplojs/utils": ">=1.6.5 <2.0.0" + } + }, "integration": { "dependencies": { "@duplojs/server-utils": "file:.." @@ -600,6 +611,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@docsearch/sidepanel-js": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/@docsearch/sidepanel-js/-/sidepanel-js-4.6.2.tgz", + "integrity": "sha512-Pni85AP/GwRj7fFg8cBJp0U04tzbueBvWSd3gysgnOsVnQVSZwSYncfErUScLE1CAtR+qocPDFjmYR9AMRNJtQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@duplojs/dev-tools": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@duplojs/dev-tools/-/dev-tools-0.2.0.tgz", @@ -1844,9 +1862,9 @@ } }, "node_modules/@iconify-json/simple-icons": { - "version": "1.2.68", - "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.68.tgz", - "integrity": "sha512-bQPl1zuZlX6AnofreA1v7J+hoPncrFMppqGboe/SH54jZO37meiBUGBqNOxEpc0HKfZGxJaVVJwZd4gdMYu3hw==", + "version": "1.2.79", + "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.79.tgz", + "integrity": "sha512-aNyO7Fd1qej9oQfIyohYFRv0lhQLaZ+6UkK1c1qwax0MDPUOZOdq65MlU500kow97pD/W+b2u1And3e25eE24Q==", "dev": true, "license": "CC0-1.0", "dependencies": { @@ -2010,9 +2028,9 @@ } }, "node_modules/@rolldown/pluginutils": { - "version": "1.0.0-beta.53", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.53.tgz", - "integrity": "sha512-vENRlFU4YbrwVqNDZ7fLvy+JR1CRkyr01jhSiDpE1u6py3OMzQfztQU2jxykW3ALNxO4kSlqIDeYyD0Y9RcQeQ==", + "version": "1.0.0-rc.13", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.13.tgz", + "integrity": "sha512-3ngTAv6F/Py35BsYbeeLeecvhMKdsKm4AoOETVhAA+Qc8nrA2I0kF7oa93mE9qnIurngOSpMnQ0x2nQY2FPviA==", "dev": true, "license": "MIT" }, @@ -2360,6 +2378,10 @@ "win32" ] }, + "node_modules/@server-utils/v0": { + "resolved": "docs/libs/v0", + "link": true + }, "node_modules/@shikijs/core": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.21.0.tgz", @@ -2417,14 +2439,38 @@ } }, "node_modules/@shikijs/transformers": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-3.21.0.tgz", - "integrity": "sha512-CZwvCWWIiRRiFk9/JKzdEooakAP8mQDtBOQ1TKiCaS2E1bYtyBCOkUzS8akO34/7ufICQ29oeSfkb3tT5KtrhA==", + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-3.23.0.tgz", + "integrity": "sha512-F9msZVxdF+krQNSdQ4V+Ja5QemeAoTQ2jxt7nJCwhDsdF1JWS3KxIQXA3lQbyKwS3J61oHRUSv4jYWv3CkaKTQ==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/core": "3.21.0", - "@shikijs/types": "3.21.0" + "@shikijs/core": "3.23.0", + "@shikijs/types": "3.23.0" + } + }, + "node_modules/@shikijs/transformers/node_modules/@shikijs/core": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.23.0.tgz", + "integrity": "sha512-NSWQz0riNb67xthdm5br6lAkvpDJRTgB36fxlo37ZzM2yq0PQFFzbd8psqC2XMPgCzo1fW6cVi18+ArJ44wqgA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4", + "hast-util-to-html": "^9.0.5" + } + }, + "node_modules/@shikijs/transformers/node_modules/@shikijs/types": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz", + "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, "node_modules/@shikijs/twoslash": { @@ -2668,6 +2714,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/web": { + "version": "0.0.344", + "resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.344.tgz", + "integrity": "sha512-5CqToBLlIpnOfqd7KDOTC5aHWvc5XykMruv1h+FGl2MHSvZIxHjxt0WKNJspoGVHf95n8e88jMBATPFBhKRyLQ==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/@types/web-bluetooth": { "version": "0.0.21", "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.21.tgz", @@ -2837,19 +2890,19 @@ "license": "ISC" }, "node_modules/@vitejs/plugin-vue": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.3.tgz", - "integrity": "sha512-TlGPkLFLVOY3T7fZrwdvKpjprR3s4fxRln0ORDo1VQ7HHyxJwTlrjKU3kpVWTlaAjIEuCTokmjkZnr8Tpc925w==", + "version": "6.0.6", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.6.tgz", + "integrity": "sha512-u9HHgfrq3AjXlysn0eINFnWQOJQLO9WN6VprZ8FXl7A2bYisv3Hui9Ij+7QZ41F/WYWarHjwBbXtD7dKg3uxbg==", "dev": true, "license": "MIT", "dependencies": { - "@rolldown/pluginutils": "1.0.0-beta.53" + "@rolldown/pluginutils": "1.0.0-rc.13" }, "engines": { "node": "^20.19.0 || >=22.12.0" }, "peerDependencies": { - "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0", "vue": "^3.2.25" } }, @@ -3214,15 +3267,15 @@ } }, "node_modules/@vueuse/core": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-14.1.0.tgz", - "integrity": "sha512-rgBinKs07hAYyPF834mDTigH7BtPqvZ3Pryuzt1SD/lg5wEcWqvwzXXYGEDb2/cP0Sj5zSvHl3WkmMELr5kfWw==", + "version": "14.2.1", + "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-14.2.1.tgz", + "integrity": "sha512-3vwDzV+GDUNpdegRY6kzpLm4Igptq+GA0QkJ3W61Iv27YWwW/ufSlOfgQIpN6FZRMG0mkaz4gglJRtq5SeJyIQ==", "dev": true, "license": "MIT", "dependencies": { "@types/web-bluetooth": "^0.0.21", - "@vueuse/metadata": "14.1.0", - "@vueuse/shared": "14.1.0" + "@vueuse/metadata": "14.2.1", + "@vueuse/shared": "14.2.1" }, "funding": { "url": "https://github.com/sponsors/antfu" @@ -3232,14 +3285,14 @@ } }, "node_modules/@vueuse/integrations": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@vueuse/integrations/-/integrations-14.1.0.tgz", - "integrity": "sha512-eNQPdisnO9SvdydTIXnTE7c29yOsJBD/xkwEyQLdhDC/LKbqrFpXHb3uS//7NcIrQO3fWVuvMGp8dbK6mNEMCA==", + "version": "14.2.1", + "resolved": "https://registry.npmjs.org/@vueuse/integrations/-/integrations-14.2.1.tgz", + "integrity": "sha512-2LIUpBi/67PoXJGqSDQUF0pgQWpNHh7beiA+KG2AbybcNm+pTGWT6oPGlBgUoDWmYwfeQqM/uzOHqcILpKL7nA==", "dev": true, "license": "MIT", "dependencies": { - "@vueuse/core": "14.1.0", - "@vueuse/shared": "14.1.0" + "@vueuse/core": "14.2.1", + "@vueuse/shared": "14.2.1" }, "funding": { "url": "https://github.com/sponsors/antfu" @@ -3249,7 +3302,7 @@ "axios": "^1", "change-case": "^5", "drauu": "^0.4", - "focus-trap": "^7", + "focus-trap": "^7 || ^8", "fuse.js": "^7", "idb-keyval": "^6", "jwt-decode": "^4", @@ -3299,9 +3352,9 @@ } }, "node_modules/@vueuse/metadata": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@vueuse/metadata/-/metadata-14.1.0.tgz", - "integrity": "sha512-7hK4g015rWn2PhKcZ99NyT+ZD9sbwm7SGvp7k+k+rKGWnLjS/oQozoIZzWfCewSUeBmnJkIb+CNr7Zc/EyRnnA==", + "version": "14.2.1", + "resolved": "https://registry.npmjs.org/@vueuse/metadata/-/metadata-14.2.1.tgz", + "integrity": "sha512-1ButlVtj5Sb/HDtIy1HFr1VqCP4G6Ypqt5MAo0lCgjokrk2mvQKsK2uuy0vqu/Ks+sHfuHo0B9Y9jn9xKdjZsw==", "dev": true, "license": "MIT", "funding": { @@ -3309,9 +3362,9 @@ } }, "node_modules/@vueuse/shared": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@vueuse/shared/-/shared-14.1.0.tgz", - "integrity": "sha512-EcKxtYvn6gx1F8z9J5/rsg3+lTQnvOruQd8fUecW99DCK04BkWD7z5KQ/wTAx+DazyoEE9dJt/zV8OIEQbM6kw==", + "version": "14.2.1", + "resolved": "https://registry.npmjs.org/@vueuse/shared/-/shared-14.2.1.tgz", + "integrity": "sha512-shTJncjV9JTI4oVNyF1FQonetYAiTBd+Qj7cY89SWbXSkx7gyhrgtEdF2ZAVWS1S3SHlaROO6F2IesJxQEkZBw==", "dev": true, "license": "MIT", "funding": { @@ -4817,9 +4870,9 @@ } }, "node_modules/focus-trap": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.8.0.tgz", - "integrity": "sha512-/yNdlIkpWbM0ptxno3ONTuf+2g318kh2ez3KSeZN5dZ8YC6AAmgeWz+GasYYiBJPFaYcSAPeu4GfhUaChzIJXA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-8.1.0.tgz", + "integrity": "sha512-T65crff26CKV2CZ3csg5y05r+560srp0b8EbAif35euW58hzklVf/Gb4Q+/HCtB8e9III3QFEyk5BWV5XJuOyw==", "dev": true, "license": "MIT", "dependencies": { @@ -8638,9 +8691,9 @@ } }, "node_modules/vite": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.0.tgz", - "integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==", + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.2.tgz", + "integrity": "sha512-Bby3NOsna2jsjfLVOHKes8sGwgl4TT0E6vvpYgnAYDIF/tie7MRaFthmKuHx1NSXjiTueXH3do80FMQgvEktRg==", "dev": true, "license": "MIT", "dependencies": { @@ -8756,30 +8809,31 @@ } }, "node_modules/vitepress": { - "version": "2.0.0-alpha.15", - "resolved": "https://registry.npmjs.org/vitepress/-/vitepress-2.0.0-alpha.15.tgz", - "integrity": "sha512-jhjSYd10Z6RZiKOa7jy0xMVf5NB5oSc/lS3bD/QoUc6V8PrvQR5JhC9104NEt6+oTGY/ftieVWxY9v7YI+1IjA==", + "version": "2.0.0-alpha.17", + "resolved": "https://registry.npmjs.org/vitepress/-/vitepress-2.0.0-alpha.17.tgz", + "integrity": "sha512-Z3VPUpwk/bHYqt1uMVOOK1/4xFiWQov1GNc2FvMdz6kvje4JRXEOngVI9C+bi5jeedMSHiA4dwKkff1NCvbZ9Q==", "dev": true, "license": "MIT", "dependencies": { - "@docsearch/css": "^4.3.2", - "@docsearch/js": "^4.3.2", - "@iconify-json/simple-icons": "^1.2.59", - "@shikijs/core": "^3.15.0", - "@shikijs/transformers": "^3.15.0", - "@shikijs/types": "^3.15.0", + "@docsearch/css": "^4.5.3", + "@docsearch/js": "^4.5.3", + "@docsearch/sidepanel-js": "^4.5.3", + "@iconify-json/simple-icons": "^1.2.69", + "@shikijs/core": "^3.22.0", + "@shikijs/transformers": "^3.22.0", + "@shikijs/types": "^3.22.0", "@types/markdown-it": "^14.1.2", - "@vitejs/plugin-vue": "^6.0.1", + "@vitejs/plugin-vue": "^6.0.4", "@vue/devtools-api": "^8.0.5", - "@vue/shared": "^3.5.24", - "@vueuse/core": "^14.0.0", - "@vueuse/integrations": "^14.0.0", - "focus-trap": "^7.6.6", + "@vue/shared": "^3.5.27", + "@vueuse/core": "^14.2.0", + "@vueuse/integrations": "^14.2.0", + "focus-trap": "^8.0.0", "mark.js": "8.11.1", "minisearch": "^7.2.0", - "shiki": "^3.15.0", - "vite": "^7.2.2", - "vue": "^3.5.24" + "shiki": "^3.22.0", + "vite": "^7.3.1", + "vue": "^3.5.27" }, "bin": { "vitepress": "bin/vitepress.js" @@ -8821,6 +8875,90 @@ } } }, + "node_modules/vitepress/node_modules/@shikijs/core": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.23.0.tgz", + "integrity": "sha512-NSWQz0riNb67xthdm5br6lAkvpDJRTgB36fxlo37ZzM2yq0PQFFzbd8psqC2XMPgCzo1fW6cVi18+ArJ44wqgA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4", + "hast-util-to-html": "^9.0.5" + } + }, + "node_modules/vitepress/node_modules/@shikijs/engine-javascript": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.23.0.tgz", + "integrity": "sha512-aHt9eiGFobmWR5uqJUViySI1bHMqrAgamWE1TYSUoftkAeCCAiGawPMwM+VCadylQtF4V3VNOZ5LmfItH5f3yA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2", + "oniguruma-to-es": "^4.3.4" + } + }, + "node_modules/vitepress/node_modules/@shikijs/engine-oniguruma": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.23.0.tgz", + "integrity": "sha512-1nWINwKXxKKLqPibT5f4pAFLej9oZzQTsby8942OTlsJzOBZ0MWKiwzMsd+jhzu8YPCHAswGnnN1YtQfirL35g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2" + } + }, + "node_modules/vitepress/node_modules/@shikijs/langs": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.23.0.tgz", + "integrity": "sha512-2Ep4W3Re5aB1/62RSYQInK9mM3HsLeB91cHqznAJMuylqjzNVAVCMnNWRHFtcNHXsoNRayP9z1qj4Sq3nMqYXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0" + } + }, + "node_modules/vitepress/node_modules/@shikijs/themes": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.23.0.tgz", + "integrity": "sha512-5qySYa1ZgAT18HR/ypENL9cUSGOeI2x+4IvYJu4JgVJdizn6kG4ia5Q1jDEOi7gTbN4RbuYtmHh0W3eccOrjMA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.23.0" + } + }, + "node_modules/vitepress/node_modules/@shikijs/types": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz", + "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } + }, + "node_modules/vitepress/node_modules/shiki": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-3.23.0.tgz", + "integrity": "sha512-55Dj73uq9ZXL5zyeRPzHQsK7Nbyt6Y10k5s7OjuFZGMhpp4r/rsLBH0o/0fstIzX1Lep9VxefWljK/SKCzygIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/core": "3.23.0", + "@shikijs/engine-javascript": "3.23.0", + "@shikijs/engine-oniguruma": "3.23.0", + "@shikijs/langs": "3.23.0", + "@shikijs/themes": "3.23.0", + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } + }, "node_modules/vitest": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.2.4.tgz", diff --git a/package.json b/package.json index 3f325a3..73c097b 100644 --- a/package.json +++ b/package.json @@ -13,15 +13,14 @@ }, "scripts": { "build": "rollup --config", - "test:tu": "vitest --coverage", - "test:tu:bench": "vitest bench", - "test:tu:watch": "vitest --coverage --watch", - "test:tu:update": "vitest --coverage --update", + "test:tu": "./.commands/test-tu.sh", + "test:tu:watch": "./.commands/test-tu.sh --watch", + "test:tu:update": "./.commands/test-tu.sh --update", "test:integration:bun": "bun test integration/bun", "test:integration:deno": "deno test -P -c integration/deno/deno.json integration/deno", - "test:types": "tsc -p tsconfig.test.json", - "test:lint": "eslint --quiet", - "test:lint:fix": "eslint --fix --quiet", + "test:types": "./.commands/test-types.sh", + "test:lint": "./.commands/test-lint.sh", + "test:lint:fix": "./.commands/test-lint.sh --fix", "docs:dev": "npm -w docs run docs:dev", "docs:build": "npm -w docs run docs:build", "docs:preview": "npm -w docs run docs:preview", diff --git a/scripts/command/create.ts b/scripts/command/create.ts index 86c19c8..09589ce 100644 --- a/scripts/command/create.ts +++ b/scripts/command/create.ts @@ -1,17 +1,18 @@ -import { type SimplifyTopLevel, type Kind, type AnyFunction, type RemoveKind, unwrap, type MaybePromise } from "@duplojs/utils"; +import { hasSomeKinds, type SimplifyTopLevel, type Kind, type AnyFunction, type RemoveKind, unwrap, type MaybePromise } from "@duplojs/utils"; import * as AA from "@duplojs/utils/array"; import * as OO from "@duplojs/utils/object"; import * as DDP from "@duplojs/utils/dataParser"; import * as EE from "@duplojs/utils/either"; +import * as CC from "@duplojs/utils/clean"; import { createBooleanOption, type Option } from "./options"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; -import type { EligibleDataParser } from "./types"; +import type { EligibleCleanType, EligibleContract, EligibleDataParser, ComputeEligibleCleanType } from "./types"; import { exitProcess } from "@scripts/common/exitProcess"; import { addIssue, addDataParserError, createError, interpretCommandError, popErrorPath, setErrorPath, SymbolCommandError, type CommandError } from "./error"; import { logCommandHelp } from "./help"; export type Subject = ( - | EligibleDataParser + | EligibleContract | DDP.DataParserArray< SimplifyTopLevel< & Omit @@ -36,6 +37,70 @@ export type Subject = ( > ); +type ComputeSubject< + GenericSubject extends Subject, +> = [GenericSubject] extends [DDP.DataParser] + ? DDP.Output + : [GenericSubject] extends [EligibleCleanType] + ? ComputeEligibleCleanType + : never; + +function commandSubjectToDataParser(contract: Subject): DDP.DataParser { + if ( + hasSomeKinds(contract, [ + DDP.stringKind, + DDP.numberKind, + DDP.bigIntKind, + DDP.dateKind, + DDP.timeKind, + DDP.nilKind, + ]) + ) { + const clone = contract.clone(); + + (clone.definition.coerce as any) = true; + + return clone; + } + + if (DDP.identifier(contract, DDP.arrayKind)) { + return DDP.array( + commandSubjectToDataParser(contract.definition.element), + contract.definition, + ); + } + + if (DDP.identifier(contract, DDP.tupleKind)) { + return DDP.tuple( + contract.definition.shape.map( + (part) => commandSubjectToDataParser(part), + ) as [DDP.DataParser, ...DDP.DataParser[]], + { + ...contract.definition, + rest: contract.definition.rest + ? commandSubjectToDataParser(contract.definition.rest) + : undefined, + }, + ); + } + + if (DDP.identifier(contract, DDP.dataParserKind)) { + return contract; + } + + return ( + CC.toMapDataParser as ( + innerContract: unknown, + params?: { + coerce?: boolean; + }, + ) => DDP.Contract + )( + contract, + { coerce: true }, + ); +} + function printError(commandError: CommandError, error?: CommandError): SymbolCommandError { if (!error) { // eslint-disable-next-line no-console @@ -84,7 +149,7 @@ export interface CreateCommandExecuteParams< SymbolCommandError >["result"] }; - subject: DDP.Output; + subject: ComputeSubject; } /** @@ -116,12 +181,19 @@ export function create( ? [args[0], {}, args[1]] : args; + const subject = ( + params.subject + && !(params.subject instanceof Array) + ? commandSubjectToDataParser(params.subject) + : params.subject + ) ?? null; + const self: Command = commandKind.setTo( { name, description: params.description ?? null, options: params.options ?? [], - subject: params.subject ?? null, + subject: subject as Command["subject"], execute: async(args, error?) => { const commandError = error ?? createError(self.name); const pathIndex = commandError.currentCommandPath.length; @@ -227,7 +299,9 @@ export function create( return printError(commandError, error); } - const subjectResult = self.subject.parse(commandOptions.restArgs); + const subjectResult = self.subject.parse( + commandOptions.restArgs[0], + ); if (EE.isLeft(subjectResult)) { addDataParserError( diff --git a/scripts/command/options/array.ts b/scripts/command/options/array.ts index 43400e5..acd4ade 100644 --- a/scripts/command/options/array.ts +++ b/scripts/command/options/array.ts @@ -1,10 +1,12 @@ -import { pipe, unwrap } from "@duplojs/utils"; +import { hasSomeKinds, pipe, unwrap } from "@duplojs/utils"; import * as SS from "@duplojs/utils/string"; import * as DDP from "@duplojs/utils/dataParser"; import type * as AA from "@duplojs/utils/array"; import * as EE from "@duplojs/utils/either"; +import * as CC from "@duplojs/utils/clean"; import { initOption, type Option } from "./base"; -import type { EligibleDataParser } from "../types"; +import type { EligibleContract } from "../types"; +import type { ComputeOptionContract } from "./types"; import { addIssue, addDataParserError } from "../error"; const defaultSeparator = ","; @@ -14,11 +16,11 @@ const defaultSeparator = ","; */ export function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number, >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string; aliases?: readonly string[]; @@ -31,20 +33,20 @@ export function createArrayOption< GenericName, [ ...AA.CreateTuple< - DDP.Output, + ComputeOptionContract, GenericMinValues >, - ...DDP.Output[], + ...ComputeOptionContract[], ] >; export function createArrayOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, GenericMinValues extends number, >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string; aliases?: readonly string[]; @@ -56,17 +58,17 @@ export function createArrayOption< GenericName, | [ ...AA.CreateTuple< - DDP.Output, + ComputeOptionContract, GenericMinValues >, - ...DDP.Output[], + ...ComputeOptionContract[], ] | undefined >; export function createArrayOption( name: string, - schema: DDP.DataParser, + contract: EligibleContract, params?: { description?: string; aliases?: readonly string[]; @@ -76,8 +78,43 @@ export function createArrayOption( separator?: string; }, ) { + let computeDataParser: DDP.Contract | undefined = undefined; + + if ( + hasSomeKinds(contract, [ + DDP.stringKind, + DDP.numberKind, + DDP.bigIntKind, + DDP.dateKind, + DDP.timeKind, + DDP.nilKind, + ]) + ) { + const clone = contract.clone(); + + (clone.definition.coerce as any) = true; + + computeDataParser = clone; + } else if ( + DDP.identifier(contract, DDP.dataParserKind) + ) { + computeDataParser = contract; + } else { + computeDataParser = ( + CC.toMapDataParser as ( + contract: unknown, + params?: { + coerce?: boolean; + }, + ) => DDP.Contract + )( + contract, + { coerce: true }, + ); + } + const dataParser = pipe( - schema, + computeDataParser, DDP.array, (schema) => params?.min ? schema.addChecker(DDP.checkerArrayMin(params.min)) diff --git a/scripts/command/options/index.ts b/scripts/command/options/index.ts index d8fce72..acc0512 100644 --- a/scripts/command/options/index.ts +++ b/scripts/command/options/index.ts @@ -1,4 +1,5 @@ export * from "./base"; +export * from "./types"; export * from "./boolean"; export * from "./simple"; diff --git a/scripts/command/options/simple.ts b/scripts/command/options/simple.ts index e1f01cc..d23f8ed 100644 --- a/scripts/command/options/simple.ts +++ b/scripts/command/options/simple.ts @@ -1,8 +1,10 @@ -import { unwrap } from "@duplojs/utils"; -import * as EE from "@duplojs/utils/either"; +import { hasSomeKinds, unwrap } from "@duplojs/utils"; import * as DDP from "@duplojs/utils/dataParser"; +import * as EE from "@duplojs/utils/either"; +import * as CC from "@duplojs/utils/clean"; import { initOption, type Option } from "./base"; -import type { EligibleDataParser } from "../types"; +import type { EligibleContract } from "../types"; +import type { ComputeOptionContract } from "./types"; import { addIssue, addDataParserError } from "../error"; /** @@ -10,41 +12,78 @@ import { addIssue, addDataParserError } from "../error"; */ export function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract, >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params: { description?: string; aliases?: readonly string[]; required: true; }, -): Option>; +): Option; export function createOption< GenericName extends string, - GenericSchema extends EligibleDataParser, + GenericContract extends EligibleContract, + GenericOutput extends ComputeOptionContract = ComputeOptionContract, >( name: GenericName, - schema: GenericSchema, + contract: GenericContract, params?: { description?: string; aliases?: readonly string[]; }, -): Option | undefined>; +): Option; export function createOption( name: string, - schema: DDP.DataParser, + contract: EligibleContract, params?: { description?: string; aliases?: readonly string[]; required?: true; }, -) { +): any { + let computeDataParser: DDP.Contract | undefined = undefined; + + if ( + hasSomeKinds(contract, [ + DDP.stringKind, + DDP.numberKind, + DDP.bigIntKind, + DDP.dateKind, + DDP.timeKind, + DDP.nilKind, + ]) + ) { + const clone = contract.clone(); + + (clone.definition.coerce as any) = true; + + computeDataParser = clone; + } else if ( + DDP.identifier(contract, DDP.dataParserKind) + ) { + computeDataParser = contract; + } else { + computeDataParser = ( + CC.toMapDataParser as ( + contract: unknown, + params?: { + coerce?: boolean; + }, + ) => DDP.Contract + )( + contract, + { coerce: true }, + ); + } + const dataParser = params?.required - ? schema - : DDP.optional(schema); + ? computeDataParser + : DDP.optional(computeDataParser); return initOption( name, diff --git a/scripts/command/options/types/computeOptionContract.ts b/scripts/command/options/types/computeOptionContract.ts new file mode 100644 index 0000000..aae53fe --- /dev/null +++ b/scripts/command/options/types/computeOptionContract.ts @@ -0,0 +1,10 @@ +import type * as DDP from "@duplojs/utils/dataParser"; +import type { ComputeEligibleCleanType, EligibleCleanType, EligibleContract } from "../../types"; + +export type ComputeOptionContract< + GenericContract extends EligibleContract, +> = [GenericContract] extends [DDP.DataParser] + ? DDP.Output + : [GenericContract] extends [EligibleCleanType] + ? ComputeEligibleCleanType + : never; diff --git a/scripts/command/options/types/index.ts b/scripts/command/options/types/index.ts new file mode 100644 index 0000000..7f7edc8 --- /dev/null +++ b/scripts/command/options/types/index.ts @@ -0,0 +1 @@ +export * from "./computeOptionContract"; diff --git a/scripts/command/types/eligibleCleanType.ts b/scripts/command/types/eligibleCleanType.ts new file mode 100644 index 0000000..691d409 --- /dev/null +++ b/scripts/command/types/eligibleCleanType.ts @@ -0,0 +1,32 @@ +import type { AnyTuple } from "@duplojs/utils"; +import type * as CC from "@duplojs/utils/clean"; +import type * as DD from "@duplojs/utils/date"; + +export type EligiblePrimitive = string | number | boolean | bigint | DD.TheDate | DD.TheTime; + +export type EligibleEntityProperty = ( + | CC.NewTypeHandler + | CC.EntityPropertyDefinitionUnion> + | CC.EntityPropertyDefinitionNullable + | CC.EntityPropertyDefinitionArray + | CC.EntityPropertyDefinitionIdentifier +); + +export type EligibleCleanType = ( + | CC.ConstraintHandler + | CC.ConstraintsSetHandler + | CC.PrimitiveHandler + | EligibleEntityProperty +); + +export type ComputeEligibleCleanType< + GenericSubject extends EligibleCleanType, +> = [GenericSubject] extends [CC.ConstraintHandler] + ? CC.GetConstraint + : [GenericSubject] extends [CC.ConstraintsSetHandler] + ? CC.GetConstraints + : [GenericSubject] extends [CC.PrimitiveHandler] + ? ReturnType + : [GenericSubject] extends [EligibleEntityProperty] + ? CC.EntityProperty + : never; diff --git a/scripts/command/types/eligibleContract.ts b/scripts/command/types/eligibleContract.ts new file mode 100644 index 0000000..d805c0c --- /dev/null +++ b/scripts/command/types/eligibleContract.ts @@ -0,0 +1,7 @@ +import type { EligibleCleanType } from "./eligibleCleanType"; +import type { EligibleDataParser } from "./eligibleDataParser"; + +export type EligibleContract = ( + | EligibleDataParser + | EligibleCleanType +); diff --git a/scripts/command/types/eligibleDataParser.ts b/scripts/command/types/eligibleDataParser.ts index e3c84b1..e379ed0 100644 --- a/scripts/command/types/eligibleDataParser.ts +++ b/scripts/command/types/eligibleDataParser.ts @@ -1,59 +1,25 @@ -import type { DP, SimplifyTopLevel } from "@duplojs/utils"; +import type { SimplifyTopLevel } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; export type EligibleDataParser = ( - | DP.DataParserString - | DP.DataParserNumber< + | DDP.DataParserString + | DDP.DataParserNumber + | DDP.DataParserBigInt + | DDP.DataParserDate + | DDP.DataParserTime + | DDP.DataParserNil + | DDP.DataParserTemplateLiteral + | DDP.DataParserLiteral< SimplifyTopLevel< - & Omit - & { - readonly coerce: true; - } - > - > - | DP.DataParserBigInt< - SimplifyTopLevel< - & Omit - & { - readonly coerce: true; - } - > - > - | DP.DataParserDate< - SimplifyTopLevel< - & Omit - & { - readonly coerce: true; - } - > - > - | DP.DataParserTime< - SimplifyTopLevel< - & Omit - & { - readonly coerce: true; - } - > - > - | DP.DataParserLiteral< - SimplifyTopLevel< - & Omit + & Omit & { readonly value: readonly string[]; } > > - | DP.DataParserNil< - SimplifyTopLevel< - & Omit - & { - readonly coerce: true; - } - > - > - | DP.DataParserTemplateLiteral - | DP.DataParserUnion< + | DDP.DataParserUnion< SimplifyTopLevel< - & Omit + & Omit & { readonly options: readonly [ EligibleDataParser, @@ -62,26 +28,26 @@ export type EligibleDataParser = ( } > > - | DP.DataParserTransform< + | DDP.DataParserTransform< SimplifyTopLevel< - & Omit + & Omit & { readonly inner: EligibleDataParser; } > > - | DP.DataParserPipe< + | DDP.DataParserPipe< SimplifyTopLevel< - & Omit + & Omit & { readonly input: EligibleDataParser; readonly output: EligibleDataParser; } > > - | DP.DataParserOptional< + | DDP.DataParserOptional< SimplifyTopLevel< - & Omit + & Omit & { readonly inner: EligibleDataParser; } diff --git a/scripts/command/types/index.ts b/scripts/command/types/index.ts index 9ef3554..d02bdc3 100644 --- a/scripts/command/types/index.ts +++ b/scripts/command/types/index.ts @@ -1 +1,3 @@ export * from "./eligibleDataParser"; +export * from "./eligibleCleanType"; +export * from "./eligibleContract"; diff --git a/scripts/common/environmentVariable/expandEnvironmentVariables.ts b/scripts/common/environmentVariable/expandEnvironmentVariables.ts index 84eb591..2288ff7 100644 --- a/scripts/common/environmentVariable/expandEnvironmentVariables.ts +++ b/scripts/common/environmentVariable/expandEnvironmentVariables.ts @@ -1,4 +1,6 @@ -import { G, O, S } from "@duplojs/utils"; +import * as GG from "@duplojs/utils/generator"; +import * as OO from "@duplojs/utils/object"; +import * as SS from "@duplojs/utils/string"; const envVarRegex = /(?[^{}]+)}/g; const escapedDollarRegex = /\\\$/g; @@ -8,7 +10,7 @@ export function expandValue( env: Record, stack = new Set(), ): string { - return S.replace( + return SS.replace( value, envVarRegex, ({ namedGroups }) => { @@ -32,13 +34,13 @@ export function expandValue( } export function expandEnvironmentVariables(env: Record) { - return G.reduce( - O.entries(env), - G.reduceFrom>(env), + return GG.reduce( + OO.entries(env), + GG.reduceFrom>(env), ({ element: [key, value], lastValue, nextWithObject }) => nextWithObject( lastValue, { - [key]: S.replaceAll( + [key]: SS.replaceAll( expandValue(value, lastValue), escapedDollarRegex, "$", diff --git a/scripts/common/environmentVariable/overrideEnvironmentVariables.ts b/scripts/common/environmentVariable/overrideEnvironmentVariables.ts index d9b9e6b..6dd1ae6 100644 --- a/scripts/common/environmentVariable/overrideEnvironmentVariables.ts +++ b/scripts/common/environmentVariable/overrideEnvironmentVariables.ts @@ -1,4 +1,6 @@ -import { A, O, pipe } from "@duplojs/utils"; +import { pipe } from "@duplojs/utils"; +import * as OO from "@duplojs/utils/object"; +import * as AA from "@duplojs/utils/array"; export function overrideEnvironmentVariables( arrayEnv: Record[], @@ -6,11 +8,11 @@ export function overrideEnvironmentVariables( ) { return pipe( arrayEnv, - A.map(O.entries), - A.flat, + AA.map(OO.entries), + AA.flat, (entries) => override ? entries - : A.reverse(entries), - O.fromEntries, + : AA.reverse(entries), + OO.fromEntries, ); } diff --git a/scripts/common/environmentVariable/parseEnvironmentFiles.ts b/scripts/common/environmentVariable/parseEnvironmentFiles.ts index ecff92c..d976839 100644 --- a/scripts/common/environmentVariable/parseEnvironmentFiles.ts +++ b/scripts/common/environmentVariable/parseEnvironmentFiles.ts @@ -1,4 +1,7 @@ -import { E, G, innerPipe, pipe, S, when } from "@duplojs/utils"; +import { innerPipe, pipe, when } from "@duplojs/utils"; +import * as GG from "@duplojs/utils/generator"; +import * as SS from "@duplojs/utils/string"; +import * as EE from "@duplojs/utils/either"; import * as SF from "@scripts/file"; const lineRegex = /^(?:export\s+)?(?[A-Z_][A-Z0-9_]*)=(?'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|`(?:\\`|[^`])*`|[^\s#\r\n][^#\r\n]*|)\s*(?:#.*)?$/mg; @@ -10,10 +13,10 @@ const newLineRegex = /\\n/g; export function parseEnvironmentLine(line: string) { return pipe( line, - S.replace(endLineBreakerRegex, "\n"), - S.extractAll(lineRegex), - G.reduce( - G.reduceFrom>({}), + SS.replace(endLineBreakerRegex, "\n"), + SS.extractAll(lineRegex), + GG.reduce( + GG.reduceFrom>({}), ({ element, nextWithObject, lastValue, next }) => { if (element.namedGroups?.key && element.namedGroups?.value) { return nextWithObject( @@ -22,13 +25,13 @@ export function parseEnvironmentLine(line: string) { [element.namedGroups.key]: pipe( element.namedGroups.value, (value) => { - const surroundingValue = S.replace(value, surroundingQuoteRegex, "$2"); + const surroundingValue = SS.replace(value, surroundingQuoteRegex, "$2"); - if (S.startsWith(value, "\"")) { + if (SS.startsWith(value, "\"")) { return pipe( surroundingValue, - S.replace(newLineRegex, "\n"), - S.replace(backCartRegex, "\r"), + SS.replace(newLineRegex, "\n"), + SS.replace(backCartRegex, "\r"), ); } @@ -48,21 +51,21 @@ export function parseEnvironmentFiles( baseEnv: Record, paths: string[], ) { - return G.asyncReduce( + return GG.asyncReduce( paths, - G.reduceFrom[]>([baseEnv]), + GG.reduceFrom[]>([baseEnv]), ({ lastValue, element, nextPush, exit }) => SF .readTextFile(element) .then( innerPipe( - E.whenIsRight( + EE.whenIsRight( innerPipe( parseEnvironmentLine, (value) => nextPush(lastValue, value), ), ), when( - E.isLeft, + EE.isLeft, exit, ), ), diff --git a/scripts/common/environmentVariableOrThrow.ts b/scripts/common/environmentVariableOrThrow.ts index e94fd87..e7ab371 100644 --- a/scripts/common/environmentVariableOrThrow.ts +++ b/scripts/common/environmentVariableOrThrow.ts @@ -1,4 +1,6 @@ -import { type DP, E, kindHeritage, unwrap } from "@duplojs/utils"; +import { kindHeritage, unwrap } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import type * as DDP from "@duplojs/utils/dataParser"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; import type * as SF from "@scripts/file"; import { type EnvironmentVariableParams, environmentVariable } from "./environmentVariable"; @@ -9,7 +11,7 @@ export class EnvironmentVariableError extends kindHeritage( Error, ) { public constructor( - public error: SF.FileSystemLeft<"read-text-file"> | E.Error, + public error: SF.FileSystemLeft<"read-text-file"> | EE.Error, ) { super({}, ["Failed to load environment variables: one env file could not be read or parsed values do not match the provided schema."]); } @@ -19,14 +21,14 @@ export class EnvironmentVariableError extends kindHeritage( * {@include common/environmentVariableOrThrow/index.md} */ export async function environmentVariableOrThrow< - GenericShape extends DP.DataParserObjectShape, + GenericShape extends DDP.DataParserObjectShape, >( shape: GenericShape, params?: EnvironmentVariableParams, -): Promise> { +): Promise> { const result = await environmentVariable(shape, params); - if (E.isLeft(result)) { + if (EE.isLeft(result)) { throw new EnvironmentVariableError(result); } diff --git a/scripts/common/getCurrentWorkDirectory.ts b/scripts/common/getCurrentWorkDirectory.ts index 4ac06b5..3127c52 100644 --- a/scripts/common/getCurrentWorkDirectory.ts +++ b/scripts/common/getCurrentWorkDirectory.ts @@ -1,9 +1,10 @@ -import { E, pipe } from "@duplojs/utils"; +import { pipe } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction } from "@scripts/implementor"; declare module "@scripts/implementor" { interface ServerUtilsFunction { - getCurrentWorkDirectory(): E.Error | E.Success; + getCurrentWorkDirectory(): EE.Error | EE.Success; getCurrentWorkDirectoryOrThrow(): string; } } @@ -15,12 +16,12 @@ export const getCurrentWorkDirectory = implementFunction( "getCurrentWorkDirectory", { NODE: () => pipe( - E.safeCallback(() => E.success(process.cwd())), - E.whenIsLeft(E.error), + EE.safeCallback(() => EE.success(process.cwd())), + EE.whenIsLeft(EE.error), ), DENO: () => pipe( - E.safeCallback(() => E.success(Deno.cwd())), - E.whenIsLeft(E.error), + EE.safeCallback(() => EE.success(Deno.cwd())), + EE.whenIsLeft(EE.error), ), }, ); diff --git a/scripts/common/setCurrentWorkingDirectory.ts b/scripts/common/setCurrentWorkingDirectory.ts index 6dfcdb5..16f51d2 100644 --- a/scripts/common/setCurrentWorkingDirectory.ts +++ b/scripts/common/setCurrentWorkingDirectory.ts @@ -1,11 +1,13 @@ -import { E, instanceOf, P, pipe, when } from "@duplojs/utils"; +import { instanceOf, pipe, when } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as PP from "@duplojs/utils/pattern"; import { implementFunction } from "@scripts/implementor"; declare module "@scripts/implementor" { interface ServerUtilsFunction { setCurrentWorkingDirectory< GenericPath extends string, - >(path: GenericPath): E.Fail | E.Ok; + >(path: GenericPath): EE.Fail | EE.Ok; } } @@ -21,12 +23,12 @@ export const setCurrentWorkingDirectory = implementFunction( instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname), ), - (path) => E.safeCallback(() => void process.chdir(path)), - P.when( - E.isLeft, - E.fail, + (path) => EE.safeCallback(() => void process.chdir(path)), + PP.when( + EE.isLeft, + EE.fail, ), - P.otherwise(E.ok), + PP.otherwise(EE.ok), ), DENO: (path: string) => pipe( path, @@ -34,12 +36,12 @@ export const setCurrentWorkingDirectory = implementFunction( instanceOf(URL), ({ pathname }) => decodeURIComponent(pathname), ), - (path) => E.safeCallback(() => void Deno.chdir(path)), - P.when( - E.isLeft, - E.fail, + (path) => EE.safeCallback(() => void Deno.chdir(path)), + PP.when( + EE.isLeft, + EE.fail, ), - P.otherwise(E.ok), + PP.otherwise(EE.ok), ), }, ); diff --git a/scripts/common/setCurrentWorkingDirectoryOrThrow.ts b/scripts/common/setCurrentWorkingDirectoryOrThrow.ts index d4f3094..8ce6e9f 100644 --- a/scripts/common/setCurrentWorkingDirectoryOrThrow.ts +++ b/scripts/common/setCurrentWorkingDirectoryOrThrow.ts @@ -1,4 +1,5 @@ -import { E, kindHeritage } from "@duplojs/utils"; +import { kindHeritage } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; import { setCurrentWorkingDirectory } from "./setCurrentWorkingDirectory"; @@ -22,7 +23,7 @@ export function setCurrentWorkingDirectoryOrThrow< ): void { const result = setCurrentWorkingDirectory(path); - if (E.isLeft(result)) { + if (EE.isLeft(result)) { throw new SetCurrentWorkingDirectoryError(); } diff --git a/scripts/dataParser/extended/coerce/file.ts b/scripts/dataParser/extended/coerce/file.ts index ff92ff3..cfb5593 100644 --- a/scripts/dataParser/extended/coerce/file.ts +++ b/scripts/dataParser/extended/coerce/file.ts @@ -1,7 +1,8 @@ +import type { NeverCoalescing } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; import type * as dataParsers from "../../parsers"; import * as dataParsersExtended from ".."; -import { type DP, type NeverCoalescing } from "@duplojs/utils"; export function file< const GenericDefinition extends Omit< @@ -12,7 +13,7 @@ export function file< params?: dataParsers.DataParserFileParams, definition?: GenericDefinition, ): dataParsersExtended.DataParserFileExtended< - DP.MergeDefinition< + DDP.MergeDefinition< dataParsers.DataParserDefinitionFile, NeverCoalescing & { coerce: true } > diff --git a/scripts/dataParser/extended/file.ts b/scripts/dataParser/extended/file.ts index e2d44ca..e702815 100644 --- a/scripts/dataParser/extended/file.ts +++ b/scripts/dataParser/extended/file.ts @@ -1,4 +1,5 @@ -import { type AnyTuple, type BytesInString, DP, type FixDeepFunctionInfer, type Kind, type NeverCoalescing, createOverride } from "@duplojs/utils"; +import { type AnyTuple, type BytesInString, type FixDeepFunctionInfer, type Kind, type NeverCoalescing, createOverride } from "@duplojs/utils"; +import * as DDP from "@duplojs/utils/dataParser"; import * as dataParsers from "../parsers"; import { type FileInterface } from "@scripts/file"; @@ -6,7 +7,7 @@ type _DataParserFileExtended< GenericDefinition extends dataParsers.DataParserDefinitionFile, > = ( & Kind - & DP.DataParserExtended< + & DDP.DataParserExtended< GenericDefinition, FileInterface, FileInterface @@ -30,21 +31,21 @@ export interface DataParserFileExtended< GenericChecker > ): DataParserFileExtended< - DP.AddCheckersToDefinition< + DDP.AddCheckersToDefinition< GenericDefinition, GenericChecker > >; refine( - theFunction: (input: DP.Output) => boolean, + theFunction: (input: DDP.Output) => boolean, definition?: Partial< - Omit + Omit > ): DataParserFileExtended< - DP.AddCheckersToDefinition< + DDP.AddCheckersToDefinition< GenericDefinition, - readonly [DP.CheckerRefineImplementation>] + readonly [DDP.CheckerRefineImplementation>] > >; @@ -82,12 +83,12 @@ export function file< params?: dataParsers.DataParserFileParams, definition?: GenericDefinition, ): DataParserFileExtended< - DP.MergeDefinition< + DDP.MergeDefinition< dataParsers.DataParserDefinitionFile, NeverCoalescing > > { - const self = DP.dataParserExtendedInit< + const self = DDP.dataParserExtendedInit< dataParsers.DataParserFile, DataParserFileExtended >( diff --git a/scripts/dataParser/parsers/coerce/file.ts b/scripts/dataParser/parsers/coerce/file.ts index 1778066..c5507b3 100644 --- a/scripts/dataParser/parsers/coerce/file.ts +++ b/scripts/dataParser/parsers/coerce/file.ts @@ -1,6 +1,7 @@ +import type { NeverCoalescing } from "@duplojs/utils"; +import type * as DDP from "@duplojs/utils/dataParser"; import * as dataParsers from "../../parsers"; -import { type DP, type NeverCoalescing } from "@duplojs/utils"; export function file< const GenericDefinition extends Omit< @@ -11,7 +12,7 @@ export function file< params?: dataParsers.DataParserFileParams, definition?: GenericDefinition, ): dataParsers.DataParserFile< - DP.MergeDefinition< + DDP.MergeDefinition< dataParsers.DataParserDefinitionFile, NeverCoalescing & { coerce: true } > diff --git a/scripts/dataParser/parsers/file.ts b/scripts/dataParser/parsers/file.ts index f2553a0..d500cab 100644 --- a/scripts/dataParser/parsers/file.ts +++ b/scripts/dataParser/parsers/file.ts @@ -1,4 +1,7 @@ -import { type BytesInString, createOverride, DP, E, stringToBytes, unwrap, type FixDeepFunctionInfer, type Kind, type O, type NeverCoalescing, toRegExp, type AnyTuple } from "@duplojs/utils"; +import { type BytesInString, createOverride, stringToBytes, unwrap, type FixDeepFunctionInfer, type Kind, type NeverCoalescing, toRegExp, type AnyTuple } from "@duplojs/utils"; +import * as DDP from "@duplojs/utils/dataParser"; +import type * as OO from "@duplojs/utils/object"; +import * as EE from "@duplojs/utils/either"; import { createFileInterface, isFileInterface, type FileInterface } from "@scripts/file"; import { createDataParserKind } from "../kind"; @@ -7,15 +10,15 @@ export interface DataParserFileCheckerCustom {} export type DataParserFileCheckers = ( // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents | DataParserFileCheckerCustom[ - O.GetPropsWithValueExtends< + OO.GetPropsWithValueExtends< DataParserFileCheckerCustom, - DP.DataParserChecker + DDP.DataParserChecker > ] - | DP.CheckerRefineImplementation + | DDP.CheckerRefineImplementation ); -export interface DataParserDefinitionFile extends DP.DataParserDefinition< +export interface DataParserDefinitionFile extends DDP.DataParserDefinition< DataParserFileCheckers > { readonly coerce: boolean; @@ -30,7 +33,7 @@ export const fileKind = createDataParserKind("file"); type _DataParserFile< GenericDefinition extends DataParserDefinitionFile, > = ( - & DP.DataParser< + & DDP.DataParser< GenericDefinition, FileInterface, FileInterface @@ -55,7 +58,7 @@ export interface DataParserFile< GenericChecker > ): DataParserFile< - DP.AddCheckersToDefinition< + DDP.AddCheckersToDefinition< GenericDefinition, GenericChecker > @@ -81,12 +84,12 @@ export function file< params?: DataParserFileParams, definition?: GenericDefinition, ): DataParserFile< - DP.MergeDefinition< + DDP.MergeDefinition< DataParserDefinitionFile, NeverCoalescing > > { - const self = DP.dataParserInit( + const self = DDP.dataParserInit( fileKind, { errorMessage: definition?.errorMessage, @@ -110,7 +113,7 @@ export function file< || self.definition.maxSize !== undefined || self.definition.minSize !== undefined ) { - return DP.addIssue( + return DDP.addIssue( error, "async data parser", data, @@ -125,7 +128,7 @@ export function file< } if (!isFileInterface(fileInterface)) { - return DP.addIssue( + return DDP.addIssue( error, "file", data, @@ -140,7 +143,7 @@ export function file< .mimeType .test(fileInterface.getMimeType() ?? "") ) { - return DP.addIssue( + return DDP.addIssue( error, `file with mime type matching ${self.definition.mimeType.source}`, data, @@ -158,7 +161,7 @@ export function file< } if (!isFileInterface(fileInterface)) { - return DP.addIssue( + return DDP.addIssue( error, "file", data, @@ -173,7 +176,7 @@ export function file< .mimeType .test(fileInterface.getMimeType() ?? "") ) { - return DP.addIssue( + return DDP.addIssue( error, `file with mime type matching ${self.definition.mimeType.source}`, fileInterface, @@ -188,8 +191,8 @@ export function file< ) { const resultStats = await fileInterface.stat(); - if (E.isLeft(resultStats)) { - return DP.addIssue( + if (EE.isLeft(resultStats)) { + return DDP.addIssue( error, "existing file", fileInterface, @@ -200,7 +203,7 @@ export function file< const stat = unwrap(resultStats); if (!stat.isFile) { - return DP.addIssue( + return DDP.addIssue( error, "file", stat, @@ -212,7 +215,7 @@ export function file< self.definition.maxSize !== undefined && stat.sizeBytes > self.definition.maxSize ) { - return DP.addIssue( + return DDP.addIssue( error, `file with sizeBytes <= ${self.definition.maxSize}`, stat.sizeBytes, @@ -224,7 +227,7 @@ export function file< self.definition.minSize !== undefined && stat.sizeBytes < self.definition.minSize ) { - return DP.addIssue( + return DDP.addIssue( error, `file with sizeBytes >= ${self.definition.minSize}`, stat.sizeBytes, diff --git a/scripts/file/appendFile.ts b/scripts/file/appendFile.ts index 19e9695..048939d 100644 --- a/scripts/file/appendFile.ts +++ b/scripts/file/appendFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { appendFile( path: string, data: Uint8Array, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -23,15 +23,15 @@ export const appendFile = implementFunction( path, data, ) - .then(E.ok) - .catch((value) => E.left("file-system-append-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-append-file", value)); }, DENO: (path, data) => Deno.writeFile( path, data, { append: true }, ) - .then(E.ok) - .catch((value) => E.left("file-system-append-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-append-file", value)), }, ); diff --git a/scripts/file/appendTextFile.ts b/scripts/file/appendTextFile.ts index cc9319b..7e519db 100644 --- a/scripts/file/appendTextFile.ts +++ b/scripts/file/appendTextFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { appendTextFile( path: string, data: string, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -23,15 +23,15 @@ export const appendTextFile = implementFunction( path, data, ) - .then(E.ok) - .catch((value) => E.left("file-system-append-text-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-append-text-file", value)); }, DENO: (path, data) => Deno.writeTextFile( path, data, { append: true }, ) - .then(E.ok) - .catch((value) => E.left("file-system-append-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-append-text-file", value)), }, ); diff --git a/scripts/file/copy.ts b/scripts/file/copy.ts index af7c81f..9094bd3 100644 --- a/scripts/file/copy.ts +++ b/scripts/file/copy.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { copy( fromPath: string, toPath: string, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -24,8 +24,8 @@ export const copy = implementFunction( toPath, { recursive: true }, ) - .then(E.ok) - .catch((value) => E.left("file-system-copy", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-copy", value)); }, }, ); diff --git a/scripts/file/ensureDirectory.ts b/scripts/file/ensureDirectory.ts index 261ac3d..fe3c9ef 100644 --- a/scripts/file/ensureDirectory.ts +++ b/scripts/file/ensureDirectory.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -26,8 +26,8 @@ export const ensureDirectory = implementFunction( recursive: true, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-directory", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-directory", value)); }, DENO: (path) => Deno.mkdir( path, @@ -35,7 +35,7 @@ export const ensureDirectory = implementFunction( recursive: true, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-directory", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-directory", value)), }, ); diff --git a/scripts/file/ensureFile.ts b/scripts/file/ensureFile.ts index accb295..03e292c 100644 --- a/scripts/file/ensureFile.ts +++ b/scripts/file/ensureFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -6,7 +6,7 @@ declare module "@scripts/implementor" { interface ServerUtilsFunction { ensureFile< GenericPath extends string, - >(path: GenericPath): Promise | E.Ok>; + >(path: GenericPath): Promise | EE.Ok>; } } @@ -21,8 +21,8 @@ export const ensureFile = implementFunction( return fs.open(path, "a") .then((fh) => fh.close()) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-file", value)); }, DENO: (path: string) => Deno.open(path, { write: true, @@ -30,7 +30,7 @@ export const ensureFile = implementFunction( append: true, }) .then((fh) => void fh.close()) - .then(E.ok) - .catch((value) => E.left("file-system-ensure-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-ensure-file", value)), }, ); diff --git a/scripts/file/exists.ts b/scripts/file/exists.ts index ceafbea..dfdb9e4 100644 --- a/scripts/file/exists.ts +++ b/scripts/file/exists.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -21,20 +21,20 @@ export const exists = implementFunction( NODE: async(path) => { const fs = await nodeFileSystem.value; return fs.access(path) - .then(E.ok) - .catch((value) => E.left("file-system-exists", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-exists", value)); }, DENO: (path) => Deno .stat(path) - .then(E.ok) - .catch((value) => E.left("file-system-exists", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-exists", value)), BUN: (path) => Bun.file(path) .exists() .then( (value) => value - ? E.ok() - : E.left("file-system-exists", new Error("Path does not exist")), + ? EE.ok() + : EE.left("file-system-exists", new Error("Path does not exist")), ) - .catch((value) => E.left("file-system-exists", value)), + .catch((value) => EE.left("file-system-exists", value)), }, ); diff --git a/scripts/file/fileInterface.ts b/scripts/file/fileInterface.ts index e2b2233..2e456bc 100644 --- a/scripts/file/fileInterface.ts +++ b/scripts/file/fileInterface.ts @@ -1,5 +1,6 @@ +import { asyncPipe, type Kind, mimeType, Path, innerPipe } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; -import { asyncPipe, type Kind, E, mimeType, Path, innerPipe } from "@duplojs/utils"; import { rename } from "./rename"; import { exists } from "./exists"; import { move } from "./move"; @@ -18,12 +19,12 @@ export interface FileInterface extends Kind< getMimeType(): string | null; getExtension(params?: Path.GetExtensionNameParams): string | null; getParentPath(): string | null; - rename(newName: string): Promise | E.Success>; - relocate(parentPath: string): Promise | E.Success>; - move(newPath: string): Promise | E.Success>; - exists(): Promise | E.Ok>; - remove(): Promise | E.Ok>; - stat(): Promise | E.Success>; + rename(newName: string): Promise | EE.Success>; + relocate(parentPath: string): Promise | EE.Success>; + move(newPath: string): Promise | EE.Success>; + exists(): Promise | EE.Ok>; + remove(): Promise | EE.Ok>; + stat(): Promise | EE.Success>; } /** @@ -61,10 +62,10 @@ export function createFileInterface( function localRename(newName: string) { return asyncPipe( rename(path, newName), - E.whenIsRight( + EE.whenIsRight( innerPipe( createFileInterface, - E.success, + EE.success, ), ), ); @@ -73,10 +74,10 @@ export function createFileInterface( function localRelocate(newParentPath: string) { return asyncPipe( relocate(path, newParentPath), - E.whenIsRight( + EE.whenIsRight( innerPipe( createFileInterface, - E.success, + EE.success, ), ), ); @@ -85,8 +86,8 @@ export function createFileInterface( function localMove(newPath: string) { return asyncPipe( move(path, newPath), - E.whenIsRight( - () => E.success( + EE.whenIsRight( + () => EE.success( createFileInterface(newPath), ), ), diff --git a/scripts/file/folderInterface.ts b/scripts/file/folderInterface.ts index 7f32068..4bcaeeb 100644 --- a/scripts/file/folderInterface.ts +++ b/scripts/file/folderInterface.ts @@ -1,4 +1,5 @@ -import { asyncPipe, E, innerPipe, Path, type Kind } from "@duplojs/utils"; +import { asyncPipe, innerPipe, Path, type Kind } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; import { move } from "./move"; import { exists } from "./exists"; @@ -20,14 +21,14 @@ export interface FolderInterface extends Kind< path: string; getName(): string | null; getParentPath(): string | null; - rename(newName: string): Promise | E.Success>; - exists(): Promise | E.Ok>; - relocate(parentPath: string): Promise | E.Success>; - move(newPath: string): Promise | E.Success>; - remove(): Promise | E.Ok>; - getChildren(): Promise | E.Success>; - stat(): Promise | E.Success>; - walk(): Promise | E.Success>>; + rename(newName: string): Promise | EE.Success>; + exists(): Promise | EE.Ok>; + relocate(parentPath: string): Promise | EE.Success>; + move(newPath: string): Promise | EE.Success>; + remove(): Promise | EE.Ok>; + getChildren(): Promise | EE.Success>; + stat(): Promise | EE.Success>; + walk(): Promise | EE.Success>>; } /** @@ -45,10 +46,10 @@ export function createFolderInterface(path: string): FolderInterface { function localRename(newName: string) { return asyncPipe( rename(path, newName), - E.whenIsRight( + EE.whenIsRight( innerPipe( createFolderInterface, - E.success, + EE.success, ), ), ); @@ -57,10 +58,10 @@ export function createFolderInterface(path: string): FolderInterface { function localRelocate(newParentPath: string) { return asyncPipe( relocate(path, newParentPath), - E.whenIsRight( + EE.whenIsRight( innerPipe( createFolderInterface, - E.success, + EE.success, ), ), ); @@ -69,8 +70,8 @@ export function createFolderInterface(path: string): FolderInterface { function localMove(newPath: string) { return asyncPipe( move(path, newPath), - E.whenIsRight( - () => E.success( + EE.whenIsRight( + () => EE.success( createFolderInterface(newPath), ), ), diff --git a/scripts/file/link.ts b/scripts/file/link.ts index 501db6d..c3629c1 100644 --- a/scripts/file/link.ts +++ b/scripts/file/link.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { link( existingPath: string, newPath: string, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -23,15 +23,15 @@ export const link = implementFunction( existingPath, newPath, ) - .then(E.ok) - .catch((value) => E.left("file-system-link", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-link", value)); }, DENO: (existingPath, newPath) => Deno .link( existingPath, newPath, ) - .then(E.ok) - .catch((value) => E.left("file-system-link", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-link", value)), }, ); diff --git a/scripts/file/linkStat.ts b/scripts/file/linkStat.ts index c73c5eb..d23a173 100644 --- a/scripts/file/linkStat.ts +++ b/scripts/file/linkStat.ts @@ -1,4 +1,6 @@ -import { D, E, innerPipe } from "@duplojs/utils"; +import { innerPipe } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as DD from "@duplojs/utils/date"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { StatInfo } from "./stat"; import type { Stats } from "node:fs"; @@ -10,10 +12,10 @@ function createStatInfoWithFsSource(source: Stats): StatInfo { isDirectory: source.isDirectory(), isSymlink: source.isSymbolicLink(), sizeBytes: source.size, - modifiedAt: D.isSafeTimestamp(source.mtime.getTime()) ? D.createOrThrow(source.mtime) : null, - accessedAt: D.isSafeTimestamp(source.atime.getTime()) ? D.createOrThrow(source.atime) : null, - createdAt: D.isSafeTimestamp(source.birthtime.getTime()) ? D.createOrThrow(source.birthtime) : null, - changedAt: D.isSafeTimestamp(source.ctime.getTime()) ? D.createOrThrow(source.ctime) : null, + modifiedAt: DD.isSafeTimestamp(source.mtime.getTime()) ? DD.createOrThrow(source.mtime) : null, + accessedAt: DD.isSafeTimestamp(source.atime.getTime()) ? DD.createOrThrow(source.atime) : null, + createdAt: DD.isSafeTimestamp(source.birthtime.getTime()) ? DD.createOrThrow(source.birthtime) : null, + changedAt: DD.isSafeTimestamp(source.ctime.getTime()) ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, permissionsMode: source.mode, @@ -37,20 +39,20 @@ function createStatInfoWithDeno(source: Deno.FileInfo): StatInfo { isSymlink: source.isSymlink, sizeBytes: source.size, modifiedAt: source.mtime - && D.isSafeTimestamp(source.mtime.getTime()) - ? D.createOrThrow(source.mtime) + && DD.isSafeTimestamp(source.mtime.getTime()) + ? DD.createOrThrow(source.mtime) : null, accessedAt: source.atime - && D.isSafeTimestamp(source.atime.getTime()) - ? D.createOrThrow(source.atime) + && DD.isSafeTimestamp(source.atime.getTime()) + ? DD.createOrThrow(source.atime) : null, createdAt: source.birthtime - && D.isSafeTimestamp(source.birthtime.getTime()) - ? D.createOrThrow(source.birthtime) + && DD.isSafeTimestamp(source.birthtime.getTime()) + ? DD.createOrThrow(source.birthtime) : null, changedAt: source.ctime - && D.isSafeTimestamp(source.ctime.getTime()) - ? D.createOrThrow(source.ctime) + && DD.isSafeTimestamp(source.ctime.getTime()) + ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, @@ -74,7 +76,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -90,19 +92,19 @@ export const linkStat = implementFunction( .then( innerPipe( createStatInfoWithFsSource, - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-link-stat", value)); + .catch((value) => EE.left("file-system-link-stat", value)); }, DENO: (path) => Deno .lstat(path) .then( innerPipe( createStatInfoWithDeno, - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-link-stat", value)), + .catch((value) => EE.left("file-system-link-stat", value)), }, ); diff --git a/scripts/file/makeDirectory.ts b/scripts/file/makeDirectory.ts index bf33762..11b87fa 100644 --- a/scripts/file/makeDirectory.ts +++ b/scripts/file/makeDirectory.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -13,7 +13,7 @@ declare module "@scripts/implementor" { >( path: GenericPath, params?: MakeDirectoryParams - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -31,8 +31,8 @@ export const makeDirectory = implementFunction( recursive: params?.recursive, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-make-directory", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-make-directory", value)); }, DENO: (path, params) => Deno.mkdir( path, @@ -40,7 +40,7 @@ export const makeDirectory = implementFunction( recursive: params?.recursive, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-make-directory", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-make-directory", value)), }, ); diff --git a/scripts/file/makeTemporaryDirectory.ts b/scripts/file/makeTemporaryDirectory.ts index 1bcb6b2..114fba8 100644 --- a/scripts/file/makeTemporaryDirectory.ts +++ b/scripts/file/makeTemporaryDirectory.ts @@ -1,10 +1,10 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; declare module "@scripts/implementor" { interface ServerUtilsFunction { - makeTemporaryDirectory(prefix: string): Promise | E.Success>; + makeTemporaryDirectory(prefix: string): Promise | EE.Success>; } } @@ -17,11 +17,11 @@ export const makeTemporaryDirectory = implementFunction( NODE: async(prefix) => { const fs = await nodeFileSystem.value; return fs.mkdtemp(prefix) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-directory", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-directory", value)); }, DENO: (prefix) => Deno.makeTempDir({ prefix }) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-directory", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-directory", value)), }, ); diff --git a/scripts/file/makeTemporaryFile.ts b/scripts/file/makeTemporaryFile.ts index 68499a6..ecd2d31 100644 --- a/scripts/file/makeTemporaryFile.ts +++ b/scripts/file/makeTemporaryFile.ts @@ -1,10 +1,11 @@ -import { E, Path } from "@duplojs/utils"; +import { Path } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeCrypto, nodeFileSystem, nodeOs } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; declare module "@scripts/implementor" { interface ServerUtilsFunction { - makeTemporaryFile(prefix: string, suffix?: string): Promise | E.Success>; + makeTemporaryFile(prefix: string, suffix?: string): Promise | EE.Success>; } } @@ -25,14 +26,14 @@ export const makeTemporaryFile = implementFunction( ]); return fs.open(fileTemporaryPath, "wx") .then((fh) => fh.close()) - .then(() => E.success(fileTemporaryPath)) - .catch((value) => E.left("file-system-make-temporary-file", value)); + .then(() => EE.success(fileTemporaryPath)) + .catch((value) => EE.left("file-system-make-temporary-file", value)); }, DENO: (prefix, suffix) => Deno.makeTempFile({ prefix, suffix, }) - .then(E.success) - .catch((value) => E.left("file-system-make-temporary-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-make-temporary-file", value)), }, ); diff --git a/scripts/file/move.ts b/scripts/file/move.ts index 356711e..512f906 100644 --- a/scripts/file/move.ts +++ b/scripts/file/move.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { move( fromPath: string, toPath: string, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -23,15 +23,15 @@ export const move = implementFunction( fromPath, toPath, ) - .then(E.ok) - .catch((value) => E.left("file-system-move", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-move", value)); }, DENO: (fromPath, toPath) => Deno.rename( fromPath, toPath, ) - .then(E.ok) - .catch((value) => E.left("file-system-move", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-move", value)), }, ); diff --git a/scripts/file/readDirectory.ts b/scripts/file/readDirectory.ts index 05db161..e7ea852 100644 --- a/scripts/file/readDirectory.ts +++ b/scripts/file/readDirectory.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -13,7 +13,7 @@ declare module "@scripts/implementor" { >( path: GenericPath, params?: ReadDirectoryParams, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -27,8 +27,8 @@ export const readDirectory = implementFunction( const fs = await nodeFileSystem.value; return fs.readdir(path, { recursive: params?.recursive }) - .then(E.success) - .catch((value) => E.left("file-system-read-directory", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-directory", value)); }, }, ); diff --git a/scripts/file/readFile.ts b/scripts/file/readFile.ts index 5a10563..056030b 100644 --- a/scripts/file/readFile.ts +++ b/scripts/file/readFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -21,16 +21,16 @@ export const readFile = implementFunction( NODE: async(path) => { const fs = await nodeFileSystem.value; return fs.readFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)); }, DENO: (path) => Deno .readFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)), BUN: (path) => Bun.file(path) .bytes() - .then(E.success) - .catch((value) => E.left("file-system-read-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-file", value)), }, ); diff --git a/scripts/file/readJsonFile.ts b/scripts/file/readJsonFile.ts index 186eb3e..a9e524e 100644 --- a/scripts/file/readJsonFile.ts +++ b/scripts/file/readJsonFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -9,7 +9,7 @@ declare module "@scripts/implementor" { GenericPath extends string = string, >( path: GenericPath, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -23,19 +23,19 @@ export const readJsonFile = implementFunction( const fs = await nodeFileSystem.value; return fs.readFile(path, { encoding: "utf-8" }) .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)); }, DENO: (path) => Deno.readTextFile(path) .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)), BUN: (path) => Bun.file(path) .text() .then(JSON.parse) - .then(E.success) - .catch((value) => E.left("file-system-read-json-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-json-file", value)), }, ); diff --git a/scripts/file/readLink.ts b/scripts/file/readLink.ts index 17413fc..0d63c5a 100644 --- a/scripts/file/readLink.ts +++ b/scripts/file/readLink.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -24,12 +24,12 @@ export const readLink = implementFunction( path, { encoding: "utf-8" }, ) - .then(E.success) - .catch((value) => E.left("file-system-read-link", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-link", value)); }, DENO: (path) => Deno .readLink(path) - .then(E.success) - .catch((value) => E.left("file-system-read-link", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-link", value)), }, ); diff --git a/scripts/file/readTextFile.ts b/scripts/file/readTextFile.ts index a82e8da..1010897 100644 --- a/scripts/file/readTextFile.ts +++ b/scripts/file/readTextFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -21,16 +21,16 @@ export const readTextFile = implementFunction( NODE: async(path) => { const fs = await nodeFileSystem.value; return fs.readFile(path, { encoding: "utf-8" }) - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)); }, DENO: (path) => Deno .readTextFile(path) - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)), BUN: (path) => Bun.file(path) .text() - .then(E.success) - .catch((value) => E.left("file-system-read-text-file", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-read-text-file", value)), }, ); diff --git a/scripts/file/realPath.ts b/scripts/file/realPath.ts index ddfe1eb..4b6b20a 100644 --- a/scripts/file/realPath.ts +++ b/scripts/file/realPath.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -8,7 +8,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -21,12 +21,12 @@ export const realPath = implementFunction( NODE: async(path) => { const fs = await nodeFileSystem.value; return fs.realpath(path) - .then(E.success) - .catch((value) => E.left("file-system-real-path", value)); + .then(EE.success) + .catch((value) => EE.left("file-system-real-path", value)); }, DENO: (path) => Deno .realPath(path) - .then(E.success) - .catch((value) => E.left("file-system-real-path", value)), + .then(EE.success) + .catch((value) => EE.left("file-system-real-path", value)), }, ); diff --git a/scripts/file/relocate.ts b/scripts/file/relocate.ts index 11d0ba3..af1d362 100644 --- a/scripts/file/relocate.ts +++ b/scripts/file/relocate.ts @@ -1,4 +1,5 @@ -import { E, Path } from "@duplojs/utils"; +import { Path } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +8,7 @@ declare module "@scripts/implementor" { relocate( fromPath: string, toPath: string, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -22,7 +23,7 @@ export const relocate = implementFunction( const baseName = Path.getBaseName(fromPath); if (!baseName) { - return E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); + return EE.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`)); } const newPath = Path.resolveRelative([newParentPath, baseName]); @@ -31,14 +32,14 @@ export const relocate = implementFunction( fromPath, newPath, ) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-relocate", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-relocate", value)); }, DENO: (fromPath, newParentPath) => { const baseName = Path.getBaseName(fromPath); if (!baseName) { - return Promise.resolve(E.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); + return Promise.resolve(EE.left("file-system-relocate", new Error(`Invalid base name ${fromPath}`))); } const newPath = Path.resolveRelative([newParentPath, baseName]); @@ -47,8 +48,8 @@ export const relocate = implementFunction( fromPath, newPath, ) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-relocate", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-relocate", value)); }, }, ); diff --git a/scripts/file/remove.ts b/scripts/file/remove.ts index 499ef5e..9baec2b 100644 --- a/scripts/file/remove.ts +++ b/scripts/file/remove.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -13,7 +13,7 @@ declare module "@scripts/implementor" { >( path: GenericPath, params?: RemoveDirectoryParams - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -32,8 +32,8 @@ export const remove = implementFunction( force: true, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-remove", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-remove", value)); }, DENO: (path, params) => Deno.remove( path, @@ -41,7 +41,7 @@ export const remove = implementFunction( recursive: params?.recursive, }, ) - .then(E.ok) - .catch((value) => E.left("file-system-remove", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-remove", value)), }, ); diff --git a/scripts/file/rename.ts b/scripts/file/rename.ts index 29ae928..7962adc 100644 --- a/scripts/file/rename.ts +++ b/scripts/file/rename.ts @@ -1,4 +1,5 @@ -import { E, Path } from "@duplojs/utils"; +import { Path } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +8,7 @@ declare module "@scripts/implementor" { rename( path: string, newName: string, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -23,11 +24,11 @@ export const rename = implementFunction( const parentPath = Path.getParentFolderPath(path); if (!parentPath) { - return E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); + return EE.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`)); } if (newName.includes("/")) { - return E.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); + return EE.left("file-system-rename", new Error(`Invalid new name ${newName}.`)); } const newPath = Path.resolveRelative([parentPath, newName]); @@ -36,18 +37,18 @@ export const rename = implementFunction( path, newPath, ) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-rename", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-rename", value)); }, DENO: (path, newName) => { const parentPath = Path.getParentFolderPath(path); if (!parentPath) { - return Promise.resolve(E.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); + return Promise.resolve(EE.left("file-system-rename", new Error(`Invalid parent path ${parentPath}.`))); } if (newName.includes("/")) { - return Promise.resolve(E.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); + return Promise.resolve(EE.left("file-system-rename", new Error(`Invalid new name ${newName}.`))); } const newPath = Path.resolveRelative([parentPath, newName]); @@ -56,8 +57,8 @@ export const rename = implementFunction( path, newPath, ) - .then(() => E.success(newPath)) - .catch((value) => E.left("file-system-rename", value)); + .then(() => EE.success(newPath)) + .catch((value) => EE.left("file-system-rename", value)); }, }, ); diff --git a/scripts/file/setMode.ts b/scripts/file/setMode.ts index 6583acc..27d96fd 100644 --- a/scripts/file/setMode.ts +++ b/scripts/file/setMode.ts @@ -1,4 +1,5 @@ -import { E, isType } from "@duplojs/utils"; +import { isType } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -51,7 +52,7 @@ declare module "@scripts/implementor" { setMode( path: string, mode: SetMode, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -64,12 +65,12 @@ export const setMode = implementFunction( NODE: async(path, mode) => { const fs = await nodeFileSystem.value; return fs.chmod(path, toMode(mode)) - .then(E.ok) - .catch((value) => E.left("file-system-set-mode", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-set-mode", value)); }, DENO: (path, mode) => Deno .chmod(path, toMode(mode)) - .then(E.ok) - .catch((value) => E.left("file-system-set-mode", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-set-mode", value)), }, ); diff --git a/scripts/file/setOwner.ts b/scripts/file/setOwner.ts index c91de99..fa967a3 100644 --- a/scripts/file/setOwner.ts +++ b/scripts/file/setOwner.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -12,7 +12,7 @@ declare module "@scripts/implementor" { setOwner( path: string, params: SetOwnerParams, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -25,12 +25,12 @@ export const setOwner = implementFunction( NODE: async(path, { userId, groupId }) => { const fs = await nodeFileSystem.value; return fs.chown(path, userId, groupId) - .then(E.ok) - .catch((value) => E.left("file-system-set-owner", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-set-owner", value)); }, DENO: (path, { userId, groupId }) => Deno .chown(path, userId, groupId) - .then(E.ok) - .catch((value) => E.left("file-system-set-owner", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-set-owner", value)), }, ); diff --git a/scripts/file/setTime.ts b/scripts/file/setTime.ts index 5f9b80c..c152ece 100644 --- a/scripts/file/setTime.ts +++ b/scripts/file/setTime.ts @@ -1,10 +1,11 @@ -import { D, E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as DD from "@duplojs/utils/date"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; interface SetTimeParams { - accessTime: D.TheDate; - modifiedTime: D.TheDate; + accessTime: DD.TheDate; + modifiedTime: DD.TheDate; } declare module "@scripts/implementor" { @@ -12,7 +13,7 @@ declare module "@scripts/implementor" { setTime( path: string, params: SetTimeParams - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -26,19 +27,19 @@ export const setTime = implementFunction( const fs = await nodeFileSystem.value; return fs.utimes( path, - D.toTimestamp(accessTime), - D.toTimestamp(modifiedTime), + DD.toTimestamp(accessTime), + DD.toTimestamp(modifiedTime), ) - .then(E.ok) - .catch((value) => E.left("file-system-set-time", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-set-time", value)); }, DENO: (path, { accessTime, modifiedTime }) => Deno .utime( path, - D.toTimestamp(accessTime), - D.toTimestamp(modifiedTime), + DD.toTimestamp(accessTime), + DD.toTimestamp(modifiedTime), ) - .then(E.ok) - .catch((value) => E.left("file-system-set-time", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-set-time", value)), }, ); diff --git a/scripts/file/stat.ts b/scripts/file/stat.ts index e9799ba..b824246 100644 --- a/scripts/file/stat.ts +++ b/scripts/file/stat.ts @@ -1,4 +1,6 @@ -import { D, E, innerPipe } from "@duplojs/utils"; +import { innerPipe } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; +import * as DD from "@duplojs/utils/date"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { Stats } from "node:fs"; import type { FileSystemLeft } from "./types"; @@ -14,10 +16,10 @@ export interface StatInfo { sizeBytes: number; /** Timestamps */ - modifiedAt: D.TheDate | null; - accessedAt: D.TheDate | null; - createdAt: D.TheDate | null; - changedAt: D.TheDate | null; + modifiedAt: DD.TheDate | null; + accessedAt: DD.TheDate | null; + createdAt: DD.TheDate | null; + changedAt: DD.TheDate | null; /** Unix/FS identifiers */ deviceId: number; @@ -49,7 +51,7 @@ declare module "@scripts/implementor" { GenericPath extends string, >( path: GenericPath, - ): Promise | E.Success>; + ): Promise | EE.Success>; } } @@ -59,10 +61,10 @@ function createStatInfoWithFsSource(source: Stats): StatInfo { isDirectory: source.isDirectory(), isSymlink: source.isSymbolicLink(), sizeBytes: source.size, - modifiedAt: D.isSafeTimestamp(source.mtime.getTime()) ? D.createOrThrow(source.mtime) : null, - accessedAt: D.isSafeTimestamp(source.atime.getTime()) ? D.createOrThrow(source.atime) : null, - createdAt: D.isSafeTimestamp(source.birthtime.getTime()) ? D.createOrThrow(source.birthtime) : null, - changedAt: D.isSafeTimestamp(source.ctime.getTime()) ? D.createOrThrow(source.ctime) : null, + modifiedAt: DD.isSafeTimestamp(source.mtime.getTime()) ? DD.createOrThrow(source.mtime) : null, + accessedAt: DD.isSafeTimestamp(source.atime.getTime()) ? DD.createOrThrow(source.atime) : null, + createdAt: DD.isSafeTimestamp(source.birthtime.getTime()) ? DD.createOrThrow(source.birthtime) : null, + changedAt: DD.isSafeTimestamp(source.ctime.getTime()) ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, permissionsMode: source.mode, @@ -86,20 +88,20 @@ function createStatInfoWithDeno(source: Deno.FileInfo): StatInfo { isSymlink: source.isSymlink, sizeBytes: source.size, modifiedAt: source.mtime - && D.isSafeTimestamp(source.mtime.getTime()) - ? D.createOrThrow(source.mtime) + && DD.isSafeTimestamp(source.mtime.getTime()) + ? DD.createOrThrow(source.mtime) : null, accessedAt: source.atime - && D.isSafeTimestamp(source.atime.getTime()) - ? D.createOrThrow(source.atime) + && DD.isSafeTimestamp(source.atime.getTime()) + ? DD.createOrThrow(source.atime) : null, createdAt: source.birthtime - && D.isSafeTimestamp(source.birthtime.getTime()) - ? D.createOrThrow(source.birthtime) + && DD.isSafeTimestamp(source.birthtime.getTime()) + ? DD.createOrThrow(source.birthtime) : null, changedAt: source.ctime - && D.isSafeTimestamp(source.ctime.getTime()) - ? D.createOrThrow(source.ctime) + && DD.isSafeTimestamp(source.ctime.getTime()) + ? DD.createOrThrow(source.ctime) : null, deviceId: source.dev, inode: source.ino, @@ -129,28 +131,28 @@ export const stat = implementFunction( .then( innerPipe( createStatInfoWithFsSource, - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-stat", value)); + .catch((value) => EE.left("file-system-stat", value)); }, DENO: (path) => Deno .stat(path) .then( innerPipe( createStatInfoWithDeno, - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-stat", value)), + .catch((value) => EE.left("file-system-stat", value)), BUN: (path) => Bun.file(path) .stat() .then( innerPipe( createStatInfoWithFsSource, - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-stat", value)), + .catch((value) => EE.left("file-system-stat", value)), }, ); diff --git a/scripts/file/symlink.ts b/scripts/file/symlink.ts index 5ab57b2..a42a9d2 100644 --- a/scripts/file/symlink.ts +++ b/scripts/file/symlink.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -18,7 +18,7 @@ declare module "@scripts/implementor" { oldPath: string, newPath: string, params?: SymlinkParams - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -35,8 +35,8 @@ export const symlink = implementFunction( newPath, params?.type, ) - .then(E.ok) - .catch((value) => E.left("file-system-symlink", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-symlink", value)); }, DENO: (oldPath, newPath, params) => Deno .symlink( @@ -44,7 +44,7 @@ export const symlink = implementFunction( newPath, params, ) - .then(E.ok) - .catch((value) => E.left("file-system-symlink", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-symlink", value)), }, ); diff --git a/scripts/file/truncate.ts b/scripts/file/truncate.ts index 83bcc20..80bb9c4 100644 --- a/scripts/file/truncate.ts +++ b/scripts/file/truncate.ts @@ -1,4 +1,5 @@ -import { E, instanceOf, pipe, when } from "@duplojs/utils"; +import { instanceOf, pipe, when } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -9,7 +10,7 @@ declare module "@scripts/implementor" { >( path: GenericPath, size?: number, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -22,8 +23,8 @@ export const truncate = implementFunction( NODE: async(path, size) => { const fs = await nodeFileSystem.value; return fs.truncate(path, size) - .then(E.ok) - .catch((value) => E.left("file-system-truncate", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-truncate", value)); }, DENO: (path: string, size) => pipe( path, @@ -33,8 +34,8 @@ export const truncate = implementFunction( ), (stringPath) => Deno .truncate(stringPath, size) - .then(E.ok) - .catch((value) => E.left("file-system-truncate", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-truncate", value)), ), }, ); diff --git a/scripts/file/types/fileSystemLeft.ts b/scripts/file/types/fileSystemLeft.ts index 0b45381..902511c 100644 --- a/scripts/file/types/fileSystemLeft.ts +++ b/scripts/file/types/fileSystemLeft.ts @@ -1,5 +1,5 @@ -import type { E } from "@duplojs/utils"; +import type * as EE from "@duplojs/utils/either"; export type FileSystemLeft< GenericName extends string, -> = E.Left<`file-system-${GenericName}`, unknown>; +> = EE.Left<`file-system-${GenericName}`, unknown>; diff --git a/scripts/file/unknownInterface.ts b/scripts/file/unknownInterface.ts index 1e6b1fc..0565f50 100644 --- a/scripts/file/unknownInterface.ts +++ b/scripts/file/unknownInterface.ts @@ -1,4 +1,5 @@ -import { Path, type E, type Kind } from "@duplojs/utils"; +import { Path, type Kind } from "@duplojs/utils"; +import type * as EE from "@duplojs/utils/either"; import { createDuplojsServerUtilsKind } from "@scripts/kind"; import { stat, type StatInfo } from "./stat"; import { exists } from "./exists"; @@ -12,8 +13,8 @@ export interface UnknownInterface extends Kind< path: string; getName(): string | null; getParentPath(): string | null; - stat(): Promise | E.Success>; - exist(): Promise | E.Ok>; + stat(): Promise | EE.Success>; + exist(): Promise | EE.Ok>; } /** diff --git a/scripts/file/walkDirectory.ts b/scripts/file/walkDirectory.ts index 8e64e7d..957d6c5 100644 --- a/scripts/file/walkDirectory.ts +++ b/scripts/file/walkDirectory.ts @@ -1,4 +1,7 @@ -import { innerPipe, E, P, G } from "@duplojs/utils"; +import { innerPipe } from "@duplojs/utils"; +import * as GG from "@duplojs/utils/generator"; +import * as EE from "@duplojs/utils/either"; +import * as PP from "@duplojs/utils/pattern"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import { type FileInterface, createFileInterface } from "./fileInterface"; import { type FolderInterface, createFolderInterface } from "./folderInterface"; @@ -18,7 +21,7 @@ declare module "@scripts/implementor" { params?: WalkDirectoryParams, ): Promise< FileSystemLeft<"walk-directory"> - | E.Success< + | EE.Success< Generator > >; @@ -43,31 +46,31 @@ export const walkDirectory = implementFunction( ) .then( innerPipe( - G.map( + GG.map( innerPipe( - P.when( + PP.when( (dirent) => dirent.isFile(), ({ parentPath, name }) => createFileInterface( `${parentPath}/${name}`, ), ), - P.when( + PP.when( (dirent) => dirent.isDirectory(), ({ parentPath, name }) => createFolderInterface( `${parentPath}/${name}`, ), ), - P.otherwise( + PP.otherwise( ({ parentPath, name }) => createUnknownInterface( `${parentPath}/${name}`, ), ), ), ), - E.success, + EE.success, ), ) - .catch((value) => E.left("file-system-walk-directory", value)); + .catch((value) => EE.left("file-system-walk-directory", value)); }, }, ); diff --git a/scripts/file/writeFile.ts b/scripts/file/writeFile.ts index c975ffd..8376af5 100644 --- a/scripts/file/writeFile.ts +++ b/scripts/file/writeFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { writeFile( path: string, data: Uint8Array, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -23,20 +23,20 @@ export const writeFile = implementFunction( path, data, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)); }, DENO: (path, data) => Deno .writeFile( path, data, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)), BUN: (path, data) => Bun .file(path) .write(data) - .then(E.ok) - .catch((value) => E.left("file-system-write-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-file", value)), }, ); diff --git a/scripts/file/writeJsonFile.ts b/scripts/file/writeJsonFile.ts index 7a8698c..12b2589 100644 --- a/scripts/file/writeJsonFile.ts +++ b/scripts/file/writeJsonFile.ts @@ -1,4 +1,5 @@ -import { asyncPipe, E, pipe } from "@duplojs/utils"; +import { asyncPipe, pipe } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -12,7 +13,7 @@ declare module "@scripts/implementor" { path: string, data: unknown, params?: WriteJsonFile - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -25,63 +26,63 @@ export const writeJsonFile = implementFunction( NODE: async(path, data, params) => { const fs = await nodeFileSystem.value; return pipe( - E.safeCallback( + EE.safeCallback( () => JSON.stringify( data, null, params?.space, ), ), - E.whenIsRight( + EE.whenIsRight( (value) => fs.writeFile( path, value, { encoding: "utf-8" }, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value)), ), - E.whenIsLeft( - (value) => E.left("file-system-write-json-file", value), + EE.whenIsLeft( + (value) => EE.left("file-system-write-json-file", value), ), ); }, DENO: (path, data, params) => asyncPipe( - E.safeCallback( + EE.safeCallback( () => JSON.stringify( data, null, params?.space, ), ), - E.whenIsRight( + EE.whenIsRight( (value) => Deno.writeTextFile( path, value, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value)), ), - E.whenIsLeft( - (value) => E.left("file-system-write-json-file", value), + EE.whenIsLeft( + (value) => EE.left("file-system-write-json-file", value), ), ), BUN: (path, data, params) => asyncPipe( - E.safeCallback( + EE.safeCallback( () => JSON.stringify( data, null, params?.space, ), ), - E.whenIsRight( + EE.whenIsRight( (value) => Bun.file(path) .write(value) - .then(E.ok) - .catch((value) => E.left("file-system-write-json-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-json-file", value)), ), - E.whenIsLeft( - (value) => E.left("file-system-write-json-file", value), + EE.whenIsLeft( + (value) => EE.left("file-system-write-json-file", value), ), ), }, diff --git a/scripts/file/writeTextFile.ts b/scripts/file/writeTextFile.ts index c4f6cb8..1de0d65 100644 --- a/scripts/file/writeTextFile.ts +++ b/scripts/file/writeTextFile.ts @@ -1,4 +1,4 @@ -import { E } from "@duplojs/utils"; +import * as EE from "@duplojs/utils/either"; import { implementFunction, nodeFileSystem } from "@scripts/implementor"; import type { FileSystemLeft } from "./types"; @@ -7,7 +7,7 @@ declare module "@scripts/implementor" { writeTextFile( path: string, data: string, - ): Promise | E.Ok>; + ): Promise | EE.Ok>; } } @@ -24,20 +24,20 @@ export const writeTextFile = implementFunction( data, { encoding: "utf-8" }, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)); + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)); }, DENO: (path, data) => Deno .writeTextFile( path, data, ) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)), BUN: (path, data) => Bun .file(path) .write(data) - .then(E.ok) - .catch((value) => E.left("file-system-write-text-file", value)), + .then(EE.ok) + .catch((value) => EE.left("file-system-write-text-file", value)), }, ); diff --git a/tests/command/create.test.ts b/tests/command/create.test.ts index eee83df..1c08f4f 100644 --- a/tests/command/create.test.ts +++ b/tests/command/create.test.ts @@ -1,4 +1,4 @@ -import { type ExpectType, DPE, DP, S } from "@duplojs/utils"; +import { type ExpectType, C, DPE, DP, S, unwrap } from "@duplojs/utils"; import { DServerCommand, TESTImplementation, setEnvironment } from "@scripts"; describe("create", () => { @@ -225,41 +225,54 @@ describe("create", () => { expect(exitSpy).toHaveBeenCalledWith(0); }); - it("renders command error when tuple subject parsing fails", async() => { + it("coerces primitive data parser subject from a single cli argument", async() => { setEnvironment("TEST"); const exitSpy = vi.fn(); - const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); + const executeSpy = vi.fn(); TESTImplementation.set("exitProcess", exitSpy); const command = DServerCommand.create( "root", { - subject: DP.tuple([DP.number()]) as never, + subject: DP.number(), + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + number, + "strict" + >; + + executeSpy(subject); }, - () => undefined, ); - await command.execute(["bad"]); + await command.execute(["42"]); - expect(errorSpy).toHaveBeenCalledTimes(1); - expect(errorSpy.mock.calls[0]![0]).toContain("SUBJECT:"); - expect(errorSpy.mock.calls[0]![0]).toContain("number"); - expect(exitSpy).toHaveBeenCalledWith(1); + expect(executeSpy).toHaveBeenCalledWith(42); + expect(exitSpy).toHaveBeenCalledWith(0); }); - it("returns subject parse error without printing when tuple subject has a shared error", async() => { + it("renders command error when tuple subject parsing fails", async() => { setEnvironment("TEST"); + const exitSpy = vi.fn(); const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); + TESTImplementation.set("exitProcess", exitSpy); + const command = DServerCommand.create( "root", { - subject: DP.tuple([DP.number()]) as never, + subject: DP.tuple([DP.number()]), }, () => undefined, ); - await expect(command.execute(["bad"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); - expect(errorSpy).not.toHaveBeenCalled(); + await command.execute(["bad"]); + + expect(errorSpy).toHaveBeenCalledTimes(1); + expect(errorSpy.mock.calls[0]![0]).toContain("SUBJECT:"); + expect(errorSpy.mock.calls[0]![0]).toContain("number"); + expect(exitSpy).toHaveBeenCalledWith(1); }); it("renders command error when single subject parsing fails", async() => { @@ -271,7 +284,7 @@ describe("create", () => { const command = DServerCommand.create( "root", { - subject: DP.number() as never, + subject: DP.number(), }, () => undefined, ); @@ -284,33 +297,34 @@ describe("create", () => { expect(exitSpy).toHaveBeenCalledWith(1); }); - it("returns many-arguments error without printing when single subject has a shared error", async() => { + it("does not print subject errors when a shared error is provided", async() => { setEnvironment("TEST"); const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); - const command = DServerCommand.create( + const tupleCommand = DServerCommand.create( "root", { - subject: DP.string() as never, + subject: DP.tuple([DP.number()]), }, () => undefined, ); - - await expect(command.execute(["one", "two"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); - expect(errorSpy).not.toHaveBeenCalled(); - }); - - it("returns single subject parse error without printing when a shared error is provided", async() => { - setEnvironment("TEST"); - const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined); - const command = DServerCommand.create( + const singleParseCommand = DServerCommand.create( "root", { - subject: DP.number() as never, + subject: DP.number(), + }, + () => undefined, + ); + const manyArgsCommand = DServerCommand.create( + "root", + { + subject: DP.string(), }, () => undefined, ); - await expect(command.execute(["bad"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); + await expect(tupleCommand.execute(["bad"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); + await expect(singleParseCommand.execute(["bad"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); + await expect(manyArgsCommand.execute(["one", "two"], DServerCommand.createError("parent"))).resolves.toBe(DServerCommand.SymbolCommandError); expect(errorSpy).not.toHaveBeenCalled(); }); @@ -345,6 +359,181 @@ describe("create", () => { expect(exitSpy).toHaveBeenCalledWith(0); }); + it("coerces primitive data parser inside tuple subject", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + + const command = DServerCommand.create( + "root", + { + subject: DP.tuple([DP.number()]), + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + [number], + "strict" + >; + + executeSpy(subject); + }, + ); + + await command.execute(["42"]); + + expect(executeSpy).toHaveBeenCalledWith([42]); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + + it("coerces primitive data parser inside tuple rest subject", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + + const command = DServerCommand.create( + "root", + { + subject: DP.tuple([DP.string()], { rest: DP.number() }), + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + [string, ...number[]], + "strict" + >; + + executeSpy(subject); + }, + ); + + await command.execute(["head", "1", "2"]); + + expect(executeSpy).toHaveBeenCalledWith(["head", 1, 2]); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + + it("coerces primitive data parser inside array subject", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + + const command = DServerCommand.create( + "root", + { + subject: DP.array(DP.number()), + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + number[], + "strict" + >; + + executeSpy(subject); + }, + ); + + await command.execute(["1", "2"]); + + expect(executeSpy).toHaveBeenCalledWith([1, 2]); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + + it("parses clean primitive subject and infers wrapped subject type", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + + const command = DServerCommand.create( + "root", + { + subject: C.Number, + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + C.Number, + "strict" + >; + + executeSpy(unwrap(subject)); + }, + ); + + await command.execute(["42"]); + + expect(executeSpy).toHaveBeenCalledWith(42); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + + it("parses clean new type subject and infers required subject type", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + const UserId = C.createNewType( + "userId", + DP.number(), + ); + + const command = DServerCommand.create( + "root", + { + subject: UserId, + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + C.GetNewType, + "strict" + >; + + executeSpy(unwrap(subject)); + }, + ); + + await command.execute(["42"]); + + expect(executeSpy).toHaveBeenCalledWith(42); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + + it("parses clean entity property subject and infers literal union type", async() => { + setEnvironment("TEST"); + const exitSpy = vi.fn(); + const executeSpy = vi.fn(); + TESTImplementation.set("exitProcess", exitSpy); + + const command = DServerCommand.create( + "root", + { + subject: C.entityPropertyDefinitionTools.union( + C.entityPropertyDefinitionTools.identifier("admin"), + C.entityPropertyDefinitionTools.identifier("client"), + ), + }, + ({ subject }) => { + type _CheckSubject = ExpectType< + typeof subject, + "admin" | "client", + "strict" + >; + + executeSpy(subject); + }, + ); + + await command.execute(["admin"]); + + expect(executeSpy).toHaveBeenCalledWith("admin"); + expect(exitSpy).toHaveBeenCalledWith(0); + }); + it("executes optional option with pipe and transform parser without runtime bug", async() => { setEnvironment("TEST"); const exitSpy = vi.fn(); @@ -466,7 +655,7 @@ describe("create", () => { expect(exitSpy).not.toHaveBeenCalledWith(1); }); - it("executes matching child command when subject is a command list", async() => { + it("handles child command dispatch and fallback", async() => { setEnvironment("TEST"); const exitSpy = vi.fn(); const childExecuteSpy = vi.fn(); @@ -486,36 +675,12 @@ describe("create", () => { ); await root.execute(["child", "arg"]); - - expect(childExecuteSpy).toHaveBeenCalledWith({ options: {} }); - expect(rootExecuteSpy).not.toHaveBeenCalled(); - expect(exitSpy).toHaveBeenCalledWith(0); - }); - - it("does not execute child command when no child name matches", async() => { - setEnvironment("TEST"); - const exitSpy = vi.fn(); - const childExecuteSpy = vi.fn(); - const rootExecuteSpy = vi.fn(); - TESTImplementation.set("exitProcess", exitSpy); - - const child = DServerCommand.create( - "child", - childExecuteSpy, - ); - const root = DServerCommand.create( - "root", - { - subject: [child], - }, - rootExecuteSpy, - ); - await root.execute(["unknown", "arg"]); - expect(childExecuteSpy).not.toHaveBeenCalled(); + expect(childExecuteSpy).toHaveBeenCalledWith({ options: {} }); expect(rootExecuteSpy).toHaveBeenCalledWith({}); - expect(exitSpy).toHaveBeenCalledWith(0); + expect(exitSpy).toHaveBeenNthCalledWith(1, 0); + expect(exitSpy).toHaveBeenNthCalledWith(2, 0); }); it("runs help only on matching child command", async() => { diff --git a/tests/command/options/array.test.ts b/tests/command/options/array.test.ts index 77db9c3..493cc84 100644 --- a/tests/command/options/array.test.ts +++ b/tests/command/options/array.test.ts @@ -1,4 +1,4 @@ -import { type ExpectType, DP, pipe, S } from "@duplojs/utils"; +import { type ExpectType, C, DP, pipe, S, unwrap } from "@duplojs/utils"; import { DServerCommand } from "@scripts"; import { createError, SymbolCommandError } from "@scripts/command/error"; @@ -145,4 +145,76 @@ describe("createArrayOption", () => { expect(result.result).toEqual([5, 2]); expect(result.argumentRest).toEqual([]); }); + + it("supports clean handler contracts with typed array output", () => { + const numberOption = DServerCommand.createArrayOption( + "counts", + C.Number, + { + required: true, + min: 1, + }, + ); + + const numberResult = numberOption.execute(["--counts=42,43"], createError("root")); + expect(numberResult).not.toBe(SymbolCommandError); + if (numberResult === SymbolCommandError) { + return; + } + + type _checkNumberResult = ExpectType< + typeof numberResult.result, + [C.Number, ...C.Number[]], + "strict" + >; + + const UserId = C.createNewType( + "userId", + DP.number(), + ); + const userOption = DServerCommand.createArrayOption( + "users", + UserId, + { required: true }, + ); + + const userResult = userOption.execute(["--users=1,2"], createError("root")); + expect(userResult).not.toBe(SymbolCommandError); + if (userResult === SymbolCommandError) { + return; + } + + type _checkUserResult = ExpectType< + typeof userResult.result, + C.GetNewType[], + "strict" + >; + + expect(numberResult.result.map(unwrap)).toEqual([42, 43]); + expect(userResult.result.map(unwrap)).toEqual([1, 2]); + }); + + it("supports clean entity property definition contracts with typed array output", () => { + const option = DServerCommand.createArrayOption( + "roles", + C.entityPropertyDefinitionTools.union( + C.entityPropertyDefinitionTools.identifier("admin"), + C.entityPropertyDefinitionTools.identifier("client"), + ), + ); + + const result = option.execute(["--roles=admin,client"], createError("root")); + expect(result).not.toBe(SymbolCommandError); + if (result === SymbolCommandError) { + return; + } + + type _checkResult = ExpectType< + typeof result.result, + ("admin" | "client")[] | undefined, + "strict" + >; + + expect(result.result).toEqual(["admin", "client"]); + }); }); diff --git a/tests/command/options/simple.test.ts b/tests/command/options/simple.test.ts index 37fb638..569e753 100644 --- a/tests/command/options/simple.test.ts +++ b/tests/command/options/simple.test.ts @@ -1,13 +1,8 @@ -import { type ExpectType, DP, DPE, S } from "@duplojs/utils"; +import { type ExpectType, C, DP, DPE, S, unwrap } from "@duplojs/utils"; import { DServerCommand } from "@scripts"; import { createError, SymbolCommandError } from "@scripts/command/error"; describe("createOption", () => { - afterEach(() => { - vi.clearAllMocks(); - vi.restoreAllMocks(); - }); - it("returns undefined when optional option is missing", () => { const option = DServerCommand.createOption("name", DP.string()); const result = option.execute(["subject"], createError("root")); @@ -108,6 +103,29 @@ describe("createOption", () => { expect(result.result).toBe(5); }); + it("coerces eligible data parser without mutating original schema", () => { + const schema = DP.number(); + const option = DServerCommand.createOption( + "count", + schema, + ); + + const result = option.execute(["--count=42"], createError("root")); + expect(result).not.toBe(SymbolCommandError); + if (result === SymbolCommandError) { + return; + } + + type _CheckResult = ExpectType< + typeof result.result, + number | undefined, + "strict" + >; + + expect(result.result).toBe(42); + expect(schema.definition.coerce).toBe(false); + }); + it("supports optional option with pipe schema without crashing at execute", () => { const option = DServerCommand.createOption( "name", @@ -141,29 +159,6 @@ describe("createOption", () => { expect(result.argumentRest).toEqual([]); }); - it("support required", () => { - const option = DServerCommand.createOption( - "name", - DPE.string(), - { required: true }, - ); - - const result = option.execute(["--name=guest"], createError("root")); - expect(result).not.toBe(SymbolCommandError); - if (result === SymbolCommandError) { - return; - } - - type _CheckResult = ExpectType< - typeof result.result, - string, - "strict" - >; - - expect(result.result).toBe("guest"); - expect(result.argumentRest).toEqual([]); - }); - it("support optional dataParser", () => { const optionOptionalRequired = DServerCommand.createOption( "name", @@ -194,10 +189,138 @@ describe("createOption", () => { return; } type _check1 = ExpectType< - typeof result.result, + typeof result1.result, string | undefined, "strict" >; - expect(result.result).toBe("guest"); + expect(result1.result).toBe("guest"); + }); + + it("supports clean primitive schema as contract", () => { + const option = DServerCommand.createOption( + "count", + C.Number, + ); + + const result = option.execute(["--count=42"], createError("root")); + expect(result).not.toBe(SymbolCommandError); + if (result === SymbolCommandError) { + return; + } + + type _check = ExpectType< + typeof result.result, + C.Number | undefined, + "strict" + >; + + expect(unwrap(result.result)).toBe(42); + }); + + it("supports clean handler contracts", () => { + const constraintOption = DServerCommand.createOption( + "count", + C.Positive, + ); + + const constraintResult = constraintOption.execute(["--count=42"], createError("root")); + expect(constraintResult).not.toBe(SymbolCommandError); + if (constraintResult === SymbolCommandError) { + return; + } + + type _checkConstraint = ExpectType< + typeof constraintResult.result, + C.Positive | undefined, + "strict" + >; + + const UserId = C.createNewType( + "userId", + DP.number(), + ); + + const newTypeOption = DServerCommand.createOption( + "user", + UserId, + { required: true }, + ); + + const newTypeResult = newTypeOption.execute(["--user=42"], createError("root")); + expect(newTypeResult).not.toBe(SymbolCommandError); + if (newTypeResult === SymbolCommandError) { + return; + } + + type _checkNewType = ExpectType< + typeof newTypeResult.result, + C.GetNewType, + "strict" + >; + + expect(unwrap(constraintResult.result)).toBe(42); + expect(unwrap(newTypeResult.result)).toBe(42); + }); + + it("supports clean entity property definition contracts", () => { + const identifierOption = DServerCommand.createOption( + "target", + C.entityPropertyDefinitionTools.identifier("duplo"), + ); + + const identifierResult = identifierOption.execute(["--target=duplo"], createError("root")); + expect(identifierResult).not.toBe(SymbolCommandError); + if (identifierResult === SymbolCommandError) { + return; + } + + type _checkIdentifier = ExpectType< + typeof identifierResult.result, + "duplo" | undefined, + "strict" + >; + + const unionOption = DServerCommand.createOption( + "role", + C.entityPropertyDefinitionTools.union( + C.entityPropertyDefinitionTools.identifier("admin"), + C.entityPropertyDefinitionTools.identifier("client"), + ), + ); + + const unionResult = unionOption.execute(["--role=admin"], createError("root")); + expect(unionResult).not.toBe(SymbolCommandError); + if (unionResult === SymbolCommandError) { + return; + } + + type _checkUnion = ExpectType< + typeof unionResult.result, + "admin" | "client" | undefined, + "strict" + >; + + const nullableOption = DServerCommand.createOption( + "target", + C.entityPropertyDefinitionTools.nullable( + C.entityPropertyDefinitionTools.identifier("duplo"), + ), + ); + + const nullableResult = nullableOption.execute(["subject"], createError("root")); + expect(nullableResult).not.toBe(SymbolCommandError); + if (nullableResult === SymbolCommandError) { + return; + } + + type _checkNullable = ExpectType< + typeof nullableResult.result, + "duplo" | null | undefined, + "strict" + >; + + expect(identifierResult.result).toBe("duplo"); + expect(unionResult.result).toBe("admin"); + expect(nullableResult.result).toBeUndefined(); }); });