@pithos/core 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@
10
10
  * ❌ const distance = math.geometry.distance; // from autocompletion
11
11
  * ✅ import { distance } from 'pithos/math/geometry';
12
12
  *
13
- * Generated on: 2026-02-22T16:49:34.264Z
13
+ * Generated on: 2026-03-04T07:03:41.432Z
14
14
  * */
15
15
 
16
16
  /**
@@ -555,6 +555,17 @@ declare const _autocompletion: {
555
555
  };
556
556
  };
557
557
  };
558
+ bridges: {
559
+ ensure: {
560
+ ensure: typeof import('./bridges/ensure')['ensure'];
561
+ };
562
+ ensureAsync: {
563
+ ensureAsync: typeof import('./bridges/ensureAsync')['ensureAsync'];
564
+ };
565
+ ensurePromise: {
566
+ ensurePromise: typeof import('./bridges/ensurePromise')['ensurePromise'];
567
+ };
568
+ };
558
569
  kanon: {
559
570
  index: {
560
571
  any: typeof import('./kanon/index')['any'];
@@ -1589,6 +1600,15 @@ export default _autocompletion;
1589
1600
  declare const arkhe: typeof _autocompletion.arkhe;
1590
1601
  export { arkhe };
1591
1602
 
1603
+ /**
1604
+ * @deprecated ⚠️ For autocompletion only.
1605
+ * Use direct imports from 'bridges/...' to preserve tree-shaking.
1606
+ * @example
1607
+ * import { ensure } from 'pithos/bridges/ensure';
1608
+ */
1609
+ declare const bridges: typeof _autocompletion.bridges;
1610
+ export { bridges };
1611
+
1592
1612
  /**
1593
1613
  * @deprecated ⚠️ For autocompletion only.
1594
1614
  * Use direct imports from 'kanon/...' to preserve tree-shaking.
@@ -0,0 +1,28 @@
1
+ import type { Schema } from "../kanon/types/base";
2
+ import type { Result } from "../zygos/result/result";
3
+ /**
4
+ * Parses a value against a Kanon schema and returns a Zygos `Result`.
5
+ *
6
+ * Bridge between Kanon validation and Zygos error handling:
7
+ * instead of checking `result.success`, you get a chainable `Result<T, string>`.
8
+ *
9
+ * @template T - The expected output type of the schema.
10
+ * @param schema - Kanon schema to validate against.
11
+ * @param input - Value to validate.
12
+ * @returns `Ok<T>` if validation succeeds, `Err<string>` otherwise.
13
+ * @since 2.1.0
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { ensure } from "pithos/bridges/ensure";
18
+ * import { object, string, number } from "pithos/kanon";
19
+ *
20
+ * const schema = object({ name: string(), age: number() });
21
+ *
22
+ * ensure(schema, data)
23
+ * .map(user => user.name.toUpperCase())
24
+ * .mapErr(error => `Validation failed: ${error}`);
25
+ * ```
26
+ */
27
+ export declare function ensure<T>(schema: Schema<T>, input: unknown): Result<T, string>;
28
+ //# sourceMappingURL=ensure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure.d.ts","sourceRoot":"","sources":["../../src/bridges/ensure.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAGnB"}
@@ -0,0 +1,31 @@
1
+ import { parse } from "../kanon/core/parser";
2
+ import { ok, err } from "../zygos/result/result";
3
+ /**
4
+ * Parses a value against a Kanon schema and returns a Zygos `Result`.
5
+ *
6
+ * Bridge between Kanon validation and Zygos error handling:
7
+ * instead of checking `result.success`, you get a chainable `Result<T, string>`.
8
+ *
9
+ * @template T - The expected output type of the schema.
10
+ * @param schema - Kanon schema to validate against.
11
+ * @param input - Value to validate.
12
+ * @returns `Ok<T>` if validation succeeds, `Err<string>` otherwise.
13
+ * @since 2.1.0
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { ensure } from "pithos/bridges/ensure";
18
+ * import { object, string, number } from "pithos/kanon";
19
+ *
20
+ * const schema = object({ name: string(), age: number() });
21
+ *
22
+ * ensure(schema, data)
23
+ * .map(user => user.name.toUpperCase())
24
+ * .mapErr(error => `Validation failed: ${error}`);
25
+ * ```
26
+ */
27
+ export function ensure(schema, input) {
28
+ const result = parse(schema, input);
29
+ return result.success ? ok(result.data) : err(result.error);
30
+ }
31
+ //# sourceMappingURL=ensure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure.js","sourceRoot":"","sources":["../../src/bridges/ensure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAI/C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,MAAM,CACpB,MAAiB,EACjB,KAAc;IAEd,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Schema } from "../kanon/types/base";
2
+ import type { ResultAsync } from "../zygos/result/result-async";
3
+ /**
4
+ * Parses a value against a Kanon schema and returns a Zygos `ResultAsync`.
5
+ *
6
+ * Async variant of `ensure` — designed for `ResultAsync` chains
7
+ * where validation is one step in an async pipeline.
8
+ *
9
+ * @template T - The expected output type of the schema.
10
+ * @param schema - Kanon schema to validate against.
11
+ * @param input - Value to validate.
12
+ * @returns `OkAsync<T>` if validation succeeds, `ErrAsync<string>` otherwise.
13
+ * @since 2.1.0
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { ensureAsync } from "pithos/bridges/ensureAsync";
18
+ * import { object, string, number } from "pithos/kanon";
19
+ *
20
+ * safeFetch("/api/user")
21
+ * .andThen(res => safeJson(res))
22
+ * .andThen(data => ensureAsync(UserSchema, data))
23
+ * .map(user => user.name);
24
+ * ```
25
+ */
26
+ export declare function ensureAsync<T>(schema: Schema<T>, input: unknown): ResultAsync<T, string>;
27
+ //# sourceMappingURL=ensureAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureAsync.d.ts","sourceRoot":"","sources":["../../src/bridges/ensureAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,KAAK,EAAE,OAAO,GACb,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAGxB"}
@@ -0,0 +1,30 @@
1
+ import { parse } from "../kanon/core/parser";
2
+ import { okAsync, errAsync } from "../zygos/result/result-async";
3
+ /**
4
+ * Parses a value against a Kanon schema and returns a Zygos `ResultAsync`.
5
+ *
6
+ * Async variant of `ensure` — designed for `ResultAsync` chains
7
+ * where validation is one step in an async pipeline.
8
+ *
9
+ * @template T - The expected output type of the schema.
10
+ * @param schema - Kanon schema to validate against.
11
+ * @param input - Value to validate.
12
+ * @returns `OkAsync<T>` if validation succeeds, `ErrAsync<string>` otherwise.
13
+ * @since 2.1.0
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { ensureAsync } from "pithos/bridges/ensureAsync";
18
+ * import { object, string, number } from "pithos/kanon";
19
+ *
20
+ * safeFetch("/api/user")
21
+ * .andThen(res => safeJson(res))
22
+ * .andThen(data => ensureAsync(UserSchema, data))
23
+ * .map(user => user.name);
24
+ * ```
25
+ */
26
+ export function ensureAsync(schema, input) {
27
+ const result = parse(schema, input);
28
+ return result.success ? okAsync(result.data) : errAsync(result.error);
29
+ }
30
+ //# sourceMappingURL=ensureAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureAsync.js","sourceRoot":"","sources":["../../src/bridges/ensureAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAI/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,WAAW,CACzB,MAAiB,EACjB,KAAc;IAEd,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { ResultAsync } from "../zygos/result/result-async";
2
+ import type { Schema } from "../kanon/types/base";
3
+ /**
4
+ * Resolves a Promise, validates the result against a Kanon schema,
5
+ * and returns a `ResultAsync`.
6
+ *
7
+ * Eliminates the `ResultAsync.fromPromise(...).andThen(...)` boilerplate
8
+ * when you need to fetch data and validate it in one step.
9
+ *
10
+ * @template T - The expected output type of the schema.
11
+ * @param schema - Kanon schema to validate against.
12
+ * @param promise - Promise that resolves to the value to validate.
13
+ * @returns `ResultAsync<T, string>` — `Ok<T>` if the promise resolves and validation succeeds, `Err<string>` otherwise.
14
+ * @since 2.2.0
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ensurePromise } from "pithos/bridges/ensurePromise";
19
+ * import { object, string, number } from "pithos/kanon";
20
+ *
21
+ * const UserSchema = object({ name: string(), age: number() });
22
+ *
23
+ * ensurePromise(UserSchema, fetch("/api/user").then(r => r.json()))
24
+ * .map(user => user.name.toUpperCase());
25
+ * ```
26
+ */
27
+ export declare function ensurePromise<T>(schema: Schema<T>, promise: Promise<unknown>): ResultAsync<T, string>;
28
+ //# sourceMappingURL=ensurePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensurePromise.d.ts","sourceRoot":"","sources":["../../src/bridges/ensurePromise.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAqB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GACxB,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAQxB"}
@@ -0,0 +1,33 @@
1
+ import { parse } from "../kanon/core/parser";
2
+ import { ResultAsync, okAsync, errAsync } from "../zygos/result/result-async";
3
+ /**
4
+ * Resolves a Promise, validates the result against a Kanon schema,
5
+ * and returns a `ResultAsync`.
6
+ *
7
+ * Eliminates the `ResultAsync.fromPromise(...).andThen(...)` boilerplate
8
+ * when you need to fetch data and validate it in one step.
9
+ *
10
+ * @template T - The expected output type of the schema.
11
+ * @param schema - Kanon schema to validate against.
12
+ * @param promise - Promise that resolves to the value to validate.
13
+ * @returns `ResultAsync<T, string>` — `Ok<T>` if the promise resolves and validation succeeds, `Err<string>` otherwise.
14
+ * @since 2.2.0
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ensurePromise } from "pithos/bridges/ensurePromise";
19
+ * import { object, string, number } from "pithos/kanon";
20
+ *
21
+ * const UserSchema = object({ name: string(), age: number() });
22
+ *
23
+ * ensurePromise(UserSchema, fetch("/api/user").then(r => r.json()))
24
+ * .map(user => user.name.toUpperCase());
25
+ * ```
26
+ */
27
+ export function ensurePromise(schema, promise) {
28
+ return ResultAsync.fromPromise(promise, (e) => e instanceof Error ? e.message : String(e)).andThen((data) => {
29
+ const result = parse(schema, data);
30
+ return result.success ? okAsync(result.data) : errAsync(result.error);
31
+ });
32
+ }
33
+ //# sourceMappingURL=ensurePromise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensurePromise.js","sourceRoot":"","sources":["../../src/bridges/ensurePromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAiB,EACjB,OAAyB;IAEzB,OAAO,WAAW,CAAC,WAAW,CAC5B,OAAO,EACP,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAClD,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithos/core",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Advanced JavaScript/TypeScript superset providing utilities, validation, and functional patterns",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,6 +25,7 @@
25
25
  "./arkhe/types/performance/*": "./dist/arkhe/types/performance/*.js",
26
26
  "./arkhe/types/utilities/*": "./dist/arkhe/types/utilities/*.js",
27
27
  "./arkhe/util/*": "./dist/arkhe/util/*.js",
28
+ "./bridges/*": "./dist/bridges/*.js",
28
29
  "./kanon/core/consts/*": "./dist/kanon/core/consts/*.js",
29
30
  "./kanon/core/*": "./dist/kanon/core/*.js",
30
31
  "./kanon/helpers/*": "./dist/kanon/helpers/*.js",
@@ -70,7 +71,11 @@
70
71
  "utilities",
71
72
  "validation",
72
73
  "functional",
73
- "ecosystem"
74
+ "ecosystem",
75
+ "lodash-alternative",
76
+ "zod-alternative",
77
+ "neverthrow-alternative",
78
+ "fp-ts-alternative"
74
79
  ],
75
80
  "author": "Pierre Moati <mopi1402>",
76
81
  "license": "MIT",
@@ -81,7 +86,7 @@
81
86
  "bugs": {
82
87
  "url": "https://github.com/mopi1402/pithos/issues"
83
88
  },
84
- "homepage": "https://github.com/mopi1402/pithos#readme",
89
+ "homepage": "https://pithos.dev",
85
90
  "engines": {
86
91
  "node": ">=20.0.0"
87
92
  },