relation-matcher 1.0.11 → 1.0.12

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/.yarnrc.yml CHANGED
@@ -1 +1,3 @@
1
1
  nodeLinker: node-modules
2
+
3
+ yarnPath: .yarn/releases/yarn-4.13.0.cjs
@@ -1,7 +1,6 @@
1
1
  import type { TInputBase } from "./types/generic-bases";
2
2
  import type { RelationMapRoot } from "./types/inputs";
3
3
  import type { RelationMapperReturnRoot } from "./types/return";
4
- export declare const relationMatcher: <TInput extends TInputBase, TOutputRoot extends RelationMapRoot<TInput>>(inputs: TInput[], output: TOutputRoot) => Record<string, RelationMapperReturnRoot<TInput, TOutputRoot>>;
5
- /** @deprecated Use `relationMatcher`. */
6
4
  export declare const relationMatcherRoot: <TInput extends TInputBase, TOutputRoot extends RelationMapRoot<TInput>>(inputs: TInput[], output: TOutputRoot) => Record<string, RelationMapperReturnRoot<TInput, TOutputRoot>>;
7
- export default relationMatcher;
5
+ export declare const relationMatcher: <TInput extends TInputBase, TOutputRoot extends RelationMapRoot<TInput>>(inputs: TInput[], output: TOutputRoot) => Record<string, RelationMapperReturnRoot<TInput, TOutputRoot>>;
6
+ export default relationMatcherRoot;
package/dist/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import invertInput, {} from "./utils/invertInput";
2
2
  import { getJoinFinalKey } from "./utils/keys";
3
3
  import { matcherFunc } from "./utils/matcher";
4
- export const relationMatcher = (inputs, output) => {
4
+ export const relationMatcherRoot = (inputs, output) => {
5
5
  if (!inputs.length)
6
6
  return {};
7
7
  if (!Array.isArray(inputs)) {
@@ -44,9 +44,8 @@ export const relationMatcher = (inputs, output) => {
44
44
  }, {});
45
45
  return baseItems;
46
46
  };
47
- /** @deprecated Use `relationMatcher`. */
48
- export const relationMatcherRoot = relationMatcher;
49
- export default relationMatcher;
47
+ export const relationMatcher = relationMatcherRoot;
48
+ export default relationMatcherRoot;
50
49
  const relationMatcherJoiner = (input, output, joiningFrom) => {
51
50
  return Object.entries(output).reduce((final, [key, value]) => {
52
51
  if (typeof value === "object") {
@@ -1,4 +1,3 @@
1
- import type { RelationMapRoot } from "~/types/inputs";
2
1
  export declare const testData: ({
3
2
  users: {
4
3
  id: string;
@@ -69,4 +68,35 @@ export declare const testData: ({
69
68
  posts: null;
70
69
  comments: null;
71
70
  })[];
72
- export declare const testSchema: RelationMapRoot<(typeof testData)[number]>;
71
+ export declare const testSchema: {
72
+ base: "users";
73
+ id: "id";
74
+ _teamToUsers: {
75
+ base: "teamToUser";
76
+ id: "teamId";
77
+ joinsFrom: "id";
78
+ joinsTo: "userId";
79
+ joinType: "array";
80
+ _team: {
81
+ base: "teams";
82
+ id: "id";
83
+ joinsFrom: "teamId";
84
+ joinsTo: "id";
85
+ joinType: "single";
86
+ };
87
+ };
88
+ _posts: {
89
+ base: "posts";
90
+ id: "id";
91
+ joinsFrom: "id";
92
+ joinsTo: "userId";
93
+ joinType: "array";
94
+ _comments: {
95
+ base: "comments";
96
+ id: "id";
97
+ joinsFrom: "id";
98
+ joinsTo: "postId";
99
+ joinType: "array";
100
+ };
101
+ };
102
+ };
@@ -1,11 +1,9 @@
1
1
  import type { TInputBase, TJoinedFromBase, TOutputBase } from "./generic-bases";
2
2
  import type { RelationMapRoot } from "./inputs";
3
3
  import type { ExtendsNull, NoUnderscore, Simplify } from "./utils";
4
- export type RelationMapperReturnRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>> = Simplify<{
5
- [inputKey in keyof TInput]: ExtendsNull<TInput[TOutput["base"]]> extends true ? Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, inputKey>> | null : Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, inputKey>>;
6
- }[keyof TInput]>;
4
+ export type RelationMapperReturnRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>> = Simplify<ExtendsNull<TInput[TOutput["base"]]> extends true ? (TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, TOutput["base"]>) | null : TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, TOutput["base"]>>;
7
5
  export type RelationMapperReturnJoinRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>, TInputKey extends keyof TInput> = {
8
- [outputKey in NoUnderscore<keyof TOutput>]: Simplify<RelationMapperReturn<TInput, TInput[TInputKey], TOutput[`_${outputKey}`]>>;
6
+ [outputKey in NoUnderscore<keyof TOutput>]: RelationMapperReturn<TInput, TInput[TInputKey], TOutput[`_${outputKey}`]>;
9
7
  };
10
8
  /** Fill current object with value specified in base */
11
9
  export type RelationMapperReturn<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase, TOutput extends TOutputBase<TInput, TJoinedFrom>> = TOutput["joinType"] extends "array" ? Array<Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>>> : ExtendsNull<TInput[TOutput["base"]]> extends true ? Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>> | null : Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>>;