@forklaunch/internal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 forklaunch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,73 @@
1
+ import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+ import { InstanceTypeRecord } from '@forklaunch/common';
5
+ import { EntityManager } from '@mikro-orm/core';
6
+
7
+ declare class IdentityRequestMapper<T, SchemaValidator extends AnySchemaValidator> {
8
+ dto: T;
9
+ _Entity: T;
10
+ deserializeDtoToEntity(schemaValidator: SchemaValidator, dto: T): T;
11
+ }
12
+ declare class IdentityResponseMapper<T, SchemaValidator extends AnySchemaValidator> {
13
+ dto: T;
14
+ _Entity: T;
15
+ serializeEntityToDto(schemaValidator: SchemaValidator, entity: T): T;
16
+ }
17
+
18
+ declare function testSchemaEquality<Schematic>(): <Z extends IdiomaticSchema<ZodSchemaValidator>, T extends IdiomaticSchema<TypeboxSchemaValidator>>(zodSchema: Z, typeBoxSchema: T, testData: Schematic extends Schema<Z, ZodSchemaValidator> ? Schema<Z, ZodSchemaValidator> extends Schematic ? Schematic extends Schema<T, TypeboxSchemaValidator> ? Schema<T, TypeboxSchemaValidator> extends Schematic ? Schematic : {
19
+ _success: never;
20
+ } & Schematic : {
21
+ _success: never;
22
+ } & Schematic : {
23
+ _success: never;
24
+ } & Schematic : {
25
+ _success: never;
26
+ } & Schematic) => EqualityWithoutFunction<T, Z>;
27
+ type InjectiveWithoutFunction<O, T> = {
28
+ [K in keyof O]: K extends keyof T ? O[K] extends object ? T[K] extends object ? InjectiveWithoutFunction<O[K], T[K]> : false : O[K] extends (...args: never[]) => unknown ? T[K] extends (...args: never[]) => unknown ? true : false : O[K] extends T[K] ? T[K] extends O[K] ? true : false : false : false;
29
+ } extends infer R ? R extends {
30
+ [K in keyof R]: true;
31
+ } ? true : false : false;
32
+ type EqualityWithoutFunction<T extends IdiomaticSchema<TypeboxSchemaValidator>, Z extends IdiomaticSchema<ZodSchemaValidator>> = Schema<T, TypeboxSchemaValidator> extends infer TypeboxSchema ? Schema<Z, ZodSchemaValidator> extends infer ZodSchema ? InjectiveWithoutFunction<TypeboxSchema, ZodSchema> extends InjectiveWithoutFunction<ZodSchema, TypeboxSchema> ? true : false : false : false;
33
+ declare enum DummyEnum {
34
+ A = "A",
35
+ B = "B"
36
+ }
37
+
38
+ type AllAfterFirstParameters<T> = T extends (first: never, ...args: infer U) => unknown ? U : never[];
39
+ type InternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, {
40
+ dto: unknown;
41
+ _Entity: unknown;
42
+ serializeEntityToDto: unknown;
43
+ } | {
44
+ dto: unknown;
45
+ _Entity: unknown;
46
+ deserializeDtoToEntity: unknown;
47
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>> = {
48
+ [K in keyof DtoMapper]: DtoMapper[K] extends {
49
+ dto: unknown;
50
+ _Entity: unknown;
51
+ serializeEntityToDto: unknown;
52
+ } ? {
53
+ serializeEntityToDto: (schemaValidator: SchemaValidator, entity: Entities[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['serializeEntityToDto']>) => Promise<Dto[K]>;
54
+ } : DtoMapper[K] extends {
55
+ dto: unknown;
56
+ _Entity: unknown;
57
+ deserializeDtoToEntity: unknown;
58
+ } ? {
59
+ deserializeDtoToEntity: (schemaValidator: SchemaValidator, dto: Dto[K], em?: EntityManager, ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['deserializeDtoToEntity']>) => Promise<Entities[K]>;
60
+ } : never;
61
+ };
62
+
63
+ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, new (schemaValidator: SchemaValidator) => {
64
+ dto: unknown;
65
+ _Entity: unknown;
66
+ serializeEntityToDto: unknown;
67
+ } | {
68
+ dto: unknown;
69
+ _Entity: unknown;
70
+ deserializeDtoToEntity: unknown;
71
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(mappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<SchemaValidator, InstanceTypeRecord<DtoMapper>, Entities, Dto>;
72
+
73
+ export { DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, testSchemaEquality, transformIntoInternalDtoMapper };
package/lib/index.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+ import { InstanceTypeRecord } from '@forklaunch/common';
5
+ import { EntityManager } from '@mikro-orm/core';
6
+
7
+ declare class IdentityRequestMapper<T, SchemaValidator extends AnySchemaValidator> {
8
+ dto: T;
9
+ _Entity: T;
10
+ deserializeDtoToEntity(schemaValidator: SchemaValidator, dto: T): T;
11
+ }
12
+ declare class IdentityResponseMapper<T, SchemaValidator extends AnySchemaValidator> {
13
+ dto: T;
14
+ _Entity: T;
15
+ serializeEntityToDto(schemaValidator: SchemaValidator, entity: T): T;
16
+ }
17
+
18
+ declare function testSchemaEquality<Schematic>(): <Z extends IdiomaticSchema<ZodSchemaValidator>, T extends IdiomaticSchema<TypeboxSchemaValidator>>(zodSchema: Z, typeBoxSchema: T, testData: Schematic extends Schema<Z, ZodSchemaValidator> ? Schema<Z, ZodSchemaValidator> extends Schematic ? Schematic extends Schema<T, TypeboxSchemaValidator> ? Schema<T, TypeboxSchemaValidator> extends Schematic ? Schematic : {
19
+ _success: never;
20
+ } & Schematic : {
21
+ _success: never;
22
+ } & Schematic : {
23
+ _success: never;
24
+ } & Schematic : {
25
+ _success: never;
26
+ } & Schematic) => EqualityWithoutFunction<T, Z>;
27
+ type InjectiveWithoutFunction<O, T> = {
28
+ [K in keyof O]: K extends keyof T ? O[K] extends object ? T[K] extends object ? InjectiveWithoutFunction<O[K], T[K]> : false : O[K] extends (...args: never[]) => unknown ? T[K] extends (...args: never[]) => unknown ? true : false : O[K] extends T[K] ? T[K] extends O[K] ? true : false : false : false;
29
+ } extends infer R ? R extends {
30
+ [K in keyof R]: true;
31
+ } ? true : false : false;
32
+ type EqualityWithoutFunction<T extends IdiomaticSchema<TypeboxSchemaValidator>, Z extends IdiomaticSchema<ZodSchemaValidator>> = Schema<T, TypeboxSchemaValidator> extends infer TypeboxSchema ? Schema<Z, ZodSchemaValidator> extends infer ZodSchema ? InjectiveWithoutFunction<TypeboxSchema, ZodSchema> extends InjectiveWithoutFunction<ZodSchema, TypeboxSchema> ? true : false : false : false;
33
+ declare enum DummyEnum {
34
+ A = "A",
35
+ B = "B"
36
+ }
37
+
38
+ type AllAfterFirstParameters<T> = T extends (first: never, ...args: infer U) => unknown ? U : never[];
39
+ type InternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, {
40
+ dto: unknown;
41
+ _Entity: unknown;
42
+ serializeEntityToDto: unknown;
43
+ } | {
44
+ dto: unknown;
45
+ _Entity: unknown;
46
+ deserializeDtoToEntity: unknown;
47
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>> = {
48
+ [K in keyof DtoMapper]: DtoMapper[K] extends {
49
+ dto: unknown;
50
+ _Entity: unknown;
51
+ serializeEntityToDto: unknown;
52
+ } ? {
53
+ serializeEntityToDto: (schemaValidator: SchemaValidator, entity: Entities[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['serializeEntityToDto']>) => Promise<Dto[K]>;
54
+ } : DtoMapper[K] extends {
55
+ dto: unknown;
56
+ _Entity: unknown;
57
+ deserializeDtoToEntity: unknown;
58
+ } ? {
59
+ deserializeDtoToEntity: (schemaValidator: SchemaValidator, dto: Dto[K], em?: EntityManager, ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['deserializeDtoToEntity']>) => Promise<Entities[K]>;
60
+ } : never;
61
+ };
62
+
63
+ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, new (schemaValidator: SchemaValidator) => {
64
+ dto: unknown;
65
+ _Entity: unknown;
66
+ serializeEntityToDto: unknown;
67
+ } | {
68
+ dto: unknown;
69
+ _Entity: unknown;
70
+ deserializeDtoToEntity: unknown;
71
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(mappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<SchemaValidator, InstanceTypeRecord<DtoMapper>, Entities, Dto>;
72
+
73
+ export { DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, testSchemaEquality, transformIntoInternalDtoMapper };
package/lib/index.js ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ DummyEnum: () => DummyEnum,
24
+ IdentityRequestMapper: () => IdentityRequestMapper,
25
+ IdentityResponseMapper: () => IdentityResponseMapper,
26
+ testSchemaEquality: () => testSchemaEquality,
27
+ transformIntoInternalDtoMapper: () => transformIntoInternalDtoMapper
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/identityMappers.ts
32
+ var IdentityRequestMapper = class {
33
+ dto;
34
+ _Entity;
35
+ deserializeDtoToEntity(schemaValidator, dto) {
36
+ return dto;
37
+ }
38
+ };
39
+ var IdentityResponseMapper = class {
40
+ dto;
41
+ _Entity;
42
+ serializeEntityToDto(schemaValidator, entity) {
43
+ return entity;
44
+ }
45
+ };
46
+
47
+ // src/schemaEquality.ts
48
+ var import_common = require("@forklaunch/common");
49
+ var import_typebox = require("@forklaunch/validator/typebox");
50
+ var import_zod = require("@forklaunch/validator/zod");
51
+ function testSchemaEquality() {
52
+ return (zodSchema, typeBoxSchema, testData) => {
53
+ const zodParseResult = (0, import_zod.parse)(zodSchema, testData);
54
+ const typeboxParseResult = (0, import_typebox.parse)(typeBoxSchema, testData);
55
+ const isEqual = (0, import_common.safeStringify)(
56
+ zodParseResult.ok ? (0, import_common.sortObjectKeys)(zodParseResult.value) : "-1"
57
+ ) === (0, import_common.safeStringify)(
58
+ typeboxParseResult.ok ? (0, import_common.sortObjectKeys)(typeboxParseResult.value) : "1"
59
+ );
60
+ return isEqual;
61
+ };
62
+ }
63
+ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
64
+ DummyEnum2["A"] = "A";
65
+ DummyEnum2["B"] = "B";
66
+ return DummyEnum2;
67
+ })(DummyEnum || {});
68
+
69
+ // src/transformIntoInternalDtoMapper.ts
70
+ function transformIntoInternalDtoMapper(mappers, schemaValidator) {
71
+ return Object.fromEntries(
72
+ Object.entries(mappers).map(([key, value]) => [
73
+ key,
74
+ new value(schemaValidator)
75
+ ])
76
+ );
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ DummyEnum,
81
+ IdentityRequestMapper,
82
+ IdentityResponseMapper,
83
+ testSchemaEquality,
84
+ transformIntoInternalDtoMapper
85
+ });
package/lib/index.mjs ADDED
@@ -0,0 +1,58 @@
1
+ // src/identityMappers.ts
2
+ var IdentityRequestMapper = class {
3
+ dto;
4
+ _Entity;
5
+ deserializeDtoToEntity(schemaValidator, dto) {
6
+ return dto;
7
+ }
8
+ };
9
+ var IdentityResponseMapper = class {
10
+ dto;
11
+ _Entity;
12
+ serializeEntityToDto(schemaValidator, entity) {
13
+ return entity;
14
+ }
15
+ };
16
+
17
+ // src/schemaEquality.ts
18
+ import { safeStringify, sortObjectKeys } from "@forklaunch/common";
19
+ import {
20
+ parse as typeboxParse
21
+ } from "@forklaunch/validator/typebox";
22
+ import {
23
+ parse as zodParse
24
+ } from "@forklaunch/validator/zod";
25
+ function testSchemaEquality() {
26
+ return (zodSchema, typeBoxSchema, testData) => {
27
+ const zodParseResult = zodParse(zodSchema, testData);
28
+ const typeboxParseResult = typeboxParse(typeBoxSchema, testData);
29
+ const isEqual = safeStringify(
30
+ zodParseResult.ok ? sortObjectKeys(zodParseResult.value) : "-1"
31
+ ) === safeStringify(
32
+ typeboxParseResult.ok ? sortObjectKeys(typeboxParseResult.value) : "1"
33
+ );
34
+ return isEqual;
35
+ };
36
+ }
37
+ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
38
+ DummyEnum2["A"] = "A";
39
+ DummyEnum2["B"] = "B";
40
+ return DummyEnum2;
41
+ })(DummyEnum || {});
42
+
43
+ // src/transformIntoInternalDtoMapper.ts
44
+ function transformIntoInternalDtoMapper(mappers, schemaValidator) {
45
+ return Object.fromEntries(
46
+ Object.entries(mappers).map(([key, value]) => [
47
+ key,
48
+ new value(schemaValidator)
49
+ ])
50
+ );
51
+ }
52
+ export {
53
+ DummyEnum,
54
+ IdentityRequestMapper,
55
+ IdentityResponseMapper,
56
+ testSchemaEquality,
57
+ transformIntoInternalDtoMapper
58
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@forklaunch/internal",
3
+ "version": "0.0.1",
4
+ "description": "Internal package for utilities and other internal code.",
5
+ "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/forklaunch/forklaunch-js/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/forklaunch/forklaunch-js.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Rohin Bhargava",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/index.d.ts",
18
+ "import": "./lib/index.mjs",
19
+ "require": "./lib/index.js",
20
+ "default": "./lib/index.js"
21
+ }
22
+ },
23
+ "types": "lib/index.d.ts",
24
+ "directories": {
25
+ "test": "__test__"
26
+ },
27
+ "files": [
28
+ "lib/**"
29
+ ],
30
+ "dependencies": {
31
+ "@mikro-orm/core": "^6.4.16",
32
+ "@forklaunch/common": "0.3.13",
33
+ "@forklaunch/validator": "0.6.15"
34
+ },
35
+ "devDependencies": {
36
+ "@eslint/js": "^9.29.0",
37
+ "@types/node": "^24.0.3",
38
+ "@typescript/native-preview": "7.0.0-dev.20250619.1",
39
+ "depcheck": "^1.4.7",
40
+ "eslint": "^9.29.0",
41
+ "globals": "^16.2.0",
42
+ "tsup": "^8.5.0",
43
+ "typedoc": "^0.28.5",
44
+ "typescript": "^5.8.3",
45
+ "typescript-eslint": "^8.34.1",
46
+ "vitest": "^3.2.4"
47
+ },
48
+ "scripts": {
49
+ "build": "tsgo --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",
50
+ "check": "depcheck",
51
+ "clean": "rm -rf lib pnpm.lock.yaml node_modules",
52
+ "docs": "typedoc --out docs *",
53
+ "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
54
+ "lint": "eslint . -c eslint.config.mjs",
55
+ "lint:fix": "eslint . -c eslint.config.mjs --fix",
56
+ "publish:package": "./publish-package.bash",
57
+ "test": "vitest --passWithNoTests"
58
+ }
59
+ }