joist-graphql-resolver-utils 2.3.0-next.9 → 2.3.0-next.91
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/build/context.cjs +2 -0
- package/build/context.d.cts +7 -0
- package/build/context.d.cts.map +1 -0
- package/build/context.d.mts +7 -0
- package/build/context.d.mts.map +1 -0
- package/build/context.js +2 -3
- package/build/cursorPagination.cjs +110 -0
- package/build/cursorPagination.cjs.map +1 -0
- package/build/cursorPagination.d.cts +43 -0
- package/build/cursorPagination.d.cts.map +1 -0
- package/build/cursorPagination.d.mts +43 -0
- package/build/cursorPagination.d.mts.map +1 -0
- package/build/cursorPagination.js +94 -62
- package/build/cursorPagination.js.map +1 -1
- package/build/entityResolver.cjs +95 -0
- package/build/entityResolver.cjs.map +1 -0
- package/build/entityResolver.d.cts +23 -0
- package/build/entityResolver.d.cts.map +1 -0
- package/build/entityResolver.d.mts +23 -0
- package/build/entityResolver.d.mts.map +1 -0
- package/build/entityResolver.js +84 -135
- package/build/entityResolver.js.map +1 -1
- package/build/hint.cjs +50 -0
- package/build/hint.cjs.map +1 -0
- package/build/hint.d.cts +12 -0
- package/build/hint.d.cts.map +1 -0
- package/build/hint.d.mts +12 -0
- package/build/hint.d.mts.map +1 -0
- package/build/hint.js +36 -65
- package/build/hint.js.map +1 -1
- package/build/index.cjs +14 -0
- package/build/index.d.cts +6 -0
- package/build/index.d.mts +6 -0
- package/build/index.js +6 -17
- package/build/limitPagination.cjs +68 -0
- package/build/limitPagination.cjs.map +1 -0
- package/build/limitPagination.d.cts +34 -0
- package/build/limitPagination.d.cts.map +1 -0
- package/build/limitPagination.d.mts +34 -0
- package/build/limitPagination.d.mts.map +1 -0
- package/build/limitPagination.js +62 -52
- package/build/limitPagination.js.map +1 -1
- package/build/makeRunInputMutation.cjs +21 -0
- package/build/makeRunInputMutation.cjs.map +1 -0
- package/build/{makeRunInputMutation.d.ts → makeRunInputMutation.d.cts} +9 -7
- package/build/makeRunInputMutation.d.cts.map +1 -0
- package/build/makeRunInputMutation.d.mts +24 -0
- package/build/makeRunInputMutation.d.mts.map +1 -0
- package/build/makeRunInputMutation.js +16 -14
- package/build/makeRunInputMutation.js.map +1 -1
- package/build/makeRunObjectField.cjs +22 -0
- package/build/makeRunObjectField.cjs.map +1 -0
- package/build/{makeRunObjectField.d.ts → makeRunObjectField.d.cts} +7 -5
- package/build/makeRunObjectField.d.cts.map +1 -0
- package/build/makeRunObjectField.d.mts +16 -0
- package/build/makeRunObjectField.d.mts.map +1 -0
- package/build/makeRunObjectField.js +17 -16
- package/build/makeRunObjectField.js.map +1 -1
- package/build/makeRunObjectFields.cjs +24 -0
- package/build/makeRunObjectFields.cjs.map +1 -0
- package/build/{makeRunObjectFields.d.ts → makeRunObjectFields.d.cts} +8 -8
- package/build/makeRunObjectFields.d.cts.map +1 -0
- package/build/makeRunObjectFields.d.mts +15 -0
- package/build/makeRunObjectFields.d.mts.map +1 -0
- package/build/makeRunObjectFields.js +19 -19
- package/build/makeRunObjectFields.js.map +1 -1
- package/build/makeRunQuery.cjs +20 -0
- package/build/makeRunQuery.cjs.map +1 -0
- package/build/{makeRunQuery.d.ts → makeRunQuery.d.cts} +7 -5
- package/build/makeRunQuery.d.cts.map +1 -0
- package/build/makeRunQuery.d.mts +20 -0
- package/build/makeRunQuery.d.mts.map +1 -0
- package/build/makeRunQuery.js +15 -14
- package/build/makeRunQuery.js.map +1 -1
- package/build/paginationUtils.cjs +34 -0
- package/build/paginationUtils.cjs.map +1 -0
- package/build/paginationUtils.d.cts +17 -0
- package/build/paginationUtils.d.cts.map +1 -0
- package/build/paginationUtils.d.mts +17 -0
- package/build/paginationUtils.d.mts.map +1 -0
- package/build/paginationUtils.js +30 -4
- package/build/paginationUtils.js.map +1 -1
- package/build/saveEntity.cjs +24 -0
- package/build/saveEntity.cjs.map +1 -0
- package/build/saveEntity.d.cts +15 -0
- package/build/saveEntity.d.cts.map +1 -0
- package/build/saveEntity.d.mts +15 -0
- package/build/saveEntity.d.mts.map +1 -0
- package/build/saveEntity.js +15 -13
- package/build/saveEntity.js.map +1 -1
- package/build/tests.cjs +9 -0
- package/build/tests.d.cts +6 -0
- package/build/tests.d.mts +6 -0
- package/build/tests.js +5 -27
- package/build/typeUtils.cjs +2 -0
- package/build/typeUtils.d.cts +11 -0
- package/build/typeUtils.d.cts.map +1 -0
- package/build/typeUtils.d.mts +11 -0
- package/build/typeUtils.d.mts.map +1 -0
- package/build/typeUtils.js +2 -3
- package/package.json +74 -16
- package/build/context.d.ts +0 -4
- package/build/context.d.ts.map +0 -1
- package/build/context.js.map +0 -1
- package/build/cursorPagination.d.ts +0 -33
- package/build/cursorPagination.d.ts.map +0 -1
- package/build/entityResolver.d.ts +0 -25
- package/build/entityResolver.d.ts.map +0 -1
- package/build/hint.d.ts +0 -9
- package/build/hint.d.ts.map +0 -1
- package/build/index.d.ts +0 -6
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/build/limitPagination.d.ts +0 -28
- package/build/limitPagination.d.ts.map +0 -1
- package/build/makeRunInputMutation.d.ts.map +0 -1
- package/build/makeRunObjectField.d.ts.map +0 -1
- package/build/makeRunObjectFields.d.ts.map +0 -1
- package/build/makeRunQuery.d.ts.map +0 -1
- package/build/paginationUtils.d.ts +0 -7
- package/build/paginationUtils.d.ts.map +0 -1
- package/build/saveEntity.d.ts +0 -12
- package/build/saveEntity.d.ts.map +0 -1
- package/build/tests.d.ts +0 -6
- package/build/tests.d.ts.map +0 -1
- package/build/tests.js.map +0 -1
- package/build/typeUtils.d.ts +0 -10
- package/build/typeUtils.d.ts.map +0 -1
- package/build/typeUtils.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./typeUtils.cjs");
|
|
3
|
+
let joist_core = require("joist-core");
|
|
4
|
+
//#region src/makeRunObjectFields.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `makeRunObjectFields` function for each project's `testUtils` file.
|
|
7
|
+
*
|
|
8
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
9
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
10
|
+
*/
|
|
11
|
+
function makeMakeRunObjectFields(runFn) {
|
|
12
|
+
return (resolver) => {
|
|
13
|
+
return (ctx, root, fields) => {
|
|
14
|
+
return runFn(ctx, async (ctx) => {
|
|
15
|
+
const _root = (0, joist_core.isEntity)(root) ? await ctx.em.load(root.id) : root;
|
|
16
|
+
return Object.fromEntries(await Promise.all(fields.map(async (key) => [key, await resolver[key](_root, {}, ctx, void 0)])));
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.makeMakeRunObjectFields = makeMakeRunObjectFields;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=makeRunObjectFields.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectFields.cjs","names":["isEntity"],"sources":["../src/makeRunObjectFields.ts"],"sourcesContent":["import { isEntity } from \"joist-core\";\n\nimport { type ResolverResult, type ResolverRoot, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunObjectFields` function for each project's `testUtils` file.\n *\n * This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory\n * that is customized (basically curried) to their own `newContext` function.\n */\nexport function makeMakeRunObjectFields<C, T>(runFn: RunFn<C>): MakeRunObjectFields<C> {\n return (resolver) => {\n return (ctx, root, fields) => {\n return runFn(ctx, async (ctx) => {\n // Sneak in a Joist-ism that will load the entity in the new em\n const _root = isEntity(root) ? await (ctx as any).em.load((root as any).id) : root;\n // Build a result with each key, where fields might return a promise, so we `await` to make assertions easier\n return Object.fromEntries(\n await Promise.all(fields.map(async (key) => [key, await (resolver[key] as any)(_root, {}, ctx, undefined!)])),\n );\n });\n };\n };\n}\n\n/** Creates a `run` method that can invoke multiple fields against an object resolver. */\nexport type MakeRunObjectFields<C> = <T, R extends ResolverRoot<T>>(resolvers: T) => RunFieldsResolverMethod<C, T, R>;\n\n// The return type for makeRunResolverKeys\ntype RunFieldsResolverMethod<C, T, R extends ResolverRoot<T>> = <K extends (keyof T)[]>(\n ctx: C,\n root: R,\n keys: K,\n) => Promise<{ [k in K[number]]: ResolverResult<T, k> }>;\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,wBAA8B,OAAyC;CACrF,QAAQ,aAAa;EACnB,QAAQ,KAAK,MAAM,WAAW;GAC5B,OAAO,MAAM,KAAK,OAAO,QAAQ;IAE/B,MAAM,SAAA,GAAQA,WAAAA,SAAAA,CAAS,IAAI,IAAI,MAAO,IAAY,GAAG,KAAM,KAAa,EAAE,IAAI;IAE9E,OAAO,OAAO,YACZ,MAAM,QAAQ,IAAI,OAAO,IAAI,OAAO,QAAQ,CAAC,KAAK,MAAO,SAAS,IAAI,CAAS,OAAO,CAAC,GAAG,KAAK,KAAA,CAAU,CAAC,CAAC,CAAC,CAC9G;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ResolverResult, ResolverRoot, RunFn } from "./typeUtils";
|
|
1
|
+
import { ResolverResult, ResolverRoot, RunFn } from "./typeUtils.cjs";
|
|
2
|
+
//#region src/makeRunObjectFields.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Creates a `makeRunObjectFields` function for each project's `testUtils` file.
|
|
4
5
|
*
|
|
5
6
|
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
6
7
|
* that is customized (basically curried) to their own `newContext` function.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function makeMakeRunObjectFields<C, T>(runFn: RunFn<C>): MakeRunObjectFields<C>;
|
|
9
10
|
/** Creates a `run` method that can invoke multiple fields against an object resolver. */
|
|
10
|
-
|
|
11
|
-
type RunFieldsResolverMethod<C, T, R extends ResolverRoot<T>> = <K extends (keyof T)[]>(ctx: C, root: R, keys: K) => Promise<{
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=makeRunObjectFields.d.ts.map
|
|
11
|
+
type MakeRunObjectFields<C> = <T, R extends ResolverRoot<T>>(resolvers: T) => RunFieldsResolverMethod<C, T, R>;
|
|
12
|
+
type RunFieldsResolverMethod<C, T, R extends ResolverRoot<T>> = <K extends (keyof T)[]>(ctx: C, root: R, keys: K) => Promise<{ [k in K[number]]: ResolverResult<T, k>; }>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { MakeRunObjectFields, makeMakeRunObjectFields };
|
|
15
|
+
//# sourceMappingURL=makeRunObjectFields.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectFields.d.cts","names":[],"sources":["../src/makeRunObjectFields.ts"],"mappings":";;;;;;;;iBAUgB,wBAAwB,GAAG,GAAG,OAAO,MAAM,KAAK,oBAAoB;;KAgBxE,oBAAoB,MAAM,GAAG,UAAU,aAAa,IAAI,WAAW,MAAM,wBAAwB,GAAG,GAAG;KAG9G,wBAAwB,GAAG,GAAG,UAAU,aAAa,OAAO,iBAAiB,MAChF,KAAK,GACL,MAAM,GACN,MAAM,MACH,WAAW,KAAK,YAAY,eAAe,GAAG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResolverResult, ResolverRoot, RunFn } from "./typeUtils.mjs";
|
|
2
|
+
//#region src/makeRunObjectFields.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `makeRunObjectFields` function for each project's `testUtils` file.
|
|
5
|
+
*
|
|
6
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
7
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
8
|
+
*/
|
|
9
|
+
declare function makeMakeRunObjectFields<C, T>(runFn: RunFn<C>): MakeRunObjectFields<C>;
|
|
10
|
+
/** Creates a `run` method that can invoke multiple fields against an object resolver. */
|
|
11
|
+
type MakeRunObjectFields<C> = <T, R extends ResolverRoot<T>>(resolvers: T) => RunFieldsResolverMethod<C, T, R>;
|
|
12
|
+
type RunFieldsResolverMethod<C, T, R extends ResolverRoot<T>> = <K extends (keyof T)[]>(ctx: C, root: R, keys: K) => Promise<{ [k in K[number]]: ResolverResult<T, k>; }>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { MakeRunObjectFields, makeMakeRunObjectFields };
|
|
15
|
+
//# sourceMappingURL=makeRunObjectFields.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectFields.d.mts","names":[],"sources":["../src/makeRunObjectFields.ts"],"mappings":";;;;;;;;iBAUgB,wBAAwB,GAAG,GAAG,OAAO,MAAM,KAAK,oBAAoB;;KAgBxE,oBAAoB,MAAM,GAAG,UAAU,aAAa,IAAI,WAAW,MAAM,wBAAwB,GAAG,GAAG;KAG9G,wBAAwB,GAAG,GAAG,UAAU,aAAa,OAAO,iBAAiB,MAChF,KAAK,GACL,MAAM,GACN,MAAM,MACH,WAAW,KAAK,YAAY,eAAe,GAAG"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const joist_core_1 = require("joist-core");
|
|
1
|
+
import "./typeUtils.js";
|
|
2
|
+
import { isEntity } from "joist-core";
|
|
3
|
+
//#region src/makeRunObjectFields.ts
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
* Creates a `makeRunObjectFields` function for each project's `testUtils` file.
|
|
6
|
+
*
|
|
7
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
8
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
9
|
+
*/
|
|
11
10
|
function makeMakeRunObjectFields(runFn) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
};
|
|
11
|
+
return (resolver) => {
|
|
12
|
+
return (ctx, root, fields) => {
|
|
13
|
+
return runFn(ctx, async (ctx) => {
|
|
14
|
+
const _root = isEntity(root) ? await ctx.em.load(root.id) : root;
|
|
15
|
+
return Object.fromEntries(await Promise.all(fields.map(async (key) => [key, await resolver[key](_root, {}, ctx, void 0)])));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
22
19
|
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { makeMakeRunObjectFields };
|
|
22
|
+
|
|
23
23
|
//# sourceMappingURL=makeRunObjectFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeRunObjectFields.js","
|
|
1
|
+
{"version":3,"file":"makeRunObjectFields.js","names":[],"sources":["../src/makeRunObjectFields.ts"],"sourcesContent":["import { isEntity } from \"joist-core\";\n\nimport { type ResolverResult, type ResolverRoot, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunObjectFields` function for each project's `testUtils` file.\n *\n * This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory\n * that is customized (basically curried) to their own `newContext` function.\n */\nexport function makeMakeRunObjectFields<C, T>(runFn: RunFn<C>): MakeRunObjectFields<C> {\n return (resolver) => {\n return (ctx, root, fields) => {\n return runFn(ctx, async (ctx) => {\n // Sneak in a Joist-ism that will load the entity in the new em\n const _root = isEntity(root) ? await (ctx as any).em.load((root as any).id) : root;\n // Build a result with each key, where fields might return a promise, so we `await` to make assertions easier\n return Object.fromEntries(\n await Promise.all(fields.map(async (key) => [key, await (resolver[key] as any)(_root, {}, ctx, undefined!)])),\n );\n });\n };\n };\n}\n\n/** Creates a `run` method that can invoke multiple fields against an object resolver. */\nexport type MakeRunObjectFields<C> = <T, R extends ResolverRoot<T>>(resolvers: T) => RunFieldsResolverMethod<C, T, R>;\n\n// The return type for makeRunResolverKeys\ntype RunFieldsResolverMethod<C, T, R extends ResolverRoot<T>> = <K extends (keyof T)[]>(\n ctx: C,\n root: R,\n keys: K,\n) => Promise<{ [k in K[number]]: ResolverResult<T, k> }>;\n"],"mappings":";;;;;;;;;AAUA,SAAgB,wBAA8B,OAAyC;CACrF,QAAQ,aAAa;EACnB,QAAQ,KAAK,MAAM,WAAW;GAC5B,OAAO,MAAM,KAAK,OAAO,QAAQ;IAE/B,MAAM,QAAQ,SAAS,IAAI,IAAI,MAAO,IAAY,GAAG,KAAM,KAAa,EAAE,IAAI;IAE9E,OAAO,OAAO,YACZ,MAAM,QAAQ,IAAI,OAAO,IAAI,OAAO,QAAQ,CAAC,KAAK,MAAO,SAAS,IAAI,CAAS,OAAO,CAAC,GAAG,KAAK,KAAA,CAAU,CAAC,CAAC,CAAC,CAC9G;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./typeUtils.cjs");
|
|
3
|
+
//#region src/makeRunQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a `makeRunQuery` function for each project's `testUtils` file.
|
|
6
|
+
*
|
|
7
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
8
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
9
|
+
*/
|
|
10
|
+
function makeMakeRunQuery(runFn) {
|
|
11
|
+
return (resolver) => {
|
|
12
|
+
return (ctx, args) => runFn(ctx, async (ctx) => {
|
|
13
|
+
return resolver[Object.keys(resolver)[0]]({}, args instanceof Function ? args() : args ?? {}, ctx, void 0);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.makeMakeRunQuery = makeMakeRunQuery;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=makeRunQuery.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunQuery.cjs","names":[],"sources":["../src/makeRunQuery.ts"],"sourcesContent":["import { type ResolverArgs, type ResolverResult, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunQuery` function for each project's `testUtils` file.\n *\n * This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory\n * that is customized (basically curried) to their own `newContext` function.\n */\nexport function makeMakeRunQuery<C>(runFn: RunFn<C>): MakeRunQuery<C> {\n return (resolver) => {\n return (ctx, args) =>\n runFn(ctx, async (ctx) => {\n const key = Object.keys(resolver)[0];\n return ((resolver as any)[key] as any)({}, args instanceof Function ? args() : (args ?? {}), ctx, undefined!);\n });\n };\n}\n\n/**\n * Creates a `run` method that invokes the query resolver's single query.\n *\n * Following our `query / foo` conventions, query resolver will have a single `fooResolver.foo` method.\n */\nexport type MakeRunQuery<C> = <T extends object>(resolver: T) => RunQueryMethod<C, T>;\n\n/** The return type of `makeRunQuery`. */\ntype RunQueryMethod<C, T> = <A extends ResolverArgs<T, keyof T>>(\n ctx: C,\n // Support either the resolver arg directly or a lambda to create the args post-flush\n args?: A | (() => A),\n) => Promise<ResolverResult<T, keyof T>>;\n"],"mappings":";;;;;;;;;AAQA,SAAgB,iBAAoB,OAAkC;CACpE,QAAQ,aAAa;EACnB,QAAQ,KAAK,SACX,MAAM,KAAK,OAAO,QAAQ;GAExB,OAAS,SADG,OAAO,KAAK,QAAQ,CAAC,CAAC,GACJ,CAAS,CAAC,GAAG,gBAAgB,WAAW,KAAK,IAAK,QAAQ,CAAC,GAAI,KAAK,KAAA,CAAU;EAC9G,CAAC;CACL;AACF"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { ResolverArgs, ResolverResult, RunFn } from "./typeUtils";
|
|
1
|
+
import { ResolverArgs, ResolverResult, RunFn } from "./typeUtils.cjs";
|
|
2
|
+
//#region src/makeRunQuery.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Creates a `makeRunQuery` function for each project's `testUtils` file.
|
|
4
5
|
*
|
|
5
6
|
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
6
7
|
* that is customized (basically curried) to their own `newContext` function.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function makeMakeRunQuery<C>(runFn: RunFn<C>): MakeRunQuery<C>;
|
|
9
10
|
/**
|
|
10
11
|
* Creates a `run` method that invokes the query resolver's single query.
|
|
11
12
|
*
|
|
12
13
|
* Following our `query / foo` conventions, query resolver will have a single `fooResolver.foo` method.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
type MakeRunQuery<C> = <T extends object>(resolver: T) => RunQueryMethod<C, T>;
|
|
15
16
|
/** The return type of `makeRunQuery`. */
|
|
16
17
|
type RunQueryMethod<C, T> = <A extends ResolverArgs<T, keyof T>>(ctx: C, args?: A | (() => A)) => Promise<ResolverResult<T, keyof T>>;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MakeRunQuery, makeMakeRunQuery };
|
|
20
|
+
//# sourceMappingURL=makeRunQuery.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunQuery.d.cts","names":[],"sources":["../src/makeRunQuery.ts"],"mappings":";;;;;;;;iBAQgB,iBAAiB,GAAG,OAAO,MAAM,KAAK,aAAa;;;;;;KAevD,aAAa,MAAM,kBAAkB,UAAU,MAAM,eAAe,GAAG;;KAG9E,eAAe,GAAG,MAAM,UAAU,aAAa,SAAS,IAC3D,KAAK,GAEL,OAAO,WAAW,OACf,QAAQ,eAAe,SAAS"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ResolverArgs, ResolverResult, RunFn } from "./typeUtils.mjs";
|
|
2
|
+
//#region src/makeRunQuery.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `makeRunQuery` function for each project's `testUtils` file.
|
|
5
|
+
*
|
|
6
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
7
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
8
|
+
*/
|
|
9
|
+
declare function makeMakeRunQuery<C>(runFn: RunFn<C>): MakeRunQuery<C>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a `run` method that invokes the query resolver's single query.
|
|
12
|
+
*
|
|
13
|
+
* Following our `query / foo` conventions, query resolver will have a single `fooResolver.foo` method.
|
|
14
|
+
*/
|
|
15
|
+
type MakeRunQuery<C> = <T extends object>(resolver: T) => RunQueryMethod<C, T>;
|
|
16
|
+
/** The return type of `makeRunQuery`. */
|
|
17
|
+
type RunQueryMethod<C, T> = <A extends ResolverArgs<T, keyof T>>(ctx: C, args?: A | (() => A)) => Promise<ResolverResult<T, keyof T>>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MakeRunQuery, makeMakeRunQuery };
|
|
20
|
+
//# sourceMappingURL=makeRunQuery.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunQuery.d.mts","names":[],"sources":["../src/makeRunQuery.ts"],"mappings":";;;;;;;;iBAQgB,iBAAiB,GAAG,OAAO,MAAM,KAAK,aAAa;;;;;;KAevD,aAAa,MAAM,kBAAkB,UAAU,MAAM,eAAe,GAAG;;KAG9E,eAAe,GAAG,MAAM,UAAU,aAAa,SAAS,IAC3D,KAAK,GAEL,OAAO,WAAW,OACf,QAAQ,eAAe,SAAS"}
|
package/build/makeRunQuery.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.makeMakeRunQuery = makeMakeRunQuery;
|
|
1
|
+
import "./typeUtils.js";
|
|
2
|
+
//#region src/makeRunQuery.ts
|
|
4
3
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
* Creates a `makeRunQuery` function for each project's `testUtils` file.
|
|
5
|
+
*
|
|
6
|
+
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
7
|
+
* that is customized (basically curried) to their own `newContext` function.
|
|
8
|
+
*/
|
|
10
9
|
function makeMakeRunQuery(runFn) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
10
|
+
return (resolver) => {
|
|
11
|
+
return (ctx, args) => runFn(ctx, async (ctx) => {
|
|
12
|
+
return resolver[Object.keys(resolver)[0]]({}, args instanceof Function ? args() : args ?? {}, ctx, void 0);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
17
15
|
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { makeMakeRunQuery };
|
|
18
|
+
|
|
18
19
|
//# sourceMappingURL=makeRunQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeRunQuery.js","
|
|
1
|
+
{"version":3,"file":"makeRunQuery.js","names":[],"sources":["../src/makeRunQuery.ts"],"sourcesContent":["import { type ResolverArgs, type ResolverResult, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunQuery` function for each project's `testUtils` file.\n *\n * This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory\n * that is customized (basically curried) to their own `newContext` function.\n */\nexport function makeMakeRunQuery<C>(runFn: RunFn<C>): MakeRunQuery<C> {\n return (resolver) => {\n return (ctx, args) =>\n runFn(ctx, async (ctx) => {\n const key = Object.keys(resolver)[0];\n return ((resolver as any)[key] as any)({}, args instanceof Function ? args() : (args ?? {}), ctx, undefined!);\n });\n };\n}\n\n/**\n * Creates a `run` method that invokes the query resolver's single query.\n *\n * Following our `query / foo` conventions, query resolver will have a single `fooResolver.foo` method.\n */\nexport type MakeRunQuery<C> = <T extends object>(resolver: T) => RunQueryMethod<C, T>;\n\n/** The return type of `makeRunQuery`. */\ntype RunQueryMethod<C, T> = <A extends ResolverArgs<T, keyof T>>(\n ctx: C,\n // Support either the resolver arg directly or a lambda to create the args post-flush\n args?: A | (() => A),\n) => Promise<ResolverResult<T, keyof T>>;\n"],"mappings":";;;;;;;;AAQA,SAAgB,iBAAoB,OAAkC;CACpE,QAAQ,aAAa;EACnB,QAAQ,KAAK,SACX,MAAM,KAAK,OAAO,QAAQ;GAExB,OAAS,SADG,OAAO,KAAK,QAAQ,CAAC,CAAC,GACJ,CAAS,CAAC,GAAG,gBAAgB,WAAW,KAAK,IAAK,QAAQ,CAAC,GAAI,KAAK,KAAA,CAAU;EAC9G,CAAC;CACL;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let joist_core = require("joist-core");
|
|
3
|
+
//#region src/paginationUtils.ts
|
|
4
|
+
const defaultLimit = 100;
|
|
5
|
+
/** Executes an entity selection after pagination has been applied. */
|
|
6
|
+
function queryEntities(ctx, base) {
|
|
7
|
+
return ctx.em.query(base);
|
|
8
|
+
}
|
|
9
|
+
/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */
|
|
10
|
+
async function countQuery(ctx, base) {
|
|
11
|
+
const select = { id: base.select.id };
|
|
12
|
+
if (Array.isArray(base.orderBy)) for (const [index, order] of base.orderBy.entries()) {
|
|
13
|
+
const sort = order?.sort;
|
|
14
|
+
if (typeof sort === "object" && sort !== null && order.order !== void 0) select[`order${index}`] = sort;
|
|
15
|
+
}
|
|
16
|
+
const rows = (0, joist_core.query)({
|
|
17
|
+
...base,
|
|
18
|
+
select,
|
|
19
|
+
orderBy: void 0,
|
|
20
|
+
limit: void 0,
|
|
21
|
+
offset: void 0
|
|
22
|
+
});
|
|
23
|
+
const [result] = await ctx.em.query({
|
|
24
|
+
from: rows,
|
|
25
|
+
select: { count: rows.id.count() }
|
|
26
|
+
});
|
|
27
|
+
return result.count;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.countQuery = countQuery;
|
|
31
|
+
exports.defaultLimit = defaultLimit;
|
|
32
|
+
exports.queryEntities = queryEntities;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=paginationUtils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginationUtils.cjs","names":["query"],"sources":["../src/paginationUtils.ts"],"sourcesContent":["import {\n type Entity,\n type EntityColumn,\n type EntityManager,\n type ExprLike,\n type GraphQLFilterWithAlias,\n type Query,\n type TableFor,\n query,\n} from \"joist-core\";\n\nexport type ContextWithEm = { em: EntityManager };\nexport type PaginationFilter<T extends Entity> = GraphQLFilterWithAlias<T>;\nexport type PaginationQuery<T extends Entity> = Query<TableFor<T> & { readonly id: EntityColumn<T, never, string> }>;\n\nexport const defaultLimit = 100;\n\n/** Executes an entity selection after pagination has been applied. */\nexport function queryEntities<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<T[]> {\n // Widen the phantom entity type so em.query can resolve its conditional scope checks.\n return ctx.em.query(base as PaginationQuery<Entity>) as Promise<T[]>;\n}\n\n/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */\nexport async function countQuery<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<number> {\n const select: { id: EntityColumn<T, never, string> } & Record<string, ExprLike<unknown>> = { id: base.select.id };\n // Keep references from expression ordering so removing ORDER BY does not prune a join.\n // I.e. ordering Authors by Book title must still count the joined Author/Book rows.\n if (Array.isArray(base.orderBy)) {\n for (const [index, order] of base.orderBy.entries()) {\n const sort = order?.sort;\n if (typeof sort === \"object\" && sort !== null && order.order !== undefined) select[`order${index}`] = sort;\n }\n }\n const rows = query({ ...base, select, orderBy: undefined, limit: undefined, offset: undefined });\n const [result] = await ctx.em.query({ from: rows, select: { count: rows.id.count() } });\n return result.count;\n}\n"],"mappings":";;;AAeA,MAAa,eAAe;;AAG5B,SAAgB,cAAgC,KAAoB,MAAwC;CAE1G,OAAO,IAAI,GAAG,MAAM,IAA+B;AACrD;;AAGA,eAAsB,WAA6B,KAAoB,MAA2C;CAChH,MAAM,SAAqF,EAAE,IAAI,KAAK,OAAO,GAAG;CAGhH,IAAI,MAAM,QAAQ,KAAK,OAAO,GAC5B,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,QAAQ,QAAQ,GAAG;EACnD,MAAM,OAAO,OAAO;EACpB,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,UAAU,KAAA,GAAW,OAAO,QAAQ,WAAW;CACxG;CAEF,MAAM,QAAA,GAAOA,WAAAA,MAAAA,CAAM;EAAE,GAAG;EAAM;EAAQ,SAAS,KAAA;EAAW,OAAO,KAAA;EAAW,QAAQ,KAAA;CAAU,CAAC;CAC/F,MAAM,CAAC,UAAU,MAAM,IAAI,GAAG,MAAM;EAAE,MAAM;EAAM,QAAQ,EAAE,OAAO,KAAK,GAAG,MAAM,EAAE;CAAE,CAAC;CACtF,OAAO,OAAO;AAChB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Entity, EntityColumn, EntityManager, GraphQLFilterWithAlias, Query, TableFor } from "joist-core";
|
|
2
|
+
//#region src/paginationUtils.d.ts
|
|
3
|
+
type ContextWithEm = {
|
|
4
|
+
em: EntityManager;
|
|
5
|
+
};
|
|
6
|
+
type PaginationFilter<T extends Entity> = GraphQLFilterWithAlias<T>;
|
|
7
|
+
type PaginationQuery<T extends Entity> = Query<TableFor<T> & {
|
|
8
|
+
readonly id: EntityColumn<T, never, string>;
|
|
9
|
+
}>;
|
|
10
|
+
declare const defaultLimit = 100;
|
|
11
|
+
/** Executes an entity selection after pagination has been applied. */
|
|
12
|
+
declare function queryEntities<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<T[]>;
|
|
13
|
+
/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */
|
|
14
|
+
declare function countQuery<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<number>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ContextWithEm, PaginationFilter, PaginationQuery, countQuery, defaultLimit, queryEntities };
|
|
17
|
+
//# sourceMappingURL=paginationUtils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginationUtils.d.cts","names":[],"sources":["../src/paginationUtils.ts"],"mappings":";;KAWY;EAAkB,IAAI;;KACtB,iBAAiB,UAAU,UAAU,uBAAuB;KAC5D,gBAAgB,UAAU,UAAU,MAAM,SAAS;WAAgB,IAAI,aAAa;;cAEnF;;iBAGG,cAAc,UAAU,QAAQ,KAAK,eAAe,MAAM,gBAAgB,KAAK,QAAQ;;iBAMjF,WAAW,UAAU,QAAQ,KAAK,eAAe,MAAM,gBAAgB,KAAK"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Entity, EntityColumn, EntityManager, GraphQLFilterWithAlias, Query, TableFor } from "joist-core";
|
|
2
|
+
//#region src/paginationUtils.d.ts
|
|
3
|
+
type ContextWithEm = {
|
|
4
|
+
em: EntityManager;
|
|
5
|
+
};
|
|
6
|
+
type PaginationFilter<T extends Entity> = GraphQLFilterWithAlias<T>;
|
|
7
|
+
type PaginationQuery<T extends Entity> = Query<TableFor<T> & {
|
|
8
|
+
readonly id: EntityColumn<T, never, string>;
|
|
9
|
+
}>;
|
|
10
|
+
declare const defaultLimit = 100;
|
|
11
|
+
/** Executes an entity selection after pagination has been applied. */
|
|
12
|
+
declare function queryEntities<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<T[]>;
|
|
13
|
+
/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */
|
|
14
|
+
declare function countQuery<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<number>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ContextWithEm, PaginationFilter, PaginationQuery, countQuery, defaultLimit, queryEntities };
|
|
17
|
+
//# sourceMappingURL=paginationUtils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginationUtils.d.mts","names":[],"sources":["../src/paginationUtils.ts"],"mappings":";;KAWY;EAAkB,IAAI;;KACtB,iBAAiB,UAAU,UAAU,uBAAuB;KAC5D,gBAAgB,UAAU,UAAU,MAAM,SAAS;WAAgB,IAAI,aAAa;;cAEnF;;iBAGG,cAAc,UAAU,QAAQ,KAAK,eAAe,MAAM,gBAAgB,KAAK,QAAQ;;iBAMjF,WAAW,UAAU,QAAQ,KAAK,eAAe,MAAM,gBAAgB,KAAK"}
|
package/build/paginationUtils.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { query } from "joist-core";
|
|
2
|
+
//#region src/paginationUtils.ts
|
|
3
|
+
const defaultLimit = 100;
|
|
4
|
+
/** Executes an entity selection after pagination has been applied. */
|
|
5
|
+
function queryEntities(ctx, base) {
|
|
6
|
+
return ctx.em.query(base);
|
|
7
|
+
}
|
|
8
|
+
/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */
|
|
9
|
+
async function countQuery(ctx, base) {
|
|
10
|
+
const select = { id: base.select.id };
|
|
11
|
+
if (Array.isArray(base.orderBy)) for (const [index, order] of base.orderBy.entries()) {
|
|
12
|
+
const sort = order?.sort;
|
|
13
|
+
if (typeof sort === "object" && sort !== null && order.order !== void 0) select[`order${index}`] = sort;
|
|
14
|
+
}
|
|
15
|
+
const rows = query({
|
|
16
|
+
...base,
|
|
17
|
+
select,
|
|
18
|
+
orderBy: void 0,
|
|
19
|
+
limit: void 0,
|
|
20
|
+
offset: void 0
|
|
21
|
+
});
|
|
22
|
+
const [result] = await ctx.em.query({
|
|
23
|
+
from: rows,
|
|
24
|
+
select: { count: rows.id.count() }
|
|
25
|
+
});
|
|
26
|
+
return result.count;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { countQuery, defaultLimit, queryEntities };
|
|
30
|
+
|
|
5
31
|
//# sourceMappingURL=paginationUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginationUtils.js","
|
|
1
|
+
{"version":3,"file":"paginationUtils.js","names":[],"sources":["../src/paginationUtils.ts"],"sourcesContent":["import {\n type Entity,\n type EntityColumn,\n type EntityManager,\n type ExprLike,\n type GraphQLFilterWithAlias,\n type Query,\n type TableFor,\n query,\n} from \"joist-core\";\n\nexport type ContextWithEm = { em: EntityManager };\nexport type PaginationFilter<T extends Entity> = GraphQLFilterWithAlias<T>;\nexport type PaginationQuery<T extends Entity> = Query<TableFor<T> & { readonly id: EntityColumn<T, never, string> }>;\n\nexport const defaultLimit = 100;\n\n/** Executes an entity selection after pagination has been applied. */\nexport function queryEntities<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<T[]> {\n // Widen the phantom entity type so em.query can resolve its conditional scope checks.\n return ctx.em.query(base as PaginationQuery<Entity>) as Promise<T[]>;\n}\n\n/** Counts the unpaginated rows, preserving distinct, grouping, and join semantics. */\nexport async function countQuery<T extends Entity>(ctx: ContextWithEm, base: PaginationQuery<T>): Promise<number> {\n const select: { id: EntityColumn<T, never, string> } & Record<string, ExprLike<unknown>> = { id: base.select.id };\n // Keep references from expression ordering so removing ORDER BY does not prune a join.\n // I.e. ordering Authors by Book title must still count the joined Author/Book rows.\n if (Array.isArray(base.orderBy)) {\n for (const [index, order] of base.orderBy.entries()) {\n const sort = order?.sort;\n if (typeof sort === \"object\" && sort !== null && order.order !== undefined) select[`order${index}`] = sort;\n }\n }\n const rows = query({ ...base, select, orderBy: undefined, limit: undefined, offset: undefined });\n const [result] = await ctx.em.query({ from: rows, select: { count: rows.id.count() } });\n return result.count;\n}\n"],"mappings":";;AAeA,MAAa,eAAe;;AAG5B,SAAgB,cAAgC,KAAoB,MAAwC;CAE1G,OAAO,IAAI,GAAG,MAAM,IAA+B;AACrD;;AAGA,eAAsB,WAA6B,KAAoB,MAA2C;CAChH,MAAM,SAAqF,EAAE,IAAI,KAAK,OAAO,GAAG;CAGhH,IAAI,MAAM,QAAQ,KAAK,OAAO,GAC5B,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,QAAQ,QAAQ,GAAG;EACnD,MAAM,OAAO,OAAO;EACpB,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,UAAU,KAAA,GAAW,OAAO,QAAQ,WAAW;CACxG;CAEF,MAAM,OAAO,MAAM;EAAE,GAAG;EAAM;EAAQ,SAAS,KAAA;EAAW,OAAO,KAAA;EAAW,QAAQ,KAAA;CAAU,CAAC;CAC/F,MAAM,CAAC,UAAU,MAAM,IAAI,GAAG,MAAM;EAAE,MAAM;EAAM,QAAQ,EAAE,OAAO,KAAK,GAAG,MAAM,EAAE;CAAE,CAAC;CACtF,OAAO,OAAO;AAChB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let joist_core = require("joist-core");
|
|
3
|
+
require("joist-test-utils");
|
|
4
|
+
//#region src/saveEntity.ts
|
|
5
|
+
/** Given an GraphQL input, creates-or-updates an entity of `type`. */
|
|
6
|
+
async function saveEntity(ctx, type, input, opts = {}) {
|
|
7
|
+
return saveEntities(ctx, type, [input], opts).then((r) => r[0]);
|
|
8
|
+
}
|
|
9
|
+
/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */
|
|
10
|
+
async function saveEntities(ctx, type, input, opts = {}) {
|
|
11
|
+
const { em } = ctx;
|
|
12
|
+
const { opts: entityOpts = {}, flush = true } = opts;
|
|
13
|
+
const results = await Promise.allSettled(input.map((input) => em.upsert(type, {
|
|
14
|
+
...entityOpts,
|
|
15
|
+
...input
|
|
16
|
+
})));
|
|
17
|
+
if (flush) await ctx.em.flush();
|
|
18
|
+
return (0, joist_core.failIfAnyRejected)(results);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.saveEntities = saveEntities;
|
|
22
|
+
exports.saveEntity = saveEntity;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=saveEntity.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveEntity.cjs","names":["failIfAnyRejected"],"sources":["../src/saveEntity.ts"],"sourcesContent":["import {\n type DeepPartialOrNull,\n type Entity,\n type EntityConstructor,\n type OptsOf,\n failIfAnyRejected,\n} from \"joist-core\";\nimport { type Context } from \"joist-test-utils\";\n\n/** Given an GraphQL input, creates-or-updates an entity of `type`. */\nexport async function saveEntity<T extends Entity>(\n ctx: Context,\n type: EntityConstructor<T>,\n input: DeepPartialOrNull<T>,\n opts: { flush?: boolean } = {},\n): Promise<T> {\n return saveEntities(ctx, type, [input], opts).then((r) => r[0]);\n}\n\n/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */\nexport async function saveEntities<T extends Entity>(\n ctx: Context,\n type: EntityConstructor<T>,\n input: readonly DeepPartialOrNull<T>[],\n opts: { flush?: boolean; opts?: Partial<OptsOf<T>> } = {},\n): Promise<T[]> {\n const { em } = ctx;\n const { opts: entityOpts = {}, flush = true } = opts;\n const results = await Promise.allSettled(input.map((input) => em.upsert(type, { ...entityOpts, ...input })));\n if (flush) {\n await ctx.em.flush();\n }\n return failIfAnyRejected(results);\n}\n"],"mappings":";;;;;AAUA,eAAsB,WACpB,KACA,MACA,OACA,OAA4B,CAAC,GACjB;CACZ,OAAO,aAAa,KAAK,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE,EAAE;AAChE;;AAGA,eAAsB,aACpB,KACA,MACA,OACA,OAAuD,CAAC,GAC1C;CACd,MAAM,EAAE,OAAO;CACf,MAAM,EAAE,MAAM,aAAa,CAAC,GAAG,QAAQ,SAAS;CAChD,MAAM,UAAU,MAAM,QAAQ,WAAW,MAAM,KAAK,UAAU,GAAG,OAAO,MAAM;EAAE,GAAG;EAAY,GAAG;CAAM,CAAC,CAAC,CAAC;CAC3G,IAAI,OACF,MAAM,IAAI,GAAG,MAAM;CAErB,QAAA,GAAOA,WAAAA,kBAAAA,CAAkB,OAAO;AAClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeepPartialOrNull, Entity, EntityConstructor, OptsOf } from "joist-core";
|
|
2
|
+
import { Context } from "joist-test-utils";
|
|
3
|
+
//#region src/saveEntity.d.ts
|
|
4
|
+
/** Given an GraphQL input, creates-or-updates an entity of `type`. */
|
|
5
|
+
declare function saveEntity<T extends Entity>(ctx: Context, type: EntityConstructor<T>, input: DeepPartialOrNull<T>, opts?: {
|
|
6
|
+
flush?: boolean;
|
|
7
|
+
}): Promise<T>;
|
|
8
|
+
/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */
|
|
9
|
+
declare function saveEntities<T extends Entity>(ctx: Context, type: EntityConstructor<T>, input: readonly DeepPartialOrNull<T>[], opts?: {
|
|
10
|
+
flush?: boolean;
|
|
11
|
+
opts?: Partial<OptsOf<T>>;
|
|
12
|
+
}): Promise<T[]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { saveEntities, saveEntity };
|
|
15
|
+
//# sourceMappingURL=saveEntity.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveEntity.d.cts","names":[],"sources":["../src/saveEntity.ts"],"mappings":";;;;iBAUsB,WAAW,UAAU,QACzC,KAAK,SACL,MAAM,kBAAkB,IACxB,OAAO,kBAAkB,IACzB;EAAQ;IACP,QAAQ;;iBAKW,aAAa,UAAU,QAC3C,KAAK,SACL,MAAM,kBAAkB,IACxB,gBAAgB,kBAAkB,MAClC;EAAQ;EAAiB,OAAO,QAAQ,OAAO;IAC9C,QAAQ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeepPartialOrNull, Entity, EntityConstructor, OptsOf } from "joist-core";
|
|
2
|
+
import { Context } from "joist-test-utils";
|
|
3
|
+
//#region src/saveEntity.d.ts
|
|
4
|
+
/** Given an GraphQL input, creates-or-updates an entity of `type`. */
|
|
5
|
+
declare function saveEntity<T extends Entity>(ctx: Context, type: EntityConstructor<T>, input: DeepPartialOrNull<T>, opts?: {
|
|
6
|
+
flush?: boolean;
|
|
7
|
+
}): Promise<T>;
|
|
8
|
+
/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */
|
|
9
|
+
declare function saveEntities<T extends Entity>(ctx: Context, type: EntityConstructor<T>, input: readonly DeepPartialOrNull<T>[], opts?: {
|
|
10
|
+
flush?: boolean;
|
|
11
|
+
opts?: Partial<OptsOf<T>>;
|
|
12
|
+
}): Promise<T[]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { saveEntities, saveEntity };
|
|
15
|
+
//# sourceMappingURL=saveEntity.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveEntity.d.mts","names":[],"sources":["../src/saveEntity.ts"],"mappings":";;;;iBAUsB,WAAW,UAAU,QACzC,KAAK,SACL,MAAM,kBAAkB,IACxB,OAAO,kBAAkB,IACzB;EAAQ;IACP,QAAQ;;iBAKW,aAAa,UAAU,QAC3C,KAAK,SACL,MAAM,kBAAkB,IACxB,gBAAgB,kBAAkB,MAClC;EAAQ;EAAiB,OAAO,QAAQ,OAAO;IAC9C,QAAQ"}
|
package/build/saveEntity.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.saveEntities = saveEntities;
|
|
5
|
-
const joist_core_1 = require("joist-core");
|
|
1
|
+
import { failIfAnyRejected } from "joist-core";
|
|
2
|
+
import "joist-test-utils";
|
|
3
|
+
//#region src/saveEntity.ts
|
|
6
4
|
/** Given an GraphQL input, creates-or-updates an entity of `type`. */
|
|
7
5
|
async function saveEntity(ctx, type, input, opts = {}) {
|
|
8
|
-
|
|
6
|
+
return saveEntities(ctx, type, [input], opts).then((r) => r[0]);
|
|
9
7
|
}
|
|
10
8
|
/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */
|
|
11
9
|
async function saveEntities(ctx, type, input, opts = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const { em } = ctx;
|
|
11
|
+
const { opts: entityOpts = {}, flush = true } = opts;
|
|
12
|
+
const results = await Promise.allSettled(input.map((input) => em.upsert(type, {
|
|
13
|
+
...entityOpts,
|
|
14
|
+
...input
|
|
15
|
+
})));
|
|
16
|
+
if (flush) await ctx.em.flush();
|
|
17
|
+
return failIfAnyRejected(results);
|
|
19
18
|
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { saveEntities, saveEntity };
|
|
21
|
+
|
|
20
22
|
//# sourceMappingURL=saveEntity.js.map
|
package/build/saveEntity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveEntity.js","
|
|
1
|
+
{"version":3,"file":"saveEntity.js","names":[],"sources":["../src/saveEntity.ts"],"sourcesContent":["import {\n type DeepPartialOrNull,\n type Entity,\n type EntityConstructor,\n type OptsOf,\n failIfAnyRejected,\n} from \"joist-core\";\nimport { type Context } from \"joist-test-utils\";\n\n/** Given an GraphQL input, creates-or-updates an entity of `type`. */\nexport async function saveEntity<T extends Entity>(\n ctx: Context,\n type: EntityConstructor<T>,\n input: DeepPartialOrNull<T>,\n opts: { flush?: boolean } = {},\n): Promise<T> {\n return saveEntities(ctx, type, [input], opts).then((r) => r[0]);\n}\n\n/** Given GraphQL inputs, creates-or-updates multiple entities of `type`. */\nexport async function saveEntities<T extends Entity>(\n ctx: Context,\n type: EntityConstructor<T>,\n input: readonly DeepPartialOrNull<T>[],\n opts: { flush?: boolean; opts?: Partial<OptsOf<T>> } = {},\n): Promise<T[]> {\n const { em } = ctx;\n const { opts: entityOpts = {}, flush = true } = opts;\n const results = await Promise.allSettled(input.map((input) => em.upsert(type, { ...entityOpts, ...input })));\n if (flush) {\n await ctx.em.flush();\n }\n return failIfAnyRejected(results);\n}\n"],"mappings":";;;;AAUA,eAAsB,WACpB,KACA,MACA,OACA,OAA4B,CAAC,GACjB;CACZ,OAAO,aAAa,KAAK,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE,EAAE;AAChE;;AAGA,eAAsB,aACpB,KACA,MACA,OACA,OAAuD,CAAC,GAC1C;CACd,MAAM,EAAE,OAAO;CACf,MAAM,EAAE,MAAM,aAAa,CAAC,GAAG,QAAQ,SAAS;CAChD,MAAM,UAAU,MAAM,QAAQ,WAAW,MAAM,KAAK,UAAU,GAAG,OAAO,MAAM;EAAE,GAAG;EAAY,GAAG;CAAM,CAAC,CAAC,CAAC;CAC3G,IAAI,OACF,MAAM,IAAI,GAAG,MAAM;CAErB,OAAO,kBAAkB,OAAO;AAClC"}
|
package/build/tests.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_makeRunInputMutation = require("./makeRunInputMutation.cjs");
|
|
3
|
+
const require_makeRunObjectField = require("./makeRunObjectField.cjs");
|
|
4
|
+
const require_makeRunObjectFields = require("./makeRunObjectFields.cjs");
|
|
5
|
+
const require_makeRunQuery = require("./makeRunQuery.cjs");
|
|
6
|
+
exports.makeMakeRunInputMutation = require_makeRunInputMutation.makeMakeRunInputMutation;
|
|
7
|
+
exports.makeMakeRunObjectField = require_makeRunObjectField.makeMakeRunObjectField;
|
|
8
|
+
exports.makeMakeRunObjectFields = require_makeRunObjectFields.makeMakeRunObjectFields;
|
|
9
|
+
exports.makeMakeRunQuery = require_makeRunQuery.makeMakeRunQuery;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ResolverArgs, ResolverResult, ResolverRoot, RunFn } from "./typeUtils.cjs";
|
|
2
|
+
import { MakeRunInputMutation, makeMakeRunInputMutation } from "./makeRunInputMutation.cjs";
|
|
3
|
+
import { MakeRunObjectField, makeMakeRunObjectField } from "./makeRunObjectField.cjs";
|
|
4
|
+
import { MakeRunObjectFields, makeMakeRunObjectFields } from "./makeRunObjectFields.cjs";
|
|
5
|
+
import { MakeRunQuery, makeMakeRunQuery } from "./makeRunQuery.cjs";
|
|
6
|
+
export { type MakeRunInputMutation, type MakeRunObjectField, type MakeRunObjectFields, type MakeRunQuery, type ResolverArgs, type ResolverResult, type ResolverRoot, type RunFn, makeMakeRunInputMutation, makeMakeRunObjectField, makeMakeRunObjectFields, makeMakeRunQuery };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ResolverArgs, ResolverResult, ResolverRoot, RunFn } from "./typeUtils.mjs";
|
|
2
|
+
import { MakeRunInputMutation, makeMakeRunInputMutation } from "./makeRunInputMutation.mjs";
|
|
3
|
+
import { MakeRunObjectField, makeMakeRunObjectField } from "./makeRunObjectField.mjs";
|
|
4
|
+
import { MakeRunObjectFields, makeMakeRunObjectFields } from "./makeRunObjectFields.mjs";
|
|
5
|
+
import { MakeRunQuery, makeMakeRunQuery } from "./makeRunQuery.mjs";
|
|
6
|
+
export { type MakeRunInputMutation, type MakeRunObjectField, type MakeRunObjectFields, type MakeRunQuery, type ResolverArgs, type ResolverResult, type ResolverRoot, type RunFn, makeMakeRunInputMutation, makeMakeRunObjectField, makeMakeRunObjectFields, makeMakeRunQuery };
|
package/build/tests.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.makeMakeRunQuery = exports.makeMakeRunObjectFields = exports.makeMakeRunObjectField = exports.makeMakeRunInputMutation = void 0;
|
|
18
|
-
var makeRunInputMutation_1 = require("./makeRunInputMutation");
|
|
19
|
-
Object.defineProperty(exports, "makeMakeRunInputMutation", { enumerable: true, get: function () { return makeRunInputMutation_1.makeMakeRunInputMutation; } });
|
|
20
|
-
var makeRunObjectField_1 = require("./makeRunObjectField");
|
|
21
|
-
Object.defineProperty(exports, "makeMakeRunObjectField", { enumerable: true, get: function () { return makeRunObjectField_1.makeMakeRunObjectField; } });
|
|
22
|
-
var makeRunObjectFields_1 = require("./makeRunObjectFields");
|
|
23
|
-
Object.defineProperty(exports, "makeMakeRunObjectFields", { enumerable: true, get: function () { return makeRunObjectFields_1.makeMakeRunObjectFields; } });
|
|
24
|
-
var makeRunQuery_1 = require("./makeRunQuery");
|
|
25
|
-
Object.defineProperty(exports, "makeMakeRunQuery", { enumerable: true, get: function () { return makeRunQuery_1.makeMakeRunQuery; } });
|
|
26
|
-
__exportStar(require("./typeUtils"), exports);
|
|
27
|
-
//# sourceMappingURL=tests.js.map
|
|
1
|
+
import { makeMakeRunInputMutation } from "./makeRunInputMutation.js";
|
|
2
|
+
import { makeMakeRunObjectField } from "./makeRunObjectField.js";
|
|
3
|
+
import { makeMakeRunObjectFields } from "./makeRunObjectFields.js";
|
|
4
|
+
import { makeMakeRunQuery } from "./makeRunQuery.js";
|
|
5
|
+
export { makeMakeRunInputMutation, makeMakeRunObjectField, makeMakeRunObjectFields, makeMakeRunQuery };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Resolver } from "./context.cjs";
|
|
2
|
+
//#region src/typeUtils.d.ts
|
|
3
|
+
type RunFn<C> = <T>(ctx: C, fn: (ctx: C) => Promise<T>) => Promise<T>;
|
|
4
|
+
/** Infers the root type of the given resolver, by assuming it's always the first arg. */
|
|
5
|
+
type ResolverRoot<T> = T extends { [key in keyof T]: infer F; } ? F extends Resolver<infer R, any, any> ? R : never : never;
|
|
6
|
+
type ResolverArgs<T, K extends keyof T> = T[K] extends Resolver<any, infer U, any> ? U : never;
|
|
7
|
+
/** Infers the return type of key `K` in the resolver object `T`. */
|
|
8
|
+
type ResolverResult<T, K extends keyof T> = T[K] extends Resolver<any, any, infer U> ? U : never;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ResolverArgs, ResolverResult, ResolverRoot, RunFn };
|
|
11
|
+
//# sourceMappingURL=typeUtils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeUtils.d.cts","names":[],"sources":["../src/typeUtils.ts"],"mappings":";;KAEY,MAAM,MAAM,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,QAAQ,OAAO,QAAQ;;KAG9D,aAAa,KAAK,aAAa,aAAa,UAAU,OAC9D,UAAU,eAAe,eACvB;KAIM,aAAa,GAAG,gBAAgB,KAAK,EAAE,WAAW,oBAAoB,UAAU;;KAGhF,eAAe,GAAG,gBAAgB,KAAK,EAAE,WAAW,yBAAyB,KAAK"}
|