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
package/build/index.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var entityResolver_1 = require("./entityResolver");
|
|
8
|
-
Object.defineProperty(exports, "entityResolver", { enumerable: true, get: function () { return entityResolver_1.entityResolver; } });
|
|
9
|
-
var hint_1 = require("./hint");
|
|
10
|
-
Object.defineProperty(exports, "convertInfoToLoadHint", { enumerable: true, get: function () { return hint_1.convertInfoToLoadHint; } });
|
|
11
|
-
var limitPagination_1 = require("./limitPagination");
|
|
12
|
-
Object.defineProperty(exports, "LimitPageInfo", { enumerable: true, get: function () { return limitPagination_1.LimitPageInfo; } });
|
|
13
|
-
Object.defineProperty(exports, "paginateLimit", { enumerable: true, get: function () { return limitPagination_1.paginateLimit; } });
|
|
14
|
-
var saveEntity_1 = require("./saveEntity");
|
|
15
|
-
Object.defineProperty(exports, "saveEntities", { enumerable: true, get: function () { return saveEntity_1.saveEntities; } });
|
|
16
|
-
Object.defineProperty(exports, "saveEntity", { enumerable: true, get: function () { return saveEntity_1.saveEntity; } });
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { CursorPageInfo, paginateCursor } from "./cursorPagination.js";
|
|
2
|
+
import { convertInfoToLoadHint } from "./hint.js";
|
|
3
|
+
import { entityResolver } from "./entityResolver.js";
|
|
4
|
+
import { LimitPageInfo, paginateLimit } from "./limitPagination.js";
|
|
5
|
+
import { saveEntities, saveEntity } from "./saveEntity.js";
|
|
6
|
+
export { CursorPageInfo, LimitPageInfo, convertInfoToLoadHint, entityResolver, paginateCursor, paginateLimit, saveEntities, saveEntity };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_paginationUtils = require("./paginationUtils.cjs");
|
|
3
|
+
require("joist-core");
|
|
4
|
+
//#region src/limitPagination.ts
|
|
5
|
+
async function paginateLimit(ctx, type, args) {
|
|
6
|
+
const limit = args.limit ?? 100;
|
|
7
|
+
const offset = args.offset ?? 0;
|
|
8
|
+
const filter = args.filter ?? {};
|
|
9
|
+
return {
|
|
10
|
+
entities: typeof type === "function" ? await ctx.em.findGql(type, filter, {
|
|
11
|
+
limit,
|
|
12
|
+
offset
|
|
13
|
+
}) : await require_paginationUtils.queryEntities(ctx, {
|
|
14
|
+
...type,
|
|
15
|
+
limit,
|
|
16
|
+
offset
|
|
17
|
+
}),
|
|
18
|
+
pageInfo: new LimitPageInfo(ctx, type, filter, {
|
|
19
|
+
limit,
|
|
20
|
+
offset
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Lazily computes limit/offset page fields. */
|
|
25
|
+
var LimitPageInfo = class {
|
|
26
|
+
#ctx;
|
|
27
|
+
#filter;
|
|
28
|
+
#page;
|
|
29
|
+
#totalCountPromise;
|
|
30
|
+
#type;
|
|
31
|
+
constructor(ctx, type, filter, page) {
|
|
32
|
+
this.#ctx = ctx;
|
|
33
|
+
this.#type = type;
|
|
34
|
+
this.#filter = filter;
|
|
35
|
+
this.#page = page;
|
|
36
|
+
}
|
|
37
|
+
get hasNextPage() {
|
|
38
|
+
return this.#hasNextPage();
|
|
39
|
+
}
|
|
40
|
+
get hasPreviousPage() {
|
|
41
|
+
return this.#page.offset > 0;
|
|
42
|
+
}
|
|
43
|
+
get totalCount() {
|
|
44
|
+
return this.#totalCountPromise ??= typeof this.#type === "function" ? this.#ctx.em.findCount(this.#type, this.#filter) : require_paginationUtils.countQuery(this.#ctx, this.#type);
|
|
45
|
+
}
|
|
46
|
+
get nextPage() {
|
|
47
|
+
return this.#nextPage();
|
|
48
|
+
}
|
|
49
|
+
get currentPage() {
|
|
50
|
+
return Math.floor(this.#page.offset / this.#page.limit) + 1;
|
|
51
|
+
}
|
|
52
|
+
/** Returns whether another page exists after this page. */
|
|
53
|
+
async #hasNextPage() {
|
|
54
|
+
const total = await this.totalCount;
|
|
55
|
+
const { offset, limit } = this.#page;
|
|
56
|
+
return offset + limit < total;
|
|
57
|
+
}
|
|
58
|
+
/** Returns the next limit/offset page if there is one. */
|
|
59
|
+
async #nextPage() {
|
|
60
|
+
if (!await this.hasNextPage) return void 0;
|
|
61
|
+
return this.currentPage + 1;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.LimitPageInfo = LimitPageInfo;
|
|
66
|
+
exports.paginateLimit = paginateLimit;
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=limitPagination.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.cjs","names":["queryEntities","#ctx","#type","#filter","#page","#hasNextPage","#totalCountPromise","countQuery","#nextPage"],"sources":["../src/limitPagination.ts"],"sourcesContent":["import { type Entity, type MaybeAbstractEntityConstructor } from \"joist-core\";\n\nimport {\n type ContextWithEm,\n type PaginationFilter,\n type PaginationQuery,\n countQuery,\n defaultLimit,\n queryEntities,\n} 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 resolver, preserving the entity query's ordering. */\nexport function paginateLimit<T extends Entity>(\n ctx: ContextWithEm,\n query: PaginationQuery<T>,\n args: Omit<LimitArgs<T>, \"filter\">,\n): Promise<{ entities: T[]; pageInfo: LimitPageInfo<T> }>;\nexport 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> }>;\nexport async function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T> | PaginationQuery<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 =\n typeof type === \"function\"\n ? await ctx.em.findGql(type, filter, { limit, offset })\n : await queryEntities<T>(ctx, { ...type, 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> | PaginationQuery<T>;\n\n constructor(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T> | PaginationQuery<T>,\n filter: PaginationFilter<T>,\n page: Page,\n ) {\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 ??=\n typeof this.#type === \"function\"\n ? this.#ctx.em.findCount(this.#type, this.#filter)\n : countQuery(this.#ctx, this.#type));\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":";;;;AA6BA,eAAsB,cACpB,KACA,MACA,MACwD;CACxD,MAAM,QAAQ,KAAK,SAAA;CACnB,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,SAAU,KAAK,UAAU,CAAC;CAKhC,OAAO;EAAE,UAHP,OAAO,SAAS,aACZ,MAAM,IAAI,GAAG,QAAQ,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC,IACpD,MAAMA,wBAAAA,cAAiB,KAAK;GAAE,GAAG;GAAM;GAAO;EAAO,CAAC;EACzC,UAAU,IAAI,cAAc,KAAK,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;CAAE;AACvF;;AAGA,IAAa,gBAAb,MAAsD;CACpD;CACA;CACA;CACA;CACA;CAEA,YACE,KACA,MACA,QACA,MACA;EACA,KAAKC,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,uBACX,OAAO,KAAKJ,UAAU,aAClB,KAAKD,KAAK,GAAG,UAAU,KAAKC,OAAO,KAAKC,OAAO,IAC/CI,wBAAAA,WAAW,KAAKN,MAAM,KAAKC,KAAK;CACxC;CAEA,IAAI,WAAwC;EAC1C,OAAO,KAAKM,UAAU;CACxB;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK,MAAM,KAAKJ,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,MAAMI,YAAyC;EAC7C,IAAI,CAAE,MAAM,KAAK,aAAc,OAAO,KAAA;EACtC,OAAO,KAAK,cAAc;CAC5B;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContextWithEm, PaginationFilter, PaginationQuery } 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 resolver, preserving the entity query's ordering. */
|
|
14
|
+
declare function paginateLimit<T extends Entity>(ctx: ContextWithEm, query: PaginationQuery<T>, args: Omit<LimitArgs<T>, "filter">): Promise<{
|
|
15
|
+
entities: T[];
|
|
16
|
+
pageInfo: LimitPageInfo<T>;
|
|
17
|
+
}>;
|
|
18
|
+
declare function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, args: LimitArgs<T, F>): Promise<{
|
|
19
|
+
entities: T[];
|
|
20
|
+
pageInfo: LimitPageInfo<T>;
|
|
21
|
+
}>;
|
|
22
|
+
/** Lazily computes limit/offset page fields. */
|
|
23
|
+
declare class LimitPageInfo<T extends Entity = Entity> {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T> | PaginationQuery<T>, filter: PaginationFilter<T>, page: Page);
|
|
26
|
+
get hasNextPage(): Promise<boolean>;
|
|
27
|
+
get hasPreviousPage(): boolean;
|
|
28
|
+
get totalCount(): Promise<number>;
|
|
29
|
+
get nextPage(): Promise<number | undefined>;
|
|
30
|
+
get currentPage(): number;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { LimitPageInfo, paginateLimit };
|
|
34
|
+
//# sourceMappingURL=limitPagination.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.d.cts","names":[],"sources":["../src/limitPagination.ts"],"mappings":";;;KAWK,UAAU,UAAU,QAAQ,mBAAmB,iBAAiB;EACnE,SAAS;EACT;EACA;;KAEG;EAAS;EAAgB;;;iBAGd,cAAc,UAAU,QACtC,KAAK,eACL,OAAO,gBAAgB,IACvB,MAAM,KAAK,UAAU,gBACpB;EAAU,UAAU;EAAK,UAAU,cAAc;;iBACpC,cAAc,UAAU,QAAQ,mBAAmB,iBAAiB,IAClF,KAAK,eACL,MAAM,+BAA+B,IACrC,MAAM,UAAU,GAAG,KAClB;EAAU,UAAU;EAAK,UAAU,cAAc;;;cAiBvC,cAAc,UAAU,SAAS;;EAO5C,YACE,KAAK,eACL,MAAM,+BAA+B,KAAK,gBAAgB,IAC1D,QAAQ,iBAAiB,IACzB,MAAM;MAQJ,eAAe;MAIf;MAIA,cAAc;MAOd,YAAY;MAIZ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContextWithEm, PaginationFilter, PaginationQuery } 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 resolver, preserving the entity query's ordering. */
|
|
14
|
+
declare function paginateLimit<T extends Entity>(ctx: ContextWithEm, query: PaginationQuery<T>, args: Omit<LimitArgs<T>, "filter">): Promise<{
|
|
15
|
+
entities: T[];
|
|
16
|
+
pageInfo: LimitPageInfo<T>;
|
|
17
|
+
}>;
|
|
18
|
+
declare function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T>, args: LimitArgs<T, F>): Promise<{
|
|
19
|
+
entities: T[];
|
|
20
|
+
pageInfo: LimitPageInfo<T>;
|
|
21
|
+
}>;
|
|
22
|
+
/** Lazily computes limit/offset page fields. */
|
|
23
|
+
declare class LimitPageInfo<T extends Entity = Entity> {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(ctx: ContextWithEm, type: MaybeAbstractEntityConstructor<T> | PaginationQuery<T>, filter: PaginationFilter<T>, page: Page);
|
|
26
|
+
get hasNextPage(): Promise<boolean>;
|
|
27
|
+
get hasPreviousPage(): boolean;
|
|
28
|
+
get totalCount(): Promise<number>;
|
|
29
|
+
get nextPage(): Promise<number | undefined>;
|
|
30
|
+
get currentPage(): number;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { LimitPageInfo, paginateLimit };
|
|
34
|
+
//# sourceMappingURL=limitPagination.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limitPagination.d.mts","names":[],"sources":["../src/limitPagination.ts"],"mappings":";;;KAWK,UAAU,UAAU,QAAQ,mBAAmB,iBAAiB;EACnE,SAAS;EACT;EACA;;KAEG;EAAS;EAAgB;;;iBAGd,cAAc,UAAU,QACtC,KAAK,eACL,OAAO,gBAAgB,IACvB,MAAM,KAAK,UAAU,gBACpB;EAAU,UAAU;EAAK,UAAU,cAAc;;iBACpC,cAAc,UAAU,QAAQ,mBAAmB,iBAAiB,IAClF,KAAK,eACL,MAAM,+BAA+B,IACrC,MAAM,UAAU,GAAG,KAClB;EAAU,UAAU;EAAK,UAAU,cAAc;;;cAiBvC,cAAc,UAAU,SAAS;;EAO5C,YACE,KAAK,eACL,MAAM,+BAA+B,KAAK,gBAAgB,IAC1D,QAAQ,iBAAiB,IACzB,MAAM;MAQJ,eAAe;MAIf;MAIA,cAAc;MAOd,YAAY;MAIZ"}
|
package/build/limitPagination.js
CHANGED
|
@@ -1,56 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.paginateLimit = paginateLimit;
|
|
5
|
-
const paginationUtils_1 = require("./paginationUtils");
|
|
6
|
-
/** Returns a limit/offset page shape for a generated query resolver. */
|
|
1
|
+
import { countQuery, queryEntities } from "./paginationUtils.js";
|
|
2
|
+
import "joist-core";
|
|
3
|
+
//#region src/limitPagination.ts
|
|
7
4
|
async function paginateLimit(ctx, type, args) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const limit = args.limit ?? 100;
|
|
6
|
+
const offset = args.offset ?? 0;
|
|
7
|
+
const filter = args.filter ?? {};
|
|
8
|
+
return {
|
|
9
|
+
entities: typeof type === "function" ? await ctx.em.findGql(type, filter, {
|
|
10
|
+
limit,
|
|
11
|
+
offset
|
|
12
|
+
}) : await queryEntities(ctx, {
|
|
13
|
+
...type,
|
|
14
|
+
limit,
|
|
15
|
+
offset
|
|
16
|
+
}),
|
|
17
|
+
pageInfo: new LimitPageInfo(ctx, type, filter, {
|
|
18
|
+
limit,
|
|
19
|
+
offset
|
|
20
|
+
})
|
|
21
|
+
};
|
|
13
22
|
}
|
|
14
23
|
/** 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
|
-
|
|
24
|
+
var LimitPageInfo = class {
|
|
25
|
+
#ctx;
|
|
26
|
+
#filter;
|
|
27
|
+
#page;
|
|
28
|
+
#totalCountPromise;
|
|
29
|
+
#type;
|
|
30
|
+
constructor(ctx, type, filter, page) {
|
|
31
|
+
this.#ctx = ctx;
|
|
32
|
+
this.#type = type;
|
|
33
|
+
this.#filter = filter;
|
|
34
|
+
this.#page = page;
|
|
35
|
+
}
|
|
36
|
+
get hasNextPage() {
|
|
37
|
+
return this.#hasNextPage();
|
|
38
|
+
}
|
|
39
|
+
get hasPreviousPage() {
|
|
40
|
+
return this.#page.offset > 0;
|
|
41
|
+
}
|
|
42
|
+
get totalCount() {
|
|
43
|
+
return this.#totalCountPromise ??= typeof this.#type === "function" ? this.#ctx.em.findCount(this.#type, this.#filter) : countQuery(this.#ctx, this.#type);
|
|
44
|
+
}
|
|
45
|
+
get nextPage() {
|
|
46
|
+
return this.#nextPage();
|
|
47
|
+
}
|
|
48
|
+
get currentPage() {
|
|
49
|
+
return Math.floor(this.#page.offset / this.#page.limit) + 1;
|
|
50
|
+
}
|
|
51
|
+
/** Returns whether another page exists after this page. */
|
|
52
|
+
async #hasNextPage() {
|
|
53
|
+
const total = await this.totalCount;
|
|
54
|
+
const { offset, limit } = this.#page;
|
|
55
|
+
return offset + limit < total;
|
|
56
|
+
}
|
|
57
|
+
/** Returns the next limit/offset page if there is one. */
|
|
58
|
+
async #nextPage() {
|
|
59
|
+
if (!await this.hasNextPage) return void 0;
|
|
60
|
+
return this.currentPage + 1;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { LimitPageInfo, paginateLimit };
|
|
65
|
+
|
|
56
66
|
//# 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 {\n type ContextWithEm,\n type PaginationFilter,\n type PaginationQuery,\n countQuery,\n defaultLimit,\n queryEntities,\n} 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 resolver, preserving the entity query's ordering. */\nexport function paginateLimit<T extends Entity>(\n ctx: ContextWithEm,\n query: PaginationQuery<T>,\n args: Omit<LimitArgs<T>, \"filter\">,\n): Promise<{ entities: T[]; pageInfo: LimitPageInfo<T> }>;\nexport 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> }>;\nexport async function paginateLimit<T extends Entity, F extends object = PaginationFilter<T>>(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T> | PaginationQuery<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 =\n typeof type === \"function\"\n ? await ctx.em.findGql(type, filter, { limit, offset })\n : await queryEntities<T>(ctx, { ...type, 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> | PaginationQuery<T>;\n\n constructor(\n ctx: ContextWithEm,\n type: MaybeAbstractEntityConstructor<T> | PaginationQuery<T>,\n filter: PaginationFilter<T>,\n page: Page,\n ) {\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 ??=\n typeof this.#type === \"function\"\n ? this.#ctx.em.findCount(this.#type, this.#filter)\n : countQuery(this.#ctx, this.#type));\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":";;;AA6BA,eAAsB,cACpB,KACA,MACA,MACwD;CACxD,MAAM,QAAQ,KAAK,SAAA;CACnB,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,SAAU,KAAK,UAAU,CAAC;CAKhC,OAAO;EAAE,UAHP,OAAO,SAAS,aACZ,MAAM,IAAI,GAAG,QAAQ,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC,IACpD,MAAM,cAAiB,KAAK;GAAE,GAAG;GAAM;GAAO;EAAO,CAAC;EACzC,UAAU,IAAI,cAAc,KAAK,MAAM,QAAQ;GAAE;GAAO;EAAO,CAAC;CAAE;AACvF;;AAGA,IAAa,gBAAb,MAAsD;CACpD;CACA;CACA;CACA;CACA;CAEA,YACE,KACA,MACA,QACA,MACA;EACA,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,uBACX,OAAO,KAAKJ,UAAU,aAClB,KAAKD,KAAK,GAAG,UAAU,KAAKC,OAAO,KAAKC,OAAO,IAC/C,WAAW,KAAKF,MAAM,KAAKC,KAAK;CACxC;CAEA,IAAI,WAAwC;EAC1C,OAAO,KAAKK,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"}
|