@geekmidas/db 10.0.0-alpha.98 → 10.0.0
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/CHANGELOG.md +67 -0
- package/README.md +0 -17
- package/dist/kysely/pagination.cjs +9 -8
- package/dist/kysely/pagination.cjs.map +1 -1
- package/dist/kysely/pagination.d.cts +14 -4
- package/dist/kysely/pagination.d.cts.map +1 -1
- package/dist/kysely/pagination.d.mts +14 -4
- package/dist/kysely/pagination.d.mts.map +1 -1
- package/dist/kysely/pagination.mjs +10 -7
- package/dist/kysely/pagination.mjs.map +1 -1
- package/dist/kysely-8WPSKCZG.cjs +17 -0
- package/dist/kysely-8WPSKCZG.cjs.map +1 -0
- package/dist/kysely-D3eeuId4.d.cts +13 -0
- package/dist/kysely-D3eeuId4.d.cts.map +1 -0
- package/dist/kysely-Dm1w5gAY.d.mts +13 -0
- package/dist/kysely-Dm1w5gAY.d.mts.map +1 -0
- package/dist/kysely-DmfA94RY.mjs +11 -0
- package/dist/kysely-DmfA94RY.mjs.map +1 -0
- package/dist/kysely.cjs +2 -11
- package/dist/kysely.d.cts +2 -9
- package/dist/kysely.d.mts +2 -9
- package/dist/kysely.mjs +2 -10
- package/dist/objection/pagination.cjs +7 -7
- package/dist/objection/pagination.cjs.map +1 -1
- package/dist/objection/pagination.d.cts +14 -4
- package/dist/objection/pagination.d.cts.map +1 -1
- package/dist/objection/pagination.d.mts +14 -4
- package/dist/objection/pagination.d.mts.map +1 -1
- package/dist/objection/pagination.mjs +8 -6
- package/dist/objection/pagination.mjs.map +1 -1
- package/dist/{pagination-CrU89125.d.cts → pagination-BAFX7C1I.d.cts} +4 -14
- package/dist/pagination-BAFX7C1I.d.cts.map +1 -0
- package/dist/pagination-BDLa7Yb_.mjs +37 -0
- package/dist/pagination-BDLa7Yb_.mjs.map +1 -0
- package/dist/pagination-Bdoa4PVj.cjs +55 -0
- package/dist/pagination-Bdoa4PVj.cjs.map +1 -0
- package/dist/{pagination-CrU89125.d.mts → pagination-BziGl-B8.d.mts} +4 -14
- package/dist/pagination-BziGl-B8.d.mts.map +1 -0
- package/dist/pagination.cjs +4 -55
- package/dist/pagination.d.cts +2 -2
- package/dist/pagination.d.mts +2 -2
- package/dist/pagination.mjs +2 -51
- package/dist/rls.cjs +29 -5
- package/dist/rls.cjs.map +1 -1
- package/dist/rls.d.cts +10 -6
- package/dist/rls.d.cts.map +1 -1
- package/dist/rls.d.mts +10 -6
- package/dist/rls.d.mts.map +1 -1
- package/dist/rls.mjs +5 -3
- package/dist/rls.mjs.map +1 -1
- package/package.json +9 -53
- package/src/__tests__/kysely.integration.spec.ts +741 -0
- package/src/__tests__/kysely.spec.ts +394 -0
- package/src/__tests__/rls.spec.ts +716 -0
- package/src/kysely/__tests__/pagination.integration.spec.ts +341 -0
- package/src/kysely/pagination.ts +113 -0
- package/src/kysely.ts +33 -0
- package/src/objection/__tests__/pagination.integration.spec.ts +291 -0
- package/src/objection/pagination.ts +98 -0
- package/src/pagination.ts +49 -0
- package/src/rls.ts +90 -0
- package/tsconfig.json +9 -0
- package/dist/errors.cjs +0 -73
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -51
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts +0 -51
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs +0 -69
- package/dist/errors.mjs.map +0 -1
- package/dist/introspect/DataBrowser.cjs +0 -117
- package/dist/introspect/DataBrowser.cjs.map +0 -1
- package/dist/introspect/DataBrowser.d.cts +0 -51
- package/dist/introspect/DataBrowser.d.cts.map +0 -1
- package/dist/introspect/DataBrowser.d.mts +0 -51
- package/dist/introspect/DataBrowser.d.mts.map +0 -1
- package/dist/introspect/DataBrowser.mjs +0 -116
- package/dist/introspect/DataBrowser.mjs.map +0 -1
- package/dist/introspect/errors.cjs +0 -48
- package/dist/introspect/errors.cjs.map +0 -1
- package/dist/introspect/errors.d.cts +0 -27
- package/dist/introspect/errors.d.cts.map +0 -1
- package/dist/introspect/errors.d.mts +0 -27
- package/dist/introspect/errors.d.mts.map +0 -1
- package/dist/introspect/errors.mjs +0 -45
- package/dist/introspect/errors.mjs.map +0 -1
- package/dist/introspect/filtering.cjs +0 -101
- package/dist/introspect/filtering.cjs.map +0 -1
- package/dist/introspect/filtering.d.cts +0 -29
- package/dist/introspect/filtering.d.cts.map +0 -1
- package/dist/introspect/filtering.d.mts +0 -29
- package/dist/introspect/filtering.d.mts.map +0 -1
- package/dist/introspect/filtering.mjs +0 -98
- package/dist/introspect/filtering.mjs.map +0 -1
- package/dist/introspect/handler.cjs +0 -159
- package/dist/introspect/handler.cjs.map +0 -1
- package/dist/introspect/handler.d.cts +0 -43
- package/dist/introspect/handler.d.cts.map +0 -1
- package/dist/introspect/handler.d.mts +0 -43
- package/dist/introspect/handler.d.mts.map +0 -1
- package/dist/introspect/handler.mjs +0 -158
- package/dist/introspect/handler.mjs.map +0 -1
- package/dist/introspect/index.cjs +0 -22
- package/dist/introspect/index.d.cts +0 -8
- package/dist/introspect/index.d.mts +0 -8
- package/dist/introspect/index.mjs +0 -8
- package/dist/introspect/introspection.cjs +0 -149
- package/dist/introspect/introspection.cjs.map +0 -1
- package/dist/introspect/introspection.d.cts +0 -25
- package/dist/introspect/introspection.d.cts.map +0 -1
- package/dist/introspect/introspection.d.mts +0 -25
- package/dist/introspect/introspection.d.mts.map +0 -1
- package/dist/introspect/introspection.mjs +0 -146
- package/dist/introspect/introspection.mjs.map +0 -1
- package/dist/introspect/types.cjs +0 -24
- package/dist/introspect/types.cjs.map +0 -1
- package/dist/introspect/types.d.cts +0 -113
- package/dist/introspect/types.d.cts.map +0 -1
- package/dist/introspect/types.d.mts +0 -113
- package/dist/introspect/types.d.mts.map +0 -1
- package/dist/introspect/types.mjs +0 -23
- package/dist/introspect/types.mjs.map +0 -1
- package/dist/kysely.cjs.map +0 -1
- package/dist/kysely.d.cts.map +0 -1
- package/dist/kysely.d.mts.map +0 -1
- package/dist/kysely.mjs.map +0 -1
- package/dist/pagination-CrU89125.d.cts.map +0 -1
- package/dist/pagination-CrU89125.d.mts.map +0 -1
- package/dist/pagination.cjs.map +0 -1
- package/dist/pagination.mjs.map +0 -1
- package/dist/pg/roles.cjs +0 -177
- package/dist/pg/roles.cjs.map +0 -1
- package/dist/pg/roles.d.cts +0 -90
- package/dist/pg/roles.d.cts.map +0 -1
- package/dist/pg/roles.d.mts +0 -90
- package/dist/pg/roles.d.mts.map +0 -1
- package/dist/pg/roles.mjs +0 -173
- package/dist/pg/roles.mjs.map +0 -1
- package/dist/pg/url.cjs +0 -48
- package/dist/pg/url.cjs.map +0 -1
- package/dist/pg/url.d.cts +0 -45
- package/dist/pg/url.d.cts.map +0 -1
- package/dist/pg/url.d.mts +0 -45
- package/dist/pg/url.d.mts.map +0 -1
- package/dist/pg/url.mjs +0 -47
- package/dist/pg/url.mjs.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @geekmidas/db
|
|
2
|
+
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
## 9.0.2
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
10
|
+
|
|
11
|
+
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
12
|
+
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
13
|
+
backwards; this release takes the whole set to 9.0.2 together.
|
|
14
|
+
|
|
15
|
+
Independent versions made "which version of the docs applies to me"
|
|
16
|
+
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
17
|
+
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
18
|
+
the current paradigm while the constructs rework is developed against it.
|
|
19
|
+
|
|
20
|
+
Every release now publishes every package, and a major anywhere is a major
|
|
21
|
+
everywhere. Peer ranges get simpler in return.
|
|
22
|
+
|
|
23
|
+
## 1.1.1
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
28
|
+
registry. The previous release only published the four packages that had
|
|
29
|
+
version bumps; the remaining packages failed with "cannot publish over the
|
|
30
|
+
previously published versions" because their versions were unchanged.
|
|
31
|
+
|
|
32
|
+
## 1.1.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- [#9](https://github.com/geekmidas/toolbox/pull/9) [`e31a60a`](https://github.com/geekmidas/toolbox/commit/e31a60a971366180a0e7bec6e7da56d8f36aa21f) Thanks [@geekmidas](https://github.com/geekmidas)! - Support kysely 0.29.
|
|
37
|
+
|
|
38
|
+
kysely 0.29 moved `Migrator` and `FileMigrationProvider` from the root barrel
|
|
39
|
+
(`'kysely'`) to the `'kysely/migration'` subpath. `@geekmidas/testkit`'s
|
|
40
|
+
`PostgresKyselyMigrator` now imports `Migrator` from `'kysely/migration'` and
|
|
41
|
+
its kysely peer becomes `~0.29.4` — consumers must be on kysely 0.29+.
|
|
42
|
+
|
|
43
|
+
The library packages that only declare a kysely _peer_ (`db`, `audit`, `studio`,
|
|
44
|
+
`telescope`) don't touch the moved symbols, so their peer range is _widened_ to
|
|
45
|
+
`>=0.28.2 <0.30.0` — they now support both 0.28 and 0.29 (non-breaking).
|
|
46
|
+
|
|
47
|
+
`@geekmidas/cli`'s scaffolded `test/globalSetup.ts` template now imports
|
|
48
|
+
`FileMigrationProvider` from `'kysely/migration'` so generated projects work on
|
|
49
|
+
kysely 0.29.
|
|
50
|
+
|
|
51
|
+
## 1.0.2
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
56
|
+
|
|
57
|
+
## 1.0.1
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- ✨ [`ac041cc`](https://github.com/geekmidas/toolbox/commit/ac041cc459e87107ffb4e508e85c04c3079bf040) Thanks [@geekmidas](https://github.com/geekmidas)! - Add objection pagination and fix secret loading for server apps
|
|
62
|
+
|
|
63
|
+
## 1.0.0
|
|
64
|
+
|
|
65
|
+
### Major Changes
|
|
66
|
+
|
|
67
|
+
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@ Database utilities for Kysely with flexible transaction management. Provides hel
|
|
|
9
9
|
- ✅ **Type-Safe**: Full TypeScript support with generic database schemas
|
|
10
10
|
- ✅ **Connection Abstraction**: Single helper for all database connection types
|
|
11
11
|
- ✅ **Zero Dependencies**: Only peer dependency on Kysely
|
|
12
|
-
- ✅ **Introspection** (`@geekmidas/db/introspect`): schemas, tables and rows as functions and a read-only JSON API
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
15
14
|
|
|
@@ -71,22 +70,6 @@ async function createUserWithPost(
|
|
|
71
70
|
}
|
|
72
71
|
```
|
|
73
72
|
|
|
74
|
-
## Introspection
|
|
75
|
-
|
|
76
|
-
`@geekmidas/db/introspect` reads a Postgres database's structure and pages
|
|
77
|
-
through its rows, read-only — as functions, and as a fetch-style JSON handler
|
|
78
|
-
with no HTTP framework behind it. `gkm dev` serves it at `/__gkm/db`.
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { createIntrospectionHandler } from '@geekmidas/db/introspect';
|
|
82
|
-
|
|
83
|
-
const handler = createIntrospectionHandler({ db, basePath: '/__db' });
|
|
84
|
-
app.all('/__db/*', (c) => handler(c.req.raw));
|
|
85
|
-
// GET /__db/schemas, /__db/tables, /__db/tables/users/rows?pageSize=20
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
It returns every row to whoever can reach it, so mount it only in development.
|
|
89
|
-
|
|
90
73
|
## API Reference
|
|
91
74
|
|
|
92
75
|
### `withTransaction`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const require_pagination = require('../pagination-Bdoa4PVj.cjs');
|
|
2
|
+
|
|
3
3
|
//#region src/kysely/pagination.ts
|
|
4
4
|
/**
|
|
5
5
|
* Generic paginated search function that handles:
|
|
@@ -24,11 +24,12 @@ const require_pagination = require("../pagination.cjs");
|
|
|
24
24
|
* });
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection =
|
|
28
|
-
const
|
|
27
|
+
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = require_pagination.Direction.Asc }) {
|
|
28
|
+
const countResult = await query.clearSelect().clearOrderBy().select((eb) => eb.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
29
|
+
const count = countResult.count;
|
|
29
30
|
let paginatedQuery = query;
|
|
30
31
|
if (cursor) {
|
|
31
|
-
const operator = cursorDirection ===
|
|
32
|
+
const operator = cursorDirection === require_pagination.Direction.Asc ? ">" : "<";
|
|
32
33
|
paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
|
|
33
34
|
}
|
|
34
35
|
const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1).execute();
|
|
@@ -37,8 +38,9 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
37
38
|
const lastRow = rows[rows.length - 1];
|
|
38
39
|
const nextCursor = hasMore && lastRow ? String(lastRow[cursorField]) : void 0;
|
|
39
40
|
const mapper = mapRow ?? ((row) => row);
|
|
41
|
+
const items = await Promise.all(rows.map(mapper));
|
|
40
42
|
return {
|
|
41
|
-
items
|
|
43
|
+
items,
|
|
42
44
|
pagination: {
|
|
43
45
|
total: Number(count),
|
|
44
46
|
hasMore,
|
|
@@ -46,11 +48,10 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
46
48
|
}
|
|
47
49
|
};
|
|
48
50
|
}
|
|
51
|
+
|
|
49
52
|
//#endregion
|
|
50
53
|
exports.Direction = require_pagination.Direction;
|
|
51
|
-
exports.InvalidCursor = require_pagination.InvalidCursor;
|
|
52
54
|
exports.decodeCursor = require_pagination.decodeCursor;
|
|
53
55
|
exports.encodeCursor = require_pagination.encodeCursor;
|
|
54
56
|
exports.paginatedSearch = paginatedSearch;
|
|
55
|
-
|
|
56
57
|
//# sourceMappingURL=pagination.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.cjs","names":[],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\
|
|
1
|
+
{"version":3,"file":"pagination.cjs","names":["Direction","row: TRow"],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport { Direction, decodeCursor, encodeCursor, type PaginationResult };\n\n/**\n * Options for paginated search.\n */\nexport interface PaginatedSearchOptions<\n\tTRow,\n\tTMapRow extends (row: TRow) => unknown = (row: TRow) => TRow,\n> {\n\t/** The base Kysely query to paginate */\n\tquery: SelectQueryBuilder<any, any, TRow>;\n\t/** Cursor value for pagination (value of cursorField from previous page) */\n\tcursor?: string;\n\t/** Maximum number of items per page (default: 20) */\n\tlimit?: number;\n\t/** Function to transform each row to the output format (default: identity) */\n\tmapRow?: TMapRow;\n\t/** Field to use for cursor pagination (default: 'id') */\n\tcursorField?: string;\n\t/** Sort direction for cursor field (default: Direction.Asc) */\n\tcursorDirection?: Direction;\n}\n\n/**\n * Generic paginated search function that handles:\n * - Total count calculation\n * - Cursor-based pagination\n * - Fetching one extra row to determine hasMore\n * - Mapping rows to output format\n *\n * @example\n * ```typescript\n * // With mapRow\n * const result = await paginatedSearch({\n * query: db.selectFrom('users').selectAll(),\n * limit: 20,\n * mapRow: (row) => ({ id: row.id, name: row.name }),\n * });\n *\n * // Without mapRow — items are the raw row type\n * const result = await paginatedSearch({\n * query: db.selectFrom('users').selectAll(),\n * limit: 20,\n * });\n * ```\n */\nexport async function paginatedSearch<\n\tTRow extends Record<string, unknown>,\n\tTMapRow extends (row: TRow) => unknown = (row: TRow) => TRow,\n>({\n\tquery,\n\tcursor,\n\tlimit = 20,\n\tmapRow,\n\tcursorField = 'id',\n\tcursorDirection = Direction.Asc,\n}: PaginatedSearchOptions<TRow, TMapRow>): Promise<\n\tPaginationResult<Awaited<ReturnType<TMapRow>>>\n> {\n\t// Get total count (without cursor)\n\tconst countResult = await query\n\t\t.clearSelect()\n\t\t.clearOrderBy()\n\t\t.select((eb) => eb.fn.countAll().as('count'))\n\t\t.executeTakeFirstOrThrow();\n\n\tconst count = countResult.count;\n\n\t// Apply cursor if provided\n\tlet paginatedQuery = query;\n\tif (cursor) {\n\t\tconst operator = cursorDirection === Direction.Asc ? '>' : '<';\n\t\tpaginatedQuery = paginatedQuery.where(\n\t\t\tcursorField as any,\n\t\t\toperator,\n\t\t\tcursor,\n\t\t) as typeof query;\n\t}\n\n\t// Fetch one extra to determine if there are more results\n\tconst data = await paginatedQuery\n\t\t.orderBy(cursorField as any, cursorDirection)\n\t\t.limit(limit + 1)\n\t\t.execute();\n\n\tconst hasMore = data.length > limit;\n\tconst rows = hasMore ? data.slice(0, limit) : data;\n\tconst lastRow = rows[rows.length - 1];\n\tconst nextCursor =\n\t\thasMore && lastRow ? String(lastRow[cursorField]) : undefined;\n\n\tconst mapper = mapRow ?? ((row: TRow) => row);\n\tconst items = (await Promise.all(rows.map(mapper))) as Awaited<\n\t\tReturnType<TMapRow>\n\t>[];\n\n\treturn {\n\t\titems,\n\t\tpagination: {\n\t\t\ttotal: Number(count),\n\t\t\thasMore,\n\t\t\tcursor: nextCursor,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAkBA,6BAAU,KACW,EAEtC;CAED,MAAM,cAAc,MAAM,MACxB,aAAa,CACb,cAAc,CACd,OAAO,CAAC,OAAO,GAAG,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,CAC5C,yBAAyB;CAE3B,MAAM,QAAQ,YAAY;CAG1B,IAAI,iBAAiB;AACrB,KAAI,QAAQ;EACX,MAAM,WAAW,oBAAoBA,6BAAU,MAAM,MAAM;AAC3D,mBAAiB,eAAe,MAC/B,aACA,UACA,OACA;CACD;CAGD,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAoB,gBAAgB,CAC5C,MAAM,QAAQ,EAAE,CAChB,SAAS;CAEX,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UAAU,OAAO,QAAQ,aAAa;CAElD,MAAM,SAAS,WAAW,CAACC,QAAc;CACzC,MAAM,QAAS,MAAM,QAAQ,IAAI,KAAK,IAAI,OAAO,CAAC;AAIlD,QAAO;EACN;EACA,YAAY;GACX,OAAO,OAAO,MAAM;GACpB;GACA,QAAQ;EACR;CACD;AACD"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-BAFX7C1I.cjs";
|
|
2
2
|
import { SelectQueryBuilder } from "kysely";
|
|
3
|
+
|
|
3
4
|
//#region src/kysely/pagination.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Options for paginated search.
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
interface PaginatedSearchOptions<TRow, TMapRow extends (row: TRow) => unknown = (row: TRow) => TRow> {
|
|
8
10
|
/** The base Kysely query to paginate */
|
|
9
11
|
query: SelectQueryBuilder<any, any, TRow>;
|
|
10
12
|
/** Cursor value for pagination (value of cursorField from previous page) */
|
|
@@ -41,7 +43,15 @@ export interface PaginatedSearchOptions<TRow, TMapRow extends (row: TRow) => unk
|
|
|
41
43
|
* });
|
|
42
44
|
* ```
|
|
43
45
|
*/
|
|
44
|
-
|
|
46
|
+
declare function paginatedSearch<TRow extends Record<string, unknown>, TMapRow extends (row: TRow) => unknown = (row: TRow) => TRow>({
|
|
47
|
+
query,
|
|
48
|
+
cursor,
|
|
49
|
+
limit,
|
|
50
|
+
mapRow,
|
|
51
|
+
cursorField,
|
|
52
|
+
cursorDirection
|
|
53
|
+
}: PaginatedSearchOptions<TRow, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
|
|
54
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
45
55
|
//#endregion
|
|
46
|
-
export { Direction,
|
|
56
|
+
export { Direction, PaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
|
|
47
57
|
//# sourceMappingURL=pagination.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.cts","names":[],"sources":["../../src/kysely/pagination.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"pagination.d.cts","names":[],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;;AAEuB,UAFN,sBAEM,CAAA,IAAA,EAAA,gBAAA,CAAA,GAAA,EAAA,IAAA,EAAA,GAAA,OAAA,GAAA,CAAA,GAAA,EAAyB,IAAzB,EAAA,GAAkC,IAAlC,CAAA,CAAA;EAAI;EAAyB,KAAK,EAGjD,kBAHiD,CAAA,GAAA,EAAA,GAAA,EAGpB,IAHoB,CAAA;EAAI;EAGpB,MAAjC,CAAA,EAAA,MAAA;EAAkB;EAMT,KAIE,CAAA,EAAA,MAAA;EAAS;EA0BN,MAAA,CAAA,EA9BZ,OA8BY;EAAe;EAAA,WACvB,CAAA,EAAA,MAAA;EAAM;EACO,eAAqB,CAAA,EA5B7B,SA4B6B;;;;;;;;;;;;;;;;AAQE;;;;;;;;;iBAV5B,6BACR,+CACS,yBAAyB,SAAS;;;;;;;GAQtD,uBAAuB,MAAM,WAAW,QAC1C,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-BziGl-B8.mjs";
|
|
2
2
|
import { SelectQueryBuilder } from "kysely";
|
|
3
|
+
|
|
3
4
|
//#region src/kysely/pagination.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Options for paginated search.
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
interface PaginatedSearchOptions<TRow, TMapRow extends (row: TRow) => unknown = (row: TRow) => TRow> {
|
|
8
10
|
/** The base Kysely query to paginate */
|
|
9
11
|
query: SelectQueryBuilder<any, any, TRow>;
|
|
10
12
|
/** Cursor value for pagination (value of cursorField from previous page) */
|
|
@@ -41,7 +43,15 @@ export interface PaginatedSearchOptions<TRow, TMapRow extends (row: TRow) => unk
|
|
|
41
43
|
* });
|
|
42
44
|
* ```
|
|
43
45
|
*/
|
|
44
|
-
|
|
46
|
+
declare function paginatedSearch<TRow extends Record<string, unknown>, TMapRow extends (row: TRow) => unknown = (row: TRow) => TRow>({
|
|
47
|
+
query,
|
|
48
|
+
cursor,
|
|
49
|
+
limit,
|
|
50
|
+
mapRow,
|
|
51
|
+
cursorField,
|
|
52
|
+
cursorDirection
|
|
53
|
+
}: PaginatedSearchOptions<TRow, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
|
|
54
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
45
55
|
//#endregion
|
|
46
|
-
export { Direction,
|
|
56
|
+
export { Direction, PaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
|
|
47
57
|
//# sourceMappingURL=pagination.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.mts","names":[],"sources":["../../src/kysely/pagination.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"pagination.d.mts","names":[],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;;AAEuB,UAFN,sBAEM,CAAA,IAAA,EAAA,gBAAA,CAAA,GAAA,EAAA,IAAA,EAAA,GAAA,OAAA,GAAA,CAAA,GAAA,EAAyB,IAAzB,EAAA,GAAkC,IAAlC,CAAA,CAAA;EAAI;EAAyB,KAAK,EAGjD,kBAHiD,CAAA,GAAA,EAAA,GAAA,EAGpB,IAHoB,CAAA;EAAI;EAGpB,MAAjC,CAAA,EAAA,MAAA;EAAkB;EAMT,KAIE,CAAA,EAAA,MAAA;EAAS;EA0BN,MAAA,CAAA,EA9BZ,OA8BY;EAAe;EAAA,WACvB,CAAA,EAAA,MAAA;EAAM;EACO,eAAqB,CAAA,EA5B7B,SA4B6B;;;;;;;;;;;;;;;;AAQE;;;;;;;;;iBAV5B,6BACR,+CACS,yBAAyB,SAAS;;;;;;;GAQtD,uBAAuB,MAAM,WAAW,QAC1C,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Direction,
|
|
1
|
+
import { Direction, decodeCursor, encodeCursor } from "../pagination-BDLa7Yb_.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/kysely/pagination.ts
|
|
3
4
|
/**
|
|
4
5
|
* Generic paginated search function that handles:
|
|
@@ -23,11 +24,12 @@ import { Direction, InvalidCursor, decodeCursor, encodeCursor } from "../paginat
|
|
|
23
24
|
* });
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
|
-
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection =
|
|
27
|
-
const
|
|
27
|
+
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = Direction.Asc }) {
|
|
28
|
+
const countResult = await query.clearSelect().clearOrderBy().select((eb) => eb.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
29
|
+
const count = countResult.count;
|
|
28
30
|
let paginatedQuery = query;
|
|
29
31
|
if (cursor) {
|
|
30
|
-
const operator = cursorDirection ===
|
|
32
|
+
const operator = cursorDirection === Direction.Asc ? ">" : "<";
|
|
31
33
|
paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
|
|
32
34
|
}
|
|
33
35
|
const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1).execute();
|
|
@@ -36,8 +38,9 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
36
38
|
const lastRow = rows[rows.length - 1];
|
|
37
39
|
const nextCursor = hasMore && lastRow ? String(lastRow[cursorField]) : void 0;
|
|
38
40
|
const mapper = mapRow ?? ((row) => row);
|
|
41
|
+
const items = await Promise.all(rows.map(mapper));
|
|
39
42
|
return {
|
|
40
|
-
items
|
|
43
|
+
items,
|
|
41
44
|
pagination: {
|
|
42
45
|
total: Number(count),
|
|
43
46
|
hasMore,
|
|
@@ -45,7 +48,7 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
|
-
//#endregion
|
|
49
|
-
export { Direction, InvalidCursor, decodeCursor, encodeCursor, paginatedSearch };
|
|
50
51
|
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Direction, decodeCursor, encodeCursor, paginatedSearch };
|
|
51
54
|
//# sourceMappingURL=pagination.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.mjs","names":[],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\
|
|
1
|
+
{"version":3,"file":"pagination.mjs","names":["row: TRow"],"sources":["../../src/kysely/pagination.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport { Direction, decodeCursor, encodeCursor, type PaginationResult };\n\n/**\n * Options for paginated search.\n */\nexport interface PaginatedSearchOptions<\n\tTRow,\n\tTMapRow extends (row: TRow) => unknown = (row: TRow) => TRow,\n> {\n\t/** The base Kysely query to paginate */\n\tquery: SelectQueryBuilder<any, any, TRow>;\n\t/** Cursor value for pagination (value of cursorField from previous page) */\n\tcursor?: string;\n\t/** Maximum number of items per page (default: 20) */\n\tlimit?: number;\n\t/** Function to transform each row to the output format (default: identity) */\n\tmapRow?: TMapRow;\n\t/** Field to use for cursor pagination (default: 'id') */\n\tcursorField?: string;\n\t/** Sort direction for cursor field (default: Direction.Asc) */\n\tcursorDirection?: Direction;\n}\n\n/**\n * Generic paginated search function that handles:\n * - Total count calculation\n * - Cursor-based pagination\n * - Fetching one extra row to determine hasMore\n * - Mapping rows to output format\n *\n * @example\n * ```typescript\n * // With mapRow\n * const result = await paginatedSearch({\n * query: db.selectFrom('users').selectAll(),\n * limit: 20,\n * mapRow: (row) => ({ id: row.id, name: row.name }),\n * });\n *\n * // Without mapRow — items are the raw row type\n * const result = await paginatedSearch({\n * query: db.selectFrom('users').selectAll(),\n * limit: 20,\n * });\n * ```\n */\nexport async function paginatedSearch<\n\tTRow extends Record<string, unknown>,\n\tTMapRow extends (row: TRow) => unknown = (row: TRow) => TRow,\n>({\n\tquery,\n\tcursor,\n\tlimit = 20,\n\tmapRow,\n\tcursorField = 'id',\n\tcursorDirection = Direction.Asc,\n}: PaginatedSearchOptions<TRow, TMapRow>): Promise<\n\tPaginationResult<Awaited<ReturnType<TMapRow>>>\n> {\n\t// Get total count (without cursor)\n\tconst countResult = await query\n\t\t.clearSelect()\n\t\t.clearOrderBy()\n\t\t.select((eb) => eb.fn.countAll().as('count'))\n\t\t.executeTakeFirstOrThrow();\n\n\tconst count = countResult.count;\n\n\t// Apply cursor if provided\n\tlet paginatedQuery = query;\n\tif (cursor) {\n\t\tconst operator = cursorDirection === Direction.Asc ? '>' : '<';\n\t\tpaginatedQuery = paginatedQuery.where(\n\t\t\tcursorField as any,\n\t\t\toperator,\n\t\t\tcursor,\n\t\t) as typeof query;\n\t}\n\n\t// Fetch one extra to determine if there are more results\n\tconst data = await paginatedQuery\n\t\t.orderBy(cursorField as any, cursorDirection)\n\t\t.limit(limit + 1)\n\t\t.execute();\n\n\tconst hasMore = data.length > limit;\n\tconst rows = hasMore ? data.slice(0, limit) : data;\n\tconst lastRow = rows[rows.length - 1];\n\tconst nextCursor =\n\t\thasMore && lastRow ? String(lastRow[cursorField]) : undefined;\n\n\tconst mapper = mapRow ?? ((row: TRow) => row);\n\tconst items = (await Promise.all(rows.map(mapper))) as Awaited<\n\t\tReturnType<TMapRow>\n\t>[];\n\n\treturn {\n\t\titems,\n\t\tpagination: {\n\t\t\ttotal: Number(count),\n\t\t\thasMore,\n\t\t\tcursor: nextCursor,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAkB,UAAU,KACW,EAEtC;CAED,MAAM,cAAc,MAAM,MACxB,aAAa,CACb,cAAc,CACd,OAAO,CAAC,OAAO,GAAG,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,CAC5C,yBAAyB;CAE3B,MAAM,QAAQ,YAAY;CAG1B,IAAI,iBAAiB;AACrB,KAAI,QAAQ;EACX,MAAM,WAAW,oBAAoB,UAAU,MAAM,MAAM;AAC3D,mBAAiB,eAAe,MAC/B,aACA,UACA,OACA;CACD;CAGD,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAoB,gBAAgB,CAC5C,MAAM,QAAQ,EAAE,CAChB,SAAS;CAEX,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UAAU,OAAO,QAAQ,aAAa;CAElD,MAAM,SAAS,WAAW,CAACA,QAAc;CACzC,MAAM,QAAS,MAAM,QAAQ,IAAI,KAAK,IAAI,OAAO,CAAC;AAIlD,QAAO;EACN;EACA,YAAY;GACX,OAAO,OAAO,MAAM;GACpB;GACA,QAAQ;EACR;CACD;AACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/kysely.ts
|
|
3
|
+
function withTransaction(db, cb, settings) {
|
|
4
|
+
if (db.isTransaction) return cb(db);
|
|
5
|
+
const builder = db.transaction();
|
|
6
|
+
if (settings?.isolationLevel) return builder.setIsolationLevel(settings.isolationLevel).execute(cb);
|
|
7
|
+
return builder.execute(cb);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
Object.defineProperty(exports, 'withTransaction', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return withTransaction;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=kysely-8WPSKCZG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-8WPSKCZG.cjs","names":["db: DatabaseConnection<DB>","cb: (trx: Transaction<DB>) => Promise<T>","settings?: TransactionSettings"],"sources":["../src/kysely.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tIsolationLevel,\n\tKysely,\n\tTransaction,\n} from 'kysely';\n\nexport interface TransactionSettings {\n\tisolationLevel?: IsolationLevel;\n}\n\nexport function withTransaction<DB, T>(\n\tdb: DatabaseConnection<DB>,\n\tcb: (trx: Transaction<DB>) => Promise<T>,\n\tsettings?: TransactionSettings,\n): Promise<T> {\n\tif (db.isTransaction) {\n\t\treturn cb(db as Transaction<DB>);\n\t}\n\n\tconst builder = db.transaction();\n\n\tif (settings?.isolationLevel) {\n\t\treturn builder.setIsolationLevel(settings.isolationLevel).execute(cb);\n\t}\n\n\treturn builder.execute(cb);\n}\n\nexport type DatabaseConnection<T> =\n\t| ControlledTransaction<T>\n\t| Kysely<T>\n\t| Transaction<T>;\n"],"mappings":";;AAWA,SAAgB,gBACfA,IACAC,IACAC,UACa;AACb,KAAI,GAAG,cACN,QAAO,GAAG,GAAsB;CAGjC,MAAM,UAAU,GAAG,aAAa;AAEhC,KAAI,UAAU,eACb,QAAO,QAAQ,kBAAkB,SAAS,eAAe,CAAC,QAAQ,GAAG;AAGtE,QAAO,QAAQ,QAAQ,GAAG;AAC1B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ControlledTransaction, IsolationLevel, Kysely, Transaction } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/kysely.d.ts
|
|
4
|
+
interface TransactionSettings {
|
|
5
|
+
isolationLevel?: IsolationLevel;
|
|
6
|
+
}
|
|
7
|
+
declare function withTransaction<DB, T>(db: DatabaseConnection<DB>, cb: (trx: Transaction<DB>) => Promise<T>, settings?: TransactionSettings): Promise<T>;
|
|
8
|
+
type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
9
|
+
//# sourceMappingURL=kysely.d.ts.map
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DatabaseConnection, TransactionSettings, withTransaction };
|
|
13
|
+
//# sourceMappingURL=kysely-D3eeuId4.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-D3eeuId4.d.cts","names":[],"sources":["../src/kysely.ts"],"sourcesContent":[],"mappings":";;;UAOiB,mBAAA;mBACC;AADlB;AAIgB,iBAAA,eAAe,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAA,EAC1B,kBAD0B,CACP,EADO,CAAA,EAAA,EAAA,EAAA,CAAA,GAAA,EAEpB,WAFoB,CAER,EAFQ,CAAA,EAAA,GAEA,OAFA,CAEQ,CAFR,CAAA,EAAA,QAAA,CAAA,EAGnB,mBAHmB,CAAA,EAI5B,OAJ4B,CAIpB,CAJoB,CAAA;AAAA,KAkBnB,kBAlBmB,CAAA,CAAA,CAAA,GAmB5B,qBAnB4B,CAmBN,CAnBM,CAAA,GAoB5B,MApB4B,CAoBrB,CApBqB,CAAA,GAqB5B,WArB4B,CAqBhB,CArBgB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ControlledTransaction, IsolationLevel, Kysely, Transaction } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/kysely.d.ts
|
|
4
|
+
interface TransactionSettings {
|
|
5
|
+
isolationLevel?: IsolationLevel;
|
|
6
|
+
}
|
|
7
|
+
declare function withTransaction<DB, T>(db: DatabaseConnection<DB>, cb: (trx: Transaction<DB>) => Promise<T>, settings?: TransactionSettings): Promise<T>;
|
|
8
|
+
type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
9
|
+
//# sourceMappingURL=kysely.d.ts.map
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DatabaseConnection, TransactionSettings, withTransaction };
|
|
13
|
+
//# sourceMappingURL=kysely-Dm1w5gAY.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-Dm1w5gAY.d.mts","names":[],"sources":["../src/kysely.ts"],"sourcesContent":[],"mappings":";;;UAOiB,mBAAA;mBACC;AADlB;AAIgB,iBAAA,eAAe,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAA,EAC1B,kBAD0B,CACP,EADO,CAAA,EAAA,EAAA,EAAA,CAAA,GAAA,EAEpB,WAFoB,CAER,EAFQ,CAAA,EAAA,GAEA,OAFA,CAEQ,CAFR,CAAA,EAAA,QAAA,CAAA,EAGnB,mBAHmB,CAAA,EAI5B,OAJ4B,CAIpB,CAJoB,CAAA;AAAA,KAkBnB,kBAlBmB,CAAA,CAAA,CAAA,GAmB5B,qBAnB4B,CAmBN,CAnBM,CAAA,GAoB5B,MApB4B,CAoBrB,CApBqB,CAAA,GAqB5B,WArB4B,CAqBhB,CArBgB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/kysely.ts
|
|
2
|
+
function withTransaction(db, cb, settings) {
|
|
3
|
+
if (db.isTransaction) return cb(db);
|
|
4
|
+
const builder = db.transaction();
|
|
5
|
+
if (settings?.isolationLevel) return builder.setIsolationLevel(settings.isolationLevel).execute(cb);
|
|
6
|
+
return builder.execute(cb);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { withTransaction };
|
|
11
|
+
//# sourceMappingURL=kysely-DmfA94RY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-DmfA94RY.mjs","names":["db: DatabaseConnection<DB>","cb: (trx: Transaction<DB>) => Promise<T>","settings?: TransactionSettings"],"sources":["../src/kysely.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tIsolationLevel,\n\tKysely,\n\tTransaction,\n} from 'kysely';\n\nexport interface TransactionSettings {\n\tisolationLevel?: IsolationLevel;\n}\n\nexport function withTransaction<DB, T>(\n\tdb: DatabaseConnection<DB>,\n\tcb: (trx: Transaction<DB>) => Promise<T>,\n\tsettings?: TransactionSettings,\n): Promise<T> {\n\tif (db.isTransaction) {\n\t\treturn cb(db as Transaction<DB>);\n\t}\n\n\tconst builder = db.transaction();\n\n\tif (settings?.isolationLevel) {\n\t\treturn builder.setIsolationLevel(settings.isolationLevel).execute(cb);\n\t}\n\n\treturn builder.execute(cb);\n}\n\nexport type DatabaseConnection<T> =\n\t| ControlledTransaction<T>\n\t| Kysely<T>\n\t| Transaction<T>;\n"],"mappings":";AAWA,SAAgB,gBACfA,IACAC,IACAC,UACa;AACb,KAAI,GAAG,cACN,QAAO,GAAG,GAAsB;CAGjC,MAAM,UAAU,GAAG,aAAa;AAEhC,KAAI,UAAU,eACb,QAAO,QAAQ,kBAAkB,SAAS,eAAe,CAAC,QAAQ,GAAG;AAGtE,QAAO,QAAQ,QAAQ,GAAG;AAC1B"}
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/kysely.ts
|
|
3
|
-
function withTransaction(db, cb, settings) {
|
|
4
|
-
if (db.isTransaction) return cb(db);
|
|
5
|
-
const builder = db.transaction();
|
|
6
|
-
if (settings?.isolationLevel) return builder.setIsolationLevel(settings.isolationLevel).execute(cb);
|
|
7
|
-
return builder.execute(cb);
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
exports.withTransaction = withTransaction;
|
|
1
|
+
const require_kysely = require('./kysely-8WPSKCZG.cjs');
|
|
11
2
|
|
|
12
|
-
|
|
3
|
+
exports.withTransaction = require_kysely.withTransaction;
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface TransactionSettings {
|
|
4
|
-
isolationLevel?: IsolationLevel;
|
|
5
|
-
}
|
|
6
|
-
export declare function withTransaction<DB, T>(db: DatabaseConnection<DB>, cb: (trx: Transaction<DB>) => Promise<T>, settings?: TransactionSettings): Promise<T>;
|
|
7
|
-
export type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
8
|
-
//#endregion
|
|
9
|
-
//# sourceMappingURL=kysely.d.cts.map
|
|
1
|
+
import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-D3eeuId4.cjs";
|
|
2
|
+
export { DatabaseConnection, TransactionSettings, withTransaction };
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface TransactionSettings {
|
|
4
|
-
isolationLevel?: IsolationLevel;
|
|
5
|
-
}
|
|
6
|
-
export declare function withTransaction<DB, T>(db: DatabaseConnection<DB>, cb: (trx: Transaction<DB>) => Promise<T>, settings?: TransactionSettings): Promise<T>;
|
|
7
|
-
export type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
8
|
-
//#endregion
|
|
9
|
-
//# sourceMappingURL=kysely.d.mts.map
|
|
1
|
+
import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-Dm1w5gAY.mjs";
|
|
2
|
+
export { DatabaseConnection, TransactionSettings, withTransaction };
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function withTransaction(db, cb, settings) {
|
|
3
|
-
if (db.isTransaction) return cb(db);
|
|
4
|
-
const builder = db.transaction();
|
|
5
|
-
if (settings?.isolationLevel) return builder.setIsolationLevel(settings.isolationLevel).execute(cb);
|
|
6
|
-
return builder.execute(cb);
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { withTransaction };
|
|
1
|
+
import { withTransaction } from "./kysely-DmfA94RY.mjs";
|
|
10
2
|
|
|
11
|
-
|
|
3
|
+
export { withTransaction };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const require_pagination = require('../pagination-Bdoa4PVj.cjs');
|
|
2
|
+
|
|
3
3
|
//#region src/objection/pagination.ts
|
|
4
4
|
/**
|
|
5
5
|
* Cursor-based paginated search for Objection.js models.
|
|
@@ -18,11 +18,11 @@ const require_pagination = require("../pagination.cjs");
|
|
|
18
18
|
* });
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection =
|
|
21
|
+
async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = require_pagination.Direction.Asc }) {
|
|
22
22
|
const total = await query.resultSize();
|
|
23
23
|
let paginatedQuery = query.clone();
|
|
24
24
|
if (cursor) {
|
|
25
|
-
const operator = cursorDirection ===
|
|
25
|
+
const operator = cursorDirection === require_pagination.Direction.Asc ? ">" : "<";
|
|
26
26
|
paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
|
|
27
27
|
}
|
|
28
28
|
const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1);
|
|
@@ -31,8 +31,9 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
31
31
|
const lastRow = rows[rows.length - 1];
|
|
32
32
|
const nextCursor = hasMore && lastRow ? String(lastRow[cursorField]) : void 0;
|
|
33
33
|
const mapper = mapRow ?? ((row) => row);
|
|
34
|
+
const items = await Promise.all(rows.map(mapper));
|
|
34
35
|
return {
|
|
35
|
-
items
|
|
36
|
+
items,
|
|
36
37
|
pagination: {
|
|
37
38
|
total,
|
|
38
39
|
hasMore,
|
|
@@ -40,11 +41,10 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
|
|
|
40
41
|
}
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
|
|
43
45
|
//#endregion
|
|
44
46
|
exports.Direction = require_pagination.Direction;
|
|
45
|
-
exports.InvalidCursor = require_pagination.InvalidCursor;
|
|
46
47
|
exports.decodeCursor = require_pagination.decodeCursor;
|
|
47
48
|
exports.encodeCursor = require_pagination.encodeCursor;
|
|
48
49
|
exports.paginatedSearch = paginatedSearch;
|
|
49
|
-
|
|
50
50
|
//# sourceMappingURL=pagination.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.cjs","names":[],"sources":["../../src/objection/pagination.ts"],"sourcesContent":["import type { Model, QueryBuilder } from 'objection';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\
|
|
1
|
+
{"version":3,"file":"pagination.cjs","names":["Direction","row: TModel"],"sources":["../../src/objection/pagination.ts"],"sourcesContent":["import type { Model, QueryBuilder } from 'objection';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport { Direction, decodeCursor, encodeCursor, type PaginationResult };\n\n/**\n * Options for paginated search with Objection.js models.\n */\nexport interface ObjectionPaginatedSearchOptions<\n\tTModel extends Model,\n\tTMapRow extends (row: TModel) => unknown = (row: TModel) => TModel,\n> {\n\t/** The Objection QueryBuilder to paginate (e.g. User.query(trx).where(...)) */\n\tquery: QueryBuilder<TModel>;\n\t/** Cursor value for pagination (value of cursorField from previous page) */\n\tcursor?: string;\n\t/** Maximum number of items per page (default: 20) */\n\tlimit?: number;\n\t/** Function to transform each row to the output format (default: identity) */\n\tmapRow?: TMapRow;\n\t/** Field to use for cursor pagination (default: 'id') */\n\tcursorField?: string;\n\t/** Sort direction for cursor field (default: Direction.Asc) */\n\tcursorDirection?: Direction;\n}\n\n/**\n * Cursor-based paginated search for Objection.js models.\n *\n * Accepts a pre-built QueryBuilder so callers can apply filters,\n * eager loading, and scopes before pagination is layered on top.\n *\n * @example\n * ```typescript\n * const result = await paginatedSearch({\n * query: User.query(trx).where('orgId', orgId).withGraphFetched('roles'),\n * cursor: previousCursor,\n * limit: 20,\n * cursorField: 'createdAt',\n * cursorDirection: Direction.Desc,\n * });\n * ```\n */\nexport async function paginatedSearch<\n\tTModel extends Model,\n\tTMapRow extends (row: TModel) => unknown = (row: TModel) => TModel,\n>({\n\tquery,\n\tcursor,\n\tlimit = 20,\n\tmapRow,\n\tcursorField = 'id',\n\tcursorDirection = Direction.Asc,\n}: ObjectionPaginatedSearchOptions<TModel, TMapRow>): Promise<\n\tPaginationResult<Awaited<ReturnType<TMapRow>>>\n> {\n\t// Get total count (without cursor filtering)\n\tconst total = await query.resultSize();\n\n\t// Apply cursor if provided\n\tlet paginatedQuery = query.clone();\n\tif (cursor) {\n\t\tconst operator = cursorDirection === Direction.Asc ? '>' : '<';\n\t\tpaginatedQuery = paginatedQuery.where(cursorField, operator, cursor);\n\t}\n\n\t// Fetch one extra to determine if there are more results\n\tconst data = await paginatedQuery\n\t\t.orderBy(cursorField, cursorDirection)\n\t\t.limit(limit + 1);\n\n\tconst hasMore = data.length > limit;\n\tconst rows = hasMore ? data.slice(0, limit) : data;\n\tconst lastRow = rows[rows.length - 1];\n\tconst nextCursor =\n\t\thasMore && lastRow\n\t\t\t? String((lastRow as Record<string, unknown>)[cursorField])\n\t\t\t: undefined;\n\n\tconst mapper = mapRow ?? ((row: TModel) => row);\n\tconst items = (await Promise.all(rows.map(mapper))) as Awaited<\n\t\tReturnType<TMapRow>\n\t>[];\n\n\treturn {\n\t\titems,\n\t\tpagination: {\n\t\t\ttotal,\n\t\t\thasMore,\n\t\t\tcursor: nextCursor,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgDA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAkBA,6BAAU,KACsB,EAEjD;CAED,MAAM,QAAQ,MAAM,MAAM,YAAY;CAGtC,IAAI,iBAAiB,MAAM,OAAO;AAClC,KAAI,QAAQ;EACX,MAAM,WAAW,oBAAoBA,6BAAU,MAAM,MAAM;AAC3D,mBAAiB,eAAe,MAAM,aAAa,UAAU,OAAO;CACpE;CAGD,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAa,gBAAgB,CACrC,MAAM,QAAQ,EAAE;CAElB,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UACR,OAAQ,QAAoC,aAAa;CAG7D,MAAM,SAAS,WAAW,CAACC,QAAgB;CAC3C,MAAM,QAAS,MAAM,QAAQ,IAAI,KAAK,IAAI,OAAO,CAAC;AAIlD,QAAO;EACN;EACA,YAAY;GACX;GACA;GACA,QAAQ;EACR;CACD;AACD"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-BAFX7C1I.cjs";
|
|
2
2
|
import { Model, QueryBuilder } from "objection";
|
|
3
|
+
|
|
3
4
|
//#region src/objection/pagination.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Options for paginated search with Objection.js models.
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
|
|
8
10
|
/** The Objection QueryBuilder to paginate (e.g. User.query(trx).where(...)) */
|
|
9
11
|
query: QueryBuilder<TModel>;
|
|
10
12
|
/** Cursor value for pagination (value of cursorField from previous page) */
|
|
@@ -35,7 +37,15 @@ export interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow e
|
|
|
35
37
|
* });
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
|
-
|
|
40
|
+
declare function paginatedSearch<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel>({
|
|
41
|
+
query,
|
|
42
|
+
cursor,
|
|
43
|
+
limit,
|
|
44
|
+
mapRow,
|
|
45
|
+
cursorField,
|
|
46
|
+
cursorDirection
|
|
47
|
+
}: ObjectionPaginatedSearchOptions<TModel, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
|
|
48
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
39
49
|
//#endregion
|
|
40
|
-
export { Direction,
|
|
50
|
+
export { Direction, ObjectionPaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
|
|
41
51
|
//# sourceMappingURL=pagination.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.cts","names":[],"sources":["../../src/objection/pagination.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"pagination.d.cts","names":[],"sources":["../../src/objection/pagination.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;;AACgB,UADC,+BACD,CAAA,eAAA,KAAA,EAAA,gBAAA,CAAA,GAAA,EACO,MADP,EAAA,GAAA,OAAA,GAAA,CAAA,GAAA,EACkC,MADlC,EAAA,GAC6C,MAD7C,CAAA,CAAA;EAAK;EACQ,KAAqB,EAG1C,YAH0C,CAG7B,MAH6B,CAAA;EAAM;EAAW,MAG9C,CAAA,EAAA,MAAA;EAAM;EAAP,KAMV,CAAA,EAAA,MAAA;EAAO;EAIW,MAAA,CAAA,EAJlB,OAIkB;EAoBN;EAAe,WAAA,CAAA,EAAA,MAAA;EAAA;EAChB,eACE,CAAA,EAtBJ,SAsBI;;;;;;;;;;;;;;;;;AAQsC;;iBAVvC,+BACN,6BACO,2BAA2B,WAAW;;;;;;;GAQ1D,gCAAgC,QAAQ,WAAW,QACrD,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-BziGl-B8.mjs";
|
|
2
2
|
import { Model, QueryBuilder } from "objection";
|
|
3
|
+
|
|
3
4
|
//#region src/objection/pagination.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Options for paginated search with Objection.js models.
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
|
|
8
10
|
/** The Objection QueryBuilder to paginate (e.g. User.query(trx).where(...)) */
|
|
9
11
|
query: QueryBuilder<TModel>;
|
|
10
12
|
/** Cursor value for pagination (value of cursorField from previous page) */
|
|
@@ -35,7 +37,15 @@ export interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow e
|
|
|
35
37
|
* });
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
|
-
|
|
40
|
+
declare function paginatedSearch<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel>({
|
|
41
|
+
query,
|
|
42
|
+
cursor,
|
|
43
|
+
limit,
|
|
44
|
+
mapRow,
|
|
45
|
+
cursorField,
|
|
46
|
+
cursorDirection
|
|
47
|
+
}: ObjectionPaginatedSearchOptions<TModel, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
|
|
48
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
39
49
|
//#endregion
|
|
40
|
-
export { Direction,
|
|
50
|
+
export { Direction, ObjectionPaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
|
|
41
51
|
//# sourceMappingURL=pagination.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.mts","names":[],"sources":["../../src/objection/pagination.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"pagination.d.mts","names":[],"sources":["../../src/objection/pagination.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;;AACgB,UADC,+BACD,CAAA,eAAA,KAAA,EAAA,gBAAA,CAAA,GAAA,EACO,MADP,EAAA,GAAA,OAAA,GAAA,CAAA,GAAA,EACkC,MADlC,EAAA,GAC6C,MAD7C,CAAA,CAAA;EAAK;EACQ,KAAqB,EAG1C,YAH0C,CAG7B,MAH6B,CAAA;EAAM;EAAW,MAG9C,CAAA,EAAA,MAAA;EAAM;EAAP,KAMV,CAAA,EAAA,MAAA;EAAO;EAIW,MAAA,CAAA,EAJlB,OAIkB;EAoBN;EAAe,WAAA,CAAA,EAAA,MAAA;EAAA;EAChB,eACE,CAAA,EAtBJ,SAsBI;;;;;;;;;;;;;;;;;AAQsC;;iBAVvC,+BACN,6BACO,2BAA2B,WAAW;;;;;;;GAQ1D,gCAAgC,QAAQ,WAAW,QACrD,iBAAiB,QAAQ,WAAW"}
|