joist-graphql-resolver-utils 2.3.0-next.7 → 2.3.0-next.70
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 +85 -0
- package/build/cursorPagination.cjs.map +1 -0
- package/build/cursorPagination.d.cts +35 -0
- package/build/cursorPagination.d.cts.map +1 -0
- package/build/cursorPagination.d.mts +35 -0
- package/build/cursorPagination.d.mts.map +1 -0
- package/build/cursorPagination.js +69 -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 +65 -0
- package/build/limitPagination.cjs.map +1 -0
- package/build/limitPagination.d.cts +30 -0
- package/build/limitPagination.d.cts.map +1 -0
- package/build/limitPagination.d.mts +30 -0
- package/build/limitPagination.d.mts.map +1 -0
- package/build/limitPagination.js +58 -51
- 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 +8 -0
- package/build/paginationUtils.cjs.map +1 -0
- package/build/paginationUtils.d.cts +10 -0
- package/build/paginationUtils.d.cts.map +1 -0
- package/build/paginationUtils.d.mts +10 -0
- package/build/paginationUtils.d.mts.map +1 -0
- package/build/paginationUtils.js +6 -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,65 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./paginationUtils.cjs");
|
|
3
|
+
require("joist-core");
|
|
4
|
+
//#region src/limitPagination.ts
|
|
5
|
+
/** Returns a limit/offset page shape for a generated query resolver. */
|
|
6
|
+
async function paginateLimit(ctx, type, args) {
|
|
7
|
+
const limit = args.limit ?? 100;
|
|
8
|
+
const offset = args.offset ?? 0;
|
|
9
|
+
const filter = args.filter ?? {};
|
|
10
|
+
return {
|
|
11
|
+
entities: await ctx.em.findGql(type, filter, {
|
|
12
|
+
limit,
|
|
13
|
+
offset
|
|
14
|
+
}),
|
|
15
|
+
pageInfo: new LimitPageInfo(ctx, type, filter, {
|
|
16
|
+
limit,
|
|
17
|
+
offset
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Lazily computes limit/offset page fields. */
|
|
22
|
+
var LimitPageInfo = class {
|
|
23
|
+
#ctx;
|
|
24
|
+
#filter;
|
|
25
|
+
#page;
|
|
26
|
+
#totalCountPromise;
|
|
27
|
+
#type;
|
|
28
|
+
constructor(ctx, type, filter, page) {
|
|
29
|
+
this.#ctx = ctx;
|
|
30
|
+
this.#type = type;
|
|
31
|
+
this.#filter = filter;
|
|
32
|
+
this.#page = page;
|
|
33
|
+
}
|
|
34
|
+
get hasNextPage() {
|
|
35
|
+
return this.#hasNextPage();
|
|
36
|
+
}
|
|
37
|
+
get hasPreviousPage() {
|
|
38
|
+
return this.#page.offset > 0;
|
|
39
|
+
}
|
|
40
|
+
get totalCount() {
|
|
41
|
+
return this.#totalCountPromise ??= this.#ctx.em.findCount(this.#type, this.#filter);
|
|
42
|
+
}
|
|
43
|
+
get nextPage() {
|
|
44
|
+
return this.#nextPage();
|
|
45
|
+
}
|
|
46
|
+
get currentPage() {
|
|
47
|
+
return Math.floor(this.#page.offset / this.#page.limit) + 1;
|
|
48
|
+
}
|
|
49
|
+
/** Returns whether another page exists after this page. */
|
|
50
|
+
async #hasNextPage() {
|
|
51
|
+
const total = await this.totalCount;
|
|
52
|
+
const { offset, limit } = this.#page;
|
|
53
|
+
return offset + limit < total;
|
|
54
|
+
}
|
|
55
|
+
/** Returns the next limit/offset page if there is one. */
|
|
56
|
+
async #nextPage() {
|
|
57
|
+
if (!await this.hasNextPage) return void 0;
|
|
58
|
+
return this.currentPage + 1;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.LimitPageInfo = LimitPageInfo;
|
|
63
|
+
exports.paginateLimit = paginateLimit;
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=limitPagination.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.cjs","names":["#ctx","#type","#filter","#page","#hasNextPage","#totalCountPromise","#nextPage"],"sources":["../src/limitPagination.ts"],"sourcesContent":["import { type Entity, type MaybeAbstractEntityConstructor } from \"joist-core\";\n\nimport { type ContextWithEm, type PaginationFilter, defaultLimit } from \"./paginationUtils.ts\";\n\ntype LimitArgs<T extends Entity, F extends object = PaginationFilter<T>> = {\n filter?: F | null;\n limit?: number | null;\n offset?: number | null;\n};\ntype Page = { offset: number; limit: number };\n\n/** Returns a limit/offset page shape for a generated query resolver. */\nexport async function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T>,\n args: LimitArgs<T, F>,\n): Promise<{ entities: T[]; pageInfo: LimitPageInfo<T> }> {\n const limit = args.limit ?? defaultLimit;\n const offset = args.offset ?? 0;\n const filter = (args.filter ?? {}) as PaginationFilter<T>;\n const entities = await ctx.em.findGql(type, filter, { limit, offset });\n return { entities, pageInfo: new LimitPageInfo(ctx, type, filter, { limit, offset }) };\n}\n\n/** Lazily computes limit/offset page fields. */\nexport class LimitPageInfo<T extends Entity = Entity> {\n #ctx: ContextWithEm;\n #filter: PaginationFilter<T>;\n #page: Page;\n #totalCountPromise: Promise<number> | undefined;\n #type: MaybeAbstractEntityConstructor<T>;\n\n constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, filter: PaginationFilter<T>, page: Page) {\n this.#ctx = ctx;\n this.#type = type;\n this.#filter = filter;\n this.#page = page;\n }\n\n get hasNextPage(): Promise<boolean> {\n return this.#hasNextPage();\n }\n\n get hasPreviousPage(): boolean {\n return this.#page.offset > 0;\n }\n\n get totalCount(): Promise<number> {\n return (this.#totalCountPromise ??= this.#ctx.em.findCount(this.#type, this.#filter));\n }\n\n get nextPage(): Promise<number | undefined> {\n return this.#nextPage();\n }\n\n get currentPage(): number {\n return Math.floor(this.#page.offset / this.#page.limit) + 1;\n }\n\n /** Returns whether another page exists after this page. */\n async #hasNextPage(): Promise<boolean> {\n const total = await this.totalCount;\n const { offset, limit } = this.#page;\n return offset + limit < total;\n }\n\n /** Returns the next limit/offset page if there is one. */\n async #nextPage(): Promise<number | undefined> {\n if (!(await this.hasNextPage)) return undefined;\n return this.currentPage + 1;\n }\n}\n"],"mappings":";;;;;AAYA,eAAsB,cACpB,KACA,MACA,MACwD;CACxD,MAAM,QAAQ,KAAK,SAAA;CACnB,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,SAAU,KAAK,UAAU,CAAC;CAEhC,OAAO;EAAE,UAAA,MADc,IAAI,GAAG,QAAQ,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;EAClD,UAAU,IAAI,cAAc,KAAK,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;CAAE;AACvF;;AAGA,IAAa,gBAAb,MAAsD;CACpD;CACA;CACA;CACA;CACA;CAEA,YAAY,KAAoB,MAAyC,QAA6B,MAAY;EAChH,KAAKA,OAAO;EACZ,KAAKC,QAAQ;EACb,KAAKC,UAAU;EACf,KAAKC,QAAQ;CACf;CAEA,IAAI,cAAgC;EAClC,OAAO,KAAKC,aAAa;CAC3B;CAEA,IAAI,kBAA2B;EAC7B,OAAO,KAAKD,MAAM,SAAS;CAC7B;CAEA,IAAI,aAA8B;EAChC,OAAQ,KAAKE,uBAAuB,KAAKL,KAAK,GAAG,UAAU,KAAKC,OAAO,KAAKC,OAAO;CACrF;CAEA,IAAI,WAAwC;EAC1C,OAAO,KAAKI,UAAU;CACxB;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK,MAAM,KAAKH,MAAM,SAAS,KAAKA,MAAM,KAAK,IAAI;CAC5D;;CAGA,MAAMC,eAAiC;EACrC,MAAM,QAAQ,MAAM,KAAK;EACzB,MAAM,EAAE,QAAQ,UAAU,KAAKD;EAC/B,OAAO,SAAS,QAAQ;CAC1B;;CAGA,MAAMG,YAAyC;EAC7C,IAAI,CAAE,MAAM,KAAK,aAAc,OAAO,KAAA;EACtC,OAAO,KAAK,cAAc;CAC5B;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ContextWithEm, PaginationFilter } from "./paginationUtils.cjs";
|
|
2
|
+
import { Entity, MaybeAbstractEntityConstructor } from "joist-core";
|
|
3
|
+
//#region src/limitPagination.d.ts
|
|
4
|
+
type LimitArgs<T extends Entity, F extends object = PaginationFilter<T>> = {
|
|
5
|
+
filter?: F | null;
|
|
6
|
+
limit?: number | null;
|
|
7
|
+
offset?: number | null;
|
|
8
|
+
};
|
|
9
|
+
type Page = {
|
|
10
|
+
offset: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
};
|
|
13
|
+
/** Returns a limit/offset page shape for a generated query resolver. */
|
|
14
|
+
declare function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, args: LimitArgs<T, F>): Promise<{
|
|
15
|
+
entities: T[];
|
|
16
|
+
pageInfo: LimitPageInfo<T>;
|
|
17
|
+
}>;
|
|
18
|
+
/** Lazily computes limit/offset page fields. */
|
|
19
|
+
declare class LimitPageInfo<T extends Entity = Entity> {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, filter: PaginationFilter<T>, page: Page);
|
|
22
|
+
get hasNextPage(): Promise<boolean>;
|
|
23
|
+
get hasPreviousPage(): boolean;
|
|
24
|
+
get totalCount(): Promise<number>;
|
|
25
|
+
get nextPage(): Promise<number | undefined>;
|
|
26
|
+
get currentPage(): number;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { LimitPageInfo, paginateLimit };
|
|
30
|
+
//# sourceMappingURL=limitPagination.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.d.cts","names":[],"sources":["../src/limitPagination.ts"],"mappings":";;;KAIK,UAAU,UAAU,QAAQ,mBAAmB,iBAAiB;EACnE,SAAS;EACT;EACA;;KAEG;EAAS;EAAgB;;;iBAGR,cAAc,UAAU,QAAQ,mBAAmB,iBAAiB,IACxF,KAAK,eACL,MAAM,+BAA+B,IACrC,MAAM,UAAU,GAAG,KAClB;EAAU,UAAU;EAAK,UAAU,cAAc;;;cASvC,cAAc,UAAU,SAAS;;EAO5C,YAAY,KAAK,eAAe,MAAM,+BAA+B,IAAI,QAAQ,iBAAiB,IAAI,MAAM;MAOxG,eAAe;MAIf;MAIA,cAAc;MAId,YAAY;MAIZ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ContextWithEm, PaginationFilter } from "./paginationUtils.mjs";
|
|
2
|
+
import { Entity, MaybeAbstractEntityConstructor } from "joist-core";
|
|
3
|
+
//#region src/limitPagination.d.ts
|
|
4
|
+
type LimitArgs<T extends Entity, F extends object = PaginationFilter<T>> = {
|
|
5
|
+
filter?: F | null;
|
|
6
|
+
limit?: number | null;
|
|
7
|
+
offset?: number | null;
|
|
8
|
+
};
|
|
9
|
+
type Page = {
|
|
10
|
+
offset: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
};
|
|
13
|
+
/** Returns a limit/offset page shape for a generated query resolver. */
|
|
14
|
+
declare function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, args: LimitArgs<T, F>): Promise<{
|
|
15
|
+
entities: T[];
|
|
16
|
+
pageInfo: LimitPageInfo<T>;
|
|
17
|
+
}>;
|
|
18
|
+
/** Lazily computes limit/offset page fields. */
|
|
19
|
+
declare class LimitPageInfo<T extends Entity = Entity> {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, filter: PaginationFilter<T>, page: Page);
|
|
22
|
+
get hasNextPage(): Promise<boolean>;
|
|
23
|
+
get hasPreviousPage(): boolean;
|
|
24
|
+
get totalCount(): Promise<number>;
|
|
25
|
+
get nextPage(): Promise<number | undefined>;
|
|
26
|
+
get currentPage(): number;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { LimitPageInfo, paginateLimit };
|
|
30
|
+
//# sourceMappingURL=limitPagination.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.d.mts","names":[],"sources":["../src/limitPagination.ts"],"mappings":";;;KAIK,UAAU,UAAU,QAAQ,mBAAmB,iBAAiB;EACnE,SAAS;EACT;EACA;;KAEG;EAAS;EAAgB;;;iBAGR,cAAc,UAAU,QAAQ,mBAAmB,iBAAiB,IACxF,KAAK,eACL,MAAM,+BAA+B,IACrC,MAAM,UAAU,GAAG,KAClB;EAAU,UAAU;EAAK,UAAU,cAAc;;;cASvC,cAAc,UAAU,SAAS;;EAO5C,YAAY,KAAK,eAAe,MAAM,+BAA+B,IAAI,QAAQ,iBAAiB,IAAI,MAAM;MAOxG,eAAe;MAIf;MAIA,cAAc;MAId,YAAY;MAIZ"}
|
package/build/limitPagination.js
CHANGED
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.paginateLimit = paginateLimit;
|
|
5
|
-
const paginationUtils_1 = require("./paginationUtils");
|
|
1
|
+
import "./paginationUtils.js";
|
|
2
|
+
import "joist-core";
|
|
3
|
+
//#region src/limitPagination.ts
|
|
6
4
|
/** Returns a limit/offset page shape for a generated query resolver. */
|
|
7
5
|
async function paginateLimit(ctx, type, args) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const limit = args.limit ?? 100;
|
|
7
|
+
const offset = args.offset ?? 0;
|
|
8
|
+
const filter = args.filter ?? {};
|
|
9
|
+
return {
|
|
10
|
+
entities: await ctx.em.findGql(type, filter, {
|
|
11
|
+
limit,
|
|
12
|
+
offset
|
|
13
|
+
}),
|
|
14
|
+
pageInfo: new LimitPageInfo(ctx, type, filter, {
|
|
15
|
+
limit,
|
|
16
|
+
offset
|
|
17
|
+
})
|
|
18
|
+
};
|
|
13
19
|
}
|
|
14
20
|
/** Lazily computes limit/offset page fields. */
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
var LimitPageInfo = class {
|
|
22
|
+
#ctx;
|
|
23
|
+
#filter;
|
|
24
|
+
#page;
|
|
25
|
+
#totalCountPromise;
|
|
26
|
+
#type;
|
|
27
|
+
constructor(ctx, type, filter, page) {
|
|
28
|
+
this.#ctx = ctx;
|
|
29
|
+
this.#type = type;
|
|
30
|
+
this.#filter = filter;
|
|
31
|
+
this.#page = page;
|
|
32
|
+
}
|
|
33
|
+
get hasNextPage() {
|
|
34
|
+
return this.#hasNextPage();
|
|
35
|
+
}
|
|
36
|
+
get hasPreviousPage() {
|
|
37
|
+
return this.#page.offset > 0;
|
|
38
|
+
}
|
|
39
|
+
get totalCount() {
|
|
40
|
+
return this.#totalCountPromise ??= this.#ctx.em.findCount(this.#type, this.#filter);
|
|
41
|
+
}
|
|
42
|
+
get nextPage() {
|
|
43
|
+
return this.#nextPage();
|
|
44
|
+
}
|
|
45
|
+
get currentPage() {
|
|
46
|
+
return Math.floor(this.#page.offset / this.#page.limit) + 1;
|
|
47
|
+
}
|
|
48
|
+
/** Returns whether another page exists after this page. */
|
|
49
|
+
async #hasNextPage() {
|
|
50
|
+
const total = await this.totalCount;
|
|
51
|
+
const { offset, limit } = this.#page;
|
|
52
|
+
return offset + limit < total;
|
|
53
|
+
}
|
|
54
|
+
/** Returns the next limit/offset page if there is one. */
|
|
55
|
+
async #nextPage() {
|
|
56
|
+
if (!await this.hasNextPage) return void 0;
|
|
57
|
+
return this.currentPage + 1;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { LimitPageInfo, paginateLimit };
|
|
62
|
+
|
|
56
63
|
//# sourceMappingURL=limitPagination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limitPagination.js","
|
|
1
|
+
{"version":3,"file":"limitPagination.js","names":["#ctx","#type","#filter","#page","#hasNextPage","#totalCountPromise","#nextPage"],"sources":["../src/limitPagination.ts"],"sourcesContent":["import { type Entity, type MaybeAbstractEntityConstructor } from \"joist-core\";\n\nimport { type ContextWithEm, type PaginationFilter, defaultLimit } from \"./paginationUtils.ts\";\n\ntype LimitArgs<T extends Entity, F extends object = PaginationFilter<T>> = {\n filter?: F | null;\n limit?: number | null;\n offset?: number | null;\n};\ntype Page = { offset: number; limit: number };\n\n/** Returns a limit/offset page shape for a generated query resolver. */\nexport async function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T>,\n args: LimitArgs<T, F>,\n): Promise<{ entities: T[]; pageInfo: LimitPageInfo<T> }> {\n const limit = args.limit ?? defaultLimit;\n const offset = args.offset ?? 0;\n const filter = (args.filter ?? {}) as PaginationFilter<T>;\n const entities = await ctx.em.findGql(type, filter, { limit, offset });\n return { entities, pageInfo: new LimitPageInfo(ctx, type, filter, { limit, offset }) };\n}\n\n/** Lazily computes limit/offset page fields. */\nexport class LimitPageInfo<T extends Entity = Entity> {\n #ctx: ContextWithEm;\n #filter: PaginationFilter<T>;\n #page: Page;\n #totalCountPromise: Promise<number> | undefined;\n #type: MaybeAbstractEntityConstructor<T>;\n\n constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, filter: PaginationFilter<T>, page: Page) {\n this.#ctx = ctx;\n this.#type = type;\n this.#filter = filter;\n this.#page = page;\n }\n\n get hasNextPage(): Promise<boolean> {\n return this.#hasNextPage();\n }\n\n get hasPreviousPage(): boolean {\n return this.#page.offset > 0;\n }\n\n get totalCount(): Promise<number> {\n return (this.#totalCountPromise ??= this.#ctx.em.findCount(this.#type, this.#filter));\n }\n\n get nextPage(): Promise<number | undefined> {\n return this.#nextPage();\n }\n\n get currentPage(): number {\n return Math.floor(this.#page.offset / this.#page.limit) + 1;\n }\n\n /** Returns whether another page exists after this page. */\n async #hasNextPage(): Promise<boolean> {\n const total = await this.totalCount;\n const { offset, limit } = this.#page;\n return offset + limit < total;\n }\n\n /** Returns the next limit/offset page if there is one. */\n async #nextPage(): Promise<number | undefined> {\n if (!(await this.hasNextPage)) return undefined;\n return this.currentPage + 1;\n }\n}\n"],"mappings":";;;;AAYA,eAAsB,cACpB,KACA,MACA,MACwD;CACxD,MAAM,QAAQ,KAAK,SAAA;CACnB,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,SAAU,KAAK,UAAU,CAAC;CAEhC,OAAO;EAAE,UAAA,MADc,IAAI,GAAG,QAAQ,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;EAClD,UAAU,IAAI,cAAc,KAAK,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;CAAE;AACvF;;AAGA,IAAa,gBAAb,MAAsD;CACpD;CACA;CACA;CACA;CACA;CAEA,YAAY,KAAoB,MAAyC,QAA6B,MAAY;EAChH,KAAKA,OAAO;EACZ,KAAKC,QAAQ;EACb,KAAKC,UAAU;EACf,KAAKC,QAAQ;CACf;CAEA,IAAI,cAAgC;EAClC,OAAO,KAAKC,aAAa;CAC3B;CAEA,IAAI,kBAA2B;EAC7B,OAAO,KAAKD,MAAM,SAAS;CAC7B;CAEA,IAAI,aAA8B;EAChC,OAAQ,KAAKE,uBAAuB,KAAKL,KAAK,GAAG,UAAU,KAAKC,OAAO,KAAKC,OAAO;CACrF;CAEA,IAAI,WAAwC;EAC1C,OAAO,KAAKI,UAAU;CACxB;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK,MAAM,KAAKH,MAAM,SAAS,KAAKA,MAAM,KAAK,IAAI;CAC5D;;CAGA,MAAMC,eAAiC;EACrC,MAAM,QAAQ,MAAM,KAAK;EACzB,MAAM,EAAE,QAAQ,UAAU,KAAKD;EAC/B,OAAO,SAAS,QAAQ;CAC1B;;CAGA,MAAMG,YAAyC;EAC7C,IAAI,CAAE,MAAM,KAAK,aAAc,OAAO,KAAA;EACtC,OAAO,KAAK,cAAc;CAC5B;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./context.cjs");
|
|
3
|
+
require("./typeUtils.cjs");
|
|
4
|
+
//#region src/makeRunInputMutation.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `makeRunInputMutation` 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 makeMakeRunInputMutation(runFn) {
|
|
12
|
+
return (resolver) => {
|
|
13
|
+
return (ctx, args) => runFn(ctx, (ctx) => {
|
|
14
|
+
return resolver[Object.keys(resolver)[0]]({}, { input: args instanceof Function ? args() : args ?? {} }, ctx, void 0);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.makeMakeRunInputMutation = makeMakeRunInputMutation;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=makeRunInputMutation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunInputMutation.cjs","names":[],"sources":["../src/makeRunInputMutation.ts"],"sourcesContent":["import { type Resolver } from \"./context.ts\";\nimport { type ResolverResult, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunInputMutation` 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 makeMakeRunInputMutation<C>(runFn: RunFn<C>): MakeRunInputMutation<C> {\n return (resolver) => {\n return (ctx, args) =>\n runFn(ctx, (ctx) => {\n const key = Object.keys(resolver)[0];\n return ((resolver as any)[key] as any)(\n {},\n { input: args instanceof Function ? args() : (args ?? {}) },\n ctx,\n undefined!,\n );\n });\n };\n}\n\n/**\n * Creates a `run` method to invoke a mutation resolver that uses the `input` convention.\n *\n * Following our `mutation / foo` conventions, `resolver` will have a single `fooResolver.foo` method.\n */\nexport type MakeRunInputMutation<C> = <T extends object>(resolver: T) => RunInputMutationMethod<C, T>;\n\ntype RunInputMutationMethod<C, T> = <I extends MutationInput<T>, R = ResolverResult<T, keyof T>>(\n ctx: C,\n input: I | (() => I),\n) => Promise<R>;\n\n/** Matches a mutation resolver that has a single `input` field. */\ntype MutationInput<T> = T[keyof T] extends Resolver<any, { input: infer I }, any> ? I : never;\n"],"mappings":";;;;;;;;;;AASA,SAAgB,yBAA4B,OAA0C;CACpF,QAAQ,aAAa;EACnB,QAAQ,KAAK,SACX,MAAM,MAAM,QAAQ;GAElB,OAAS,SADG,OAAO,KAAK,QAAQ,CAAC,CAAC,GACJ,CAC5B,CAAC,GACD,EAAE,OAAO,gBAAgB,WAAW,KAAK,IAAK,QAAQ,CAAC,EAAG,GAC1D,KACA,KAAA,CACF;EACF,CAAC;CACL;AACF"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { Resolver } from "./context";
|
|
2
|
-
import { ResolverResult, RunFn } from "./typeUtils";
|
|
1
|
+
import { Resolver } from "./context.cjs";
|
|
2
|
+
import { ResolverResult, RunFn } from "./typeUtils.cjs";
|
|
3
|
+
//#region src/makeRunInputMutation.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Creates a `makeRunInputMutation` function for each project's `testUtils` file.
|
|
5
6
|
*
|
|
6
7
|
* This is called `makeMake` because it's a factory for each project's `testUtils` to make its own factory
|
|
7
8
|
* that is customized (basically curried) to their own `newContext` function.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function makeMakeRunInputMutation<C>(runFn: RunFn<C>): MakeRunInputMutation<C>;
|
|
10
11
|
/**
|
|
11
12
|
* Creates a `run` method to invoke a mutation resolver that uses the `input` convention.
|
|
12
13
|
*
|
|
13
14
|
* Following our `mutation / foo` conventions, `resolver` will have a single `fooResolver.foo` method.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
type MakeRunInputMutation<C> = <T extends object>(resolver: T) => RunInputMutationMethod<C, T>;
|
|
16
17
|
type RunInputMutationMethod<C, T> = <I extends MutationInput<T>, R = ResolverResult<T, keyof T>>(ctx: C, input: I | (() => I)) => Promise<R>;
|
|
17
18
|
/** Matches a mutation resolver that has a single `input` field. */
|
|
18
19
|
type MutationInput<T> = T[keyof T] extends Resolver<any, {
|
|
19
|
-
|
|
20
|
+
input: infer I;
|
|
20
21
|
}, any> ? I : never;
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MakeRunInputMutation, makeMakeRunInputMutation };
|
|
24
|
+
//# sourceMappingURL=makeRunInputMutation.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunInputMutation.d.cts","names":[],"sources":["../src/makeRunInputMutation.ts"],"mappings":";;;;;;;;;iBASgB,yBAAyB,GAAG,OAAO,MAAM,KAAK,qBAAqB;;;;;;KAoBvE,qBAAqB,MAAM,kBAAkB,UAAU,MAAM,uBAAuB,GAAG;KAE9F,uBAAuB,GAAG,MAAM,UAAU,cAAc,IAAI,IAAI,eAAe,SAAS,IAC3F,KAAK,GACL,OAAO,WAAW,OACf,QAAQ;;KAGR,cAAc,KAAK,QAAQ,WAAW;EAAgB,aAAa;UAAY"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Resolver } from "./context.mjs";
|
|
2
|
+
import { ResolverResult, RunFn } from "./typeUtils.mjs";
|
|
3
|
+
//#region src/makeRunInputMutation.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a `makeRunInputMutation` 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
|
+
declare function makeMakeRunInputMutation<C>(runFn: RunFn<C>): MakeRunInputMutation<C>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a `run` method to invoke a mutation resolver that uses the `input` convention.
|
|
13
|
+
*
|
|
14
|
+
* Following our `mutation / foo` conventions, `resolver` will have a single `fooResolver.foo` method.
|
|
15
|
+
*/
|
|
16
|
+
type MakeRunInputMutation<C> = <T extends object>(resolver: T) => RunInputMutationMethod<C, T>;
|
|
17
|
+
type RunInputMutationMethod<C, T> = <I extends MutationInput<T>, R = ResolverResult<T, keyof T>>(ctx: C, input: I | (() => I)) => Promise<R>;
|
|
18
|
+
/** Matches a mutation resolver that has a single `input` field. */
|
|
19
|
+
type MutationInput<T> = T[keyof T] extends Resolver<any, {
|
|
20
|
+
input: infer I;
|
|
21
|
+
}, any> ? I : never;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MakeRunInputMutation, makeMakeRunInputMutation };
|
|
24
|
+
//# sourceMappingURL=makeRunInputMutation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunInputMutation.d.mts","names":[],"sources":["../src/makeRunInputMutation.ts"],"mappings":";;;;;;;;;iBASgB,yBAAyB,GAAG,OAAO,MAAM,KAAK,qBAAqB;;;;;;KAoBvE,qBAAqB,MAAM,kBAAkB,UAAU,MAAM,uBAAuB,GAAG;KAE9F,uBAAuB,GAAG,MAAM,UAAU,cAAc,IAAI,IAAI,eAAe,SAAS,IAC3F,KAAK,GACL,OAAO,WAAW,OACf,QAAQ;;KAGR,cAAc,KAAK,QAAQ,WAAW;EAAgB,aAAa;UAAY"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "./context.js";
|
|
2
|
+
import "./typeUtils.js";
|
|
3
|
+
//#region src/makeRunInputMutation.ts
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Creates a `makeRunInputMutation` 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
10
|
function makeMakeRunInputMutation(runFn) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
11
|
+
return (resolver) => {
|
|
12
|
+
return (ctx, args) => runFn(ctx, (ctx) => {
|
|
13
|
+
return resolver[Object.keys(resolver)[0]]({}, { input: args instanceof Function ? args() : args ?? {} }, ctx, void 0);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
17
16
|
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { makeMakeRunInputMutation };
|
|
19
|
+
|
|
18
20
|
//# sourceMappingURL=makeRunInputMutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeRunInputMutation.js","
|
|
1
|
+
{"version":3,"file":"makeRunInputMutation.js","names":[],"sources":["../src/makeRunInputMutation.ts"],"sourcesContent":["import { type Resolver } from \"./context.ts\";\nimport { type ResolverResult, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunInputMutation` 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 makeMakeRunInputMutation<C>(runFn: RunFn<C>): MakeRunInputMutation<C> {\n return (resolver) => {\n return (ctx, args) =>\n runFn(ctx, (ctx) => {\n const key = Object.keys(resolver)[0];\n return ((resolver as any)[key] as any)(\n {},\n { input: args instanceof Function ? args() : (args ?? {}) },\n ctx,\n undefined!,\n );\n });\n };\n}\n\n/**\n * Creates a `run` method to invoke a mutation resolver that uses the `input` convention.\n *\n * Following our `mutation / foo` conventions, `resolver` will have a single `fooResolver.foo` method.\n */\nexport type MakeRunInputMutation<C> = <T extends object>(resolver: T) => RunInputMutationMethod<C, T>;\n\ntype RunInputMutationMethod<C, T> = <I extends MutationInput<T>, R = ResolverResult<T, keyof T>>(\n ctx: C,\n input: I | (() => I),\n) => Promise<R>;\n\n/** Matches a mutation resolver that has a single `input` field. */\ntype MutationInput<T> = T[keyof T] extends Resolver<any, { input: infer I }, any> ? I : never;\n"],"mappings":";;;;;;;;;AASA,SAAgB,yBAA4B,OAA0C;CACpF,QAAQ,aAAa;EACnB,QAAQ,KAAK,SACX,MAAM,MAAM,QAAQ;GAElB,OAAS,SADG,OAAO,KAAK,QAAQ,CAAC,CAAC,GACJ,CAC5B,CAAC,GACD,EAAE,OAAO,gBAAgB,WAAW,KAAK,IAAK,QAAQ,CAAC,EAAG,GAC1D,KACA,KAAA,CACF;EACF,CAAC;CACL;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./typeUtils.cjs");
|
|
3
|
+
let joist_core = require("joist-core");
|
|
4
|
+
//#region src/makeRunObjectField.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `makeRunObjectField` 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 makeMakeRunObjectField(runFn) {
|
|
12
|
+
return (resolvers) => {
|
|
13
|
+
return (ctx, root, key, args) => runFn(ctx, async (ctx) => {
|
|
14
|
+
const _root = (0, joist_core.isEntity)(root) ? await ctx.em.load(root.id) : root;
|
|
15
|
+
return resolvers[key](_root, args instanceof Function ? args(_root) : args ?? {}, ctx, void 0);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.makeMakeRunObjectField = makeMakeRunObjectField;
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=makeRunObjectField.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectField.cjs","names":["isEntity"],"sources":["../src/makeRunObjectField.ts"],"sourcesContent":["import { isEntity } from \"joist-core\";\n\nimport { type ResolverArgs, type ResolverResult, type ResolverRoot, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunObjectField` 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 makeMakeRunObjectField<C>(runFn: RunFn<C>): MakeRunObjectField<C> {\n return (resolvers) => {\n return (ctx, root, key, args) =>\n 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 return (resolvers[key] as any)(_root, args instanceof Function ? args(_root) : (args ?? {}), ctx, undefined!);\n });\n };\n}\n\n/** Creates a `run` method to invoke a single field resolver with that field's args. */\nexport type MakeRunObjectField<C> = <T extends object, R extends ResolverRoot<T>>(\n resolvers: T,\n) => RunObjectFieldMethod<C, T, R>;\n\n/** The return type of `makeRunObject`. */\ntype RunObjectFieldMethod<C, T, R> = <K extends keyof T, A extends ResolverArgs<T, K>>(\n ctx: C,\n root: R,\n key: K,\n // Support either the resolver arg directly or a lambda to create the args post-flush\n args?: A | ((root: R) => A),\n) => Promise<ResolverResult<T, K>>;\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,uBAA0B,OAAwC;CAChF,QAAQ,cAAc;EACpB,QAAQ,KAAK,MAAM,KAAK,SACtB,MAAM,KAAK,OAAO,QAAQ;GAExB,MAAM,SAAA,GAAQA,WAAAA,SAAAA,CAAS,IAAI,IAAI,MAAO,IAAY,GAAG,KAAM,KAAa,EAAE,IAAI;GAC9E,OAAQ,UAAU,IAAI,CAAS,OAAO,gBAAgB,WAAW,KAAK,KAAK,IAAK,QAAQ,CAAC,GAAI,KAAK,KAAA,CAAU;EAC9G,CAAC;CACL;AACF"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ResolverArgs, ResolverResult, ResolverRoot, RunFn } from "./typeUtils";
|
|
1
|
+
import { ResolverArgs, ResolverResult, ResolverRoot, RunFn } from "./typeUtils.cjs";
|
|
2
|
+
//#region src/makeRunObjectField.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Creates a `makeRunObjectField` 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 makeMakeRunObjectField<C>(runFn: RunFn<C>): MakeRunObjectField<C>;
|
|
9
10
|
/** Creates a `run` method to invoke a single field resolver with that field's args. */
|
|
10
|
-
|
|
11
|
+
type MakeRunObjectField<C> = <T extends object, R extends ResolverRoot<T>>(resolvers: T) => RunObjectFieldMethod<C, T, R>;
|
|
11
12
|
/** The return type of `makeRunObject`. */
|
|
12
13
|
type RunObjectFieldMethod<C, T, R> = <K extends keyof T, A extends ResolverArgs<T, K>>(ctx: C, root: R, key: K, args?: A | ((root: R) => A)) => Promise<ResolverResult<T, K>>;
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MakeRunObjectField, makeMakeRunObjectField };
|
|
16
|
+
//# sourceMappingURL=makeRunObjectField.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectField.d.cts","names":[],"sources":["../src/makeRunObjectField.ts"],"mappings":";;;;;;;;iBAUgB,uBAAuB,GAAG,OAAO,MAAM,KAAK,mBAAmB;;KAYnE,mBAAmB,MAAM,kBAAkB,UAAU,aAAa,IAC5E,WAAW,MACR,qBAAqB,GAAG,GAAG;;KAG3B,qBAAqB,GAAG,GAAG,MAAM,gBAAgB,GAAG,UAAU,aAAa,GAAG,IACjF,KAAK,GACL,MAAM,GACN,KAAK,GAEL,OAAO,MAAM,MAAM,MAAM,OACtB,QAAQ,eAAe,GAAG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ResolverArgs, ResolverResult, ResolverRoot, RunFn } from "./typeUtils.mjs";
|
|
2
|
+
//#region src/makeRunObjectField.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `makeRunObjectField` 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 makeMakeRunObjectField<C>(runFn: RunFn<C>): MakeRunObjectField<C>;
|
|
10
|
+
/** Creates a `run` method to invoke a single field resolver with that field's args. */
|
|
11
|
+
type MakeRunObjectField<C> = <T extends object, R extends ResolverRoot<T>>(resolvers: T) => RunObjectFieldMethod<C, T, R>;
|
|
12
|
+
/** The return type of `makeRunObject`. */
|
|
13
|
+
type RunObjectFieldMethod<C, T, R> = <K extends keyof T, A extends ResolverArgs<T, K>>(ctx: C, root: R, key: K, args?: A | ((root: R) => A)) => Promise<ResolverResult<T, K>>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MakeRunObjectField, makeMakeRunObjectField };
|
|
16
|
+
//# sourceMappingURL=makeRunObjectField.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRunObjectField.d.mts","names":[],"sources":["../src/makeRunObjectField.ts"],"mappings":";;;;;;;;iBAUgB,uBAAuB,GAAG,OAAO,MAAM,KAAK,mBAAmB;;KAYnE,mBAAmB,MAAM,kBAAkB,UAAU,aAAa,IAC5E,WAAW,MACR,qBAAqB,GAAG,GAAG;;KAG3B,qBAAqB,GAAG,GAAG,MAAM,gBAAgB,GAAG,UAAU,aAAa,GAAG,IACjF,KAAK,GACL,MAAM,GACN,KAAK,GAEL,OAAO,MAAM,MAAM,MAAM,OACtB,QAAQ,eAAe,GAAG"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const joist_core_1 = require("joist-core");
|
|
1
|
+
import "./typeUtils.js";
|
|
2
|
+
import { isEntity } from "joist-core";
|
|
3
|
+
//#region src/makeRunObjectField.ts
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
* Creates a `makeRunObjectField` 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 makeMakeRunObjectField(runFn) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
11
|
+
return (resolvers) => {
|
|
12
|
+
return (ctx, root, key, args) => runFn(ctx, async (ctx) => {
|
|
13
|
+
const _root = isEntity(root) ? await ctx.em.load(root.id) : root;
|
|
14
|
+
return resolvers[key](_root, args instanceof Function ? args(_root) : args ?? {}, ctx, void 0);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
19
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { makeMakeRunObjectField };
|
|
20
|
+
|
|
20
21
|
//# sourceMappingURL=makeRunObjectField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeRunObjectField.js","
|
|
1
|
+
{"version":3,"file":"makeRunObjectField.js","names":[],"sources":["../src/makeRunObjectField.ts"],"sourcesContent":["import { isEntity } from \"joist-core\";\n\nimport { type ResolverArgs, type ResolverResult, type ResolverRoot, type RunFn } from \"./typeUtils.ts\";\n\n/**\n * Creates a `makeRunObjectField` 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 makeMakeRunObjectField<C>(runFn: RunFn<C>): MakeRunObjectField<C> {\n return (resolvers) => {\n return (ctx, root, key, args) =>\n 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 return (resolvers[key] as any)(_root, args instanceof Function ? args(_root) : (args ?? {}), ctx, undefined!);\n });\n };\n}\n\n/** Creates a `run` method to invoke a single field resolver with that field's args. */\nexport type MakeRunObjectField<C> = <T extends object, R extends ResolverRoot<T>>(\n resolvers: T,\n) => RunObjectFieldMethod<C, T, R>;\n\n/** The return type of `makeRunObject`. */\ntype RunObjectFieldMethod<C, T, R> = <K extends keyof T, A extends ResolverArgs<T, K>>(\n ctx: C,\n root: R,\n key: K,\n // Support either the resolver arg directly or a lambda to create the args post-flush\n args?: A | ((root: R) => A),\n) => Promise<ResolverResult<T, K>>;\n"],"mappings":";;;;;;;;;AAUA,SAAgB,uBAA0B,OAAwC;CAChF,QAAQ,cAAc;EACpB,QAAQ,KAAK,MAAM,KAAK,SACtB,MAAM,KAAK,OAAO,QAAQ;GAExB,MAAM,QAAQ,SAAS,IAAI,IAAI,MAAO,IAAY,GAAG,KAAM,KAAa,EAAE,IAAI;GAC9E,OAAQ,UAAU,IAAI,CAAS,OAAO,gBAAgB,WAAW,KAAK,KAAK,IAAK,QAAQ,CAAC,GAAI,KAAK,KAAA,CAAU;EAC9G,CAAC;CACL;AACF"}
|
|
@@ -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"}
|