@geekmidas/db 10.0.0-alpha.9 → 10.0.0-alpha.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.
Files changed (138) hide show
  1. package/README.md +17 -0
  2. package/dist/errors.cjs +72 -5
  3. package/dist/errors.cjs.map +1 -0
  4. package/dist/errors.d.cts +4 -6
  5. package/dist/errors.d.cts.map +1 -1
  6. package/dist/errors.d.mts +4 -6
  7. package/dist/errors.d.mts.map +1 -1
  8. package/dist/errors.mjs +68 -2
  9. package/dist/errors.mjs.map +1 -0
  10. package/dist/introspect/DataBrowser.cjs +117 -0
  11. package/dist/introspect/DataBrowser.cjs.map +1 -0
  12. package/dist/introspect/DataBrowser.d.cts +51 -0
  13. package/dist/introspect/DataBrowser.d.cts.map +1 -0
  14. package/dist/introspect/DataBrowser.d.mts +51 -0
  15. package/dist/introspect/DataBrowser.d.mts.map +1 -0
  16. package/dist/introspect/DataBrowser.mjs +116 -0
  17. package/dist/introspect/DataBrowser.mjs.map +1 -0
  18. package/dist/introspect/errors.cjs +48 -0
  19. package/dist/introspect/errors.cjs.map +1 -0
  20. package/dist/introspect/errors.d.cts +27 -0
  21. package/dist/introspect/errors.d.cts.map +1 -0
  22. package/dist/introspect/errors.d.mts +27 -0
  23. package/dist/introspect/errors.d.mts.map +1 -0
  24. package/dist/introspect/errors.mjs +45 -0
  25. package/dist/introspect/errors.mjs.map +1 -0
  26. package/dist/introspect/filtering.cjs +101 -0
  27. package/dist/introspect/filtering.cjs.map +1 -0
  28. package/dist/introspect/filtering.d.cts +29 -0
  29. package/dist/introspect/filtering.d.cts.map +1 -0
  30. package/dist/introspect/filtering.d.mts +29 -0
  31. package/dist/introspect/filtering.d.mts.map +1 -0
  32. package/dist/introspect/filtering.mjs +98 -0
  33. package/dist/introspect/filtering.mjs.map +1 -0
  34. package/dist/introspect/handler.cjs +159 -0
  35. package/dist/introspect/handler.cjs.map +1 -0
  36. package/dist/introspect/handler.d.cts +43 -0
  37. package/dist/introspect/handler.d.cts.map +1 -0
  38. package/dist/introspect/handler.d.mts +43 -0
  39. package/dist/introspect/handler.d.mts.map +1 -0
  40. package/dist/introspect/handler.mjs +158 -0
  41. package/dist/introspect/handler.mjs.map +1 -0
  42. package/dist/introspect/index.cjs +22 -0
  43. package/dist/introspect/index.d.cts +8 -0
  44. package/dist/introspect/index.d.mts +8 -0
  45. package/dist/introspect/index.mjs +8 -0
  46. package/dist/introspect/introspection.cjs +149 -0
  47. package/dist/introspect/introspection.cjs.map +1 -0
  48. package/dist/introspect/introspection.d.cts +25 -0
  49. package/dist/introspect/introspection.d.cts.map +1 -0
  50. package/dist/introspect/introspection.d.mts +25 -0
  51. package/dist/introspect/introspection.d.mts.map +1 -0
  52. package/dist/introspect/introspection.mjs +146 -0
  53. package/dist/introspect/introspection.mjs.map +1 -0
  54. package/dist/introspect/types.cjs +24 -0
  55. package/dist/introspect/types.cjs.map +1 -0
  56. package/dist/introspect/types.d.cts +113 -0
  57. package/dist/introspect/types.d.cts.map +1 -0
  58. package/dist/introspect/types.d.mts +113 -0
  59. package/dist/introspect/types.d.mts.map +1 -0
  60. package/dist/introspect/types.mjs +23 -0
  61. package/dist/introspect/types.mjs.map +1 -0
  62. package/dist/kysely/pagination.cjs +8 -9
  63. package/dist/kysely/pagination.cjs.map +1 -1
  64. package/dist/kysely/pagination.d.cts +4 -14
  65. package/dist/kysely/pagination.d.cts.map +1 -1
  66. package/dist/kysely/pagination.d.mts +4 -14
  67. package/dist/kysely/pagination.d.mts.map +1 -1
  68. package/dist/kysely/pagination.mjs +7 -10
  69. package/dist/kysely/pagination.mjs.map +1 -1
  70. package/dist/kysely.cjs +11 -2
  71. package/dist/kysely.cjs.map +1 -0
  72. package/dist/kysely.d.cts +9 -2
  73. package/dist/kysely.d.cts.map +1 -0
  74. package/dist/kysely.d.mts +9 -2
  75. package/dist/kysely.d.mts.map +1 -0
  76. package/dist/kysely.mjs +10 -2
  77. package/dist/kysely.mjs.map +1 -0
  78. package/dist/objection/pagination.cjs +7 -7
  79. package/dist/objection/pagination.cjs.map +1 -1
  80. package/dist/objection/pagination.d.cts +4 -14
  81. package/dist/objection/pagination.d.cts.map +1 -1
  82. package/dist/objection/pagination.d.mts +4 -14
  83. package/dist/objection/pagination.d.mts.map +1 -1
  84. package/dist/objection/pagination.mjs +6 -8
  85. package/dist/objection/pagination.mjs.map +1 -1
  86. package/dist/{pagination-kv-KWS-7.d.mts → pagination-CrU89125.d.cts} +14 -4
  87. package/dist/pagination-CrU89125.d.cts.map +1 -0
  88. package/dist/{pagination-BAFX7C1I.d.cts → pagination-CrU89125.d.mts} +14 -4
  89. package/dist/pagination-CrU89125.d.mts.map +1 -0
  90. package/dist/pagination.cjs +55 -4
  91. package/dist/pagination.cjs.map +1 -0
  92. package/dist/pagination.d.cts +2 -2
  93. package/dist/pagination.d.mts +2 -2
  94. package/dist/pagination.mjs +51 -2
  95. package/dist/pagination.mjs.map +1 -0
  96. package/dist/pg/roles.cjs +26 -3
  97. package/dist/pg/roles.cjs.map +1 -1
  98. package/dist/pg/roles.d.cts +16 -8
  99. package/dist/pg/roles.d.cts.map +1 -1
  100. package/dist/pg/roles.d.mts +16 -8
  101. package/dist/pg/roles.d.mts.map +1 -1
  102. package/dist/pg/roles.mjs +25 -2
  103. package/dist/pg/roles.mjs.map +1 -1
  104. package/dist/pg/url.cjs +18 -3
  105. package/dist/pg/url.cjs.map +1 -1
  106. package/dist/pg/url.d.cts +2 -4
  107. package/dist/pg/url.d.cts.map +1 -1
  108. package/dist/pg/url.d.mts +2 -4
  109. package/dist/pg/url.d.mts.map +1 -1
  110. package/dist/pg/url.mjs +17 -3
  111. package/dist/pg/url.mjs.map +1 -1
  112. package/dist/rls.cjs +5 -29
  113. package/dist/rls.cjs.map +1 -1
  114. package/dist/rls.d.cts +6 -10
  115. package/dist/rls.d.cts.map +1 -1
  116. package/dist/rls.d.mts +6 -10
  117. package/dist/rls.d.mts.map +1 -1
  118. package/dist/rls.mjs +3 -5
  119. package/dist/rls.mjs.map +1 -1
  120. package/package.json +14 -3
  121. package/dist/errors-CfFCan-X.mjs +0 -69
  122. package/dist/errors-CfFCan-X.mjs.map +0 -1
  123. package/dist/errors-Cs5jlAv-.cjs +0 -93
  124. package/dist/errors-Cs5jlAv-.cjs.map +0 -1
  125. package/dist/kysely-BAedYsvn.d.mts +0 -13
  126. package/dist/kysely-BAedYsvn.d.mts.map +0 -1
  127. package/dist/kysely-Bo_Zg-D3.mjs +0 -11
  128. package/dist/kysely-Bo_Zg-D3.mjs.map +0 -1
  129. package/dist/kysely-D3eeuId4.d.cts +0 -13
  130. package/dist/kysely-D3eeuId4.d.cts.map +0 -1
  131. package/dist/kysely-LWvS2ekY.cjs +0 -17
  132. package/dist/kysely-LWvS2ekY.cjs.map +0 -1
  133. package/dist/pagination-BAFX7C1I.d.cts.map +0 -1
  134. package/dist/pagination-Bu1dqOy0.cjs +0 -55
  135. package/dist/pagination-Bu1dqOy0.cjs.map +0 -1
  136. package/dist/pagination-CQ8QHXaL.mjs +0 -37
  137. package/dist/pagination-CQ8QHXaL.mjs.map +0 -1
  138. package/dist/pagination-kv-KWS-7.d.mts.map +0 -1
@@ -1,5 +1,4 @@
1
- import { Direction, decodeCursor, encodeCursor } from "../pagination-CQ8QHXaL.mjs";
2
-
1
+ import { Direction, InvalidCursor, decodeCursor, encodeCursor } from "../pagination.mjs";
3
2
  //#region src/kysely/pagination.ts
4
3
  /**
5
4
  * Generic paginated search function that handles:
@@ -24,12 +23,11 @@ import { Direction, decodeCursor, encodeCursor } from "../pagination-CQ8QHXaL.mj
24
23
  * });
25
24
  * ```
26
25
  */
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;
26
+ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = "asc" }) {
27
+ const count = (await query.clearSelect().clearOrderBy().select((eb) => eb.fn.countAll().as("count")).executeTakeFirstOrThrow()).count;
30
28
  let paginatedQuery = query;
31
29
  if (cursor) {
32
- const operator = cursorDirection === Direction.Asc ? ">" : "<";
30
+ const operator = cursorDirection === "asc" ? ">" : "<";
33
31
  paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
34
32
  }
35
33
  const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1).execute();
@@ -38,9 +36,8 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
38
36
  const lastRow = rows[rows.length - 1];
39
37
  const nextCursor = hasMore && lastRow ? String(lastRow[cursorField]) : void 0;
40
38
  const mapper = mapRow ?? ((row) => row);
41
- const items = await Promise.all(rows.map(mapper));
42
39
  return {
43
- items,
40
+ items: await Promise.all(rows.map(mapper)),
44
41
  pagination: {
45
42
  total: Number(count),
46
43
  hasMore,
@@ -48,7 +45,7 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
48
45
  }
49
46
  };
50
47
  }
51
-
52
48
  //#endregion
53
- export { Direction, decodeCursor, encodeCursor, paginatedSearch };
49
+ export { Direction, InvalidCursor, decodeCursor, encodeCursor, paginatedSearch };
50
+
54
51
  //# sourceMappingURL=pagination.mjs.map
@@ -1 +1 @@
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"}
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\tInvalidCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\tInvalidCursor,\n\ttype PaginationResult,\n};\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":";;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAA,SAGC;CAQD,MAAM,SAAQ,MANY,MACxB,YAAY,CAAC,CACb,aAAa,CAAC,CACd,QAAQ,OAAO,GAAG,GAAG,SAAS,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAC5C,wBAAwB,EAAA,CAEA;CAG1B,IAAI,iBAAiB;CACrB,IAAI,QAAQ;EACX,MAAM,WAAW,oBAAA,QAAoC,MAAM;EAC3D,iBAAiB,eAAe,MAC/B,aACA,UACA,MACD;CACD;CAGA,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAoB,eAAe,CAAC,CAC5C,MAAM,QAAQ,CAAC,CAAC,CAChB,QAAQ;CAEV,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,KAAK,IAAI;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UAAU,OAAO,QAAQ,YAAY,IAAI,KAAA;CAErD,MAAM,SAAS,YAAY,QAAc;CAKzC,OAAO;EACN,OAAA,MALoB,QAAQ,IAAI,KAAK,IAAI,MAAM,CAAC;EAMhD,YAAY;GACX,OAAO,OAAO,KAAK;GACnB;GACA,QAAQ;EACT;CACD;AACD"}
package/dist/kysely.cjs CHANGED
@@ -1,3 +1,12 @@
1
- const require_kysely = require('./kysely-LWvS2ekY.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
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;
2
11
 
3
- exports.withTransaction = require_kysely.withTransaction;
12
+ //# sourceMappingURL=kysely.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kysely.cjs","names":[],"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,gBACf,IACA,IACA,UACa;CACb,IAAI,GAAG,eACN,OAAO,GAAG,EAAqB;CAGhC,MAAM,UAAU,GAAG,YAAY;CAE/B,IAAI,UAAU,gBACb,OAAO,QAAQ,kBAAkB,SAAS,cAAc,CAAC,CAAC,QAAQ,EAAE;CAGrE,OAAO,QAAQ,QAAQ,EAAE;AAC1B"}
package/dist/kysely.d.cts CHANGED
@@ -1,2 +1,9 @@
1
- import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-D3eeuId4.cjs";
2
- export { DatabaseConnection, TransactionSettings, withTransaction };
1
+ import { ControlledTransaction, IsolationLevel, Kysely, Transaction } from "kysely";
2
+ //#region src/kysely.d.ts
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kysely.d.cts","names":[],"sources":["../src/kysely.ts"],"mappings":";;iBAOiB;EAChB,iBAAiB;;wBAGF,gBAAgB,IAAI,GACnC,IAAI,mBAAmB,KACvB,KAAK,KAAK,YAAY,QAAQ,QAAQ,IACtC,WAAW,sBACT,QAAQ;YAcC,mBAAmB,KAC5B,sBAAsB,KACtB,OAAO,KACP,YAAY"}
package/dist/kysely.d.mts CHANGED
@@ -1,2 +1,9 @@
1
- import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-BAedYsvn.mjs";
2
- export { DatabaseConnection, TransactionSettings, withTransaction };
1
+ import { ControlledTransaction, IsolationLevel, Kysely, Transaction } from "kysely";
2
+ //#region src/kysely.d.ts
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kysely.d.mts","names":[],"sources":["../src/kysely.ts"],"mappings":";;iBAOiB;EAChB,iBAAiB;;wBAGF,gBAAgB,IAAI,GACnC,IAAI,mBAAmB,KACvB,KAAK,KAAK,YAAY,QAAQ,QAAQ,IACtC,WAAW,sBACT,QAAQ;YAcC,mBAAmB,KAC5B,sBAAsB,KACtB,OAAO,KACP,YAAY"}
package/dist/kysely.mjs CHANGED
@@ -1,3 +1,11 @@
1
- import { withTransaction } from "./kysely-Bo_Zg-D3.mjs";
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
+ //#endregion
9
+ export { withTransaction };
2
10
 
3
- export { withTransaction };
11
+ //# sourceMappingURL=kysely.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kysely.mjs","names":[],"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,gBACf,IACA,IACA,UACa;CACb,IAAI,GAAG,eACN,OAAO,GAAG,EAAqB;CAGhC,MAAM,UAAU,GAAG,YAAY;CAE/B,IAAI,UAAU,gBACb,OAAO,QAAQ,kBAAkB,SAAS,cAAc,CAAC,CAAC,QAAQ,EAAE;CAGrE,OAAO,QAAQ,QAAQ,EAAE;AAC1B"}
@@ -1,5 +1,5 @@
1
- const require_pagination = require('../pagination-Bu1dqOy0.cjs');
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_pagination = require("../pagination.cjs");
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-Bu1dqOy0.cjs');
18
18
  * });
19
19
  * ```
20
20
  */
21
- async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = require_pagination.Direction.Asc }) {
21
+ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = "asc" }) {
22
22
  const total = await query.resultSize();
23
23
  let paginatedQuery = query.clone();
24
24
  if (cursor) {
25
- const operator = cursorDirection === require_pagination.Direction.Asc ? ">" : "<";
25
+ const operator = cursorDirection === "asc" ? ">" : "<";
26
26
  paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
27
27
  }
28
28
  const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1);
@@ -31,9 +31,8 @@ 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));
35
34
  return {
36
- items,
35
+ items: await Promise.all(rows.map(mapper)),
37
36
  pagination: {
38
37
  total,
39
38
  hasMore,
@@ -41,10 +40,11 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
41
40
  }
42
41
  };
43
42
  }
44
-
45
43
  //#endregion
46
44
  exports.Direction = require_pagination.Direction;
45
+ exports.InvalidCursor = require_pagination.InvalidCursor;
47
46
  exports.decodeCursor = require_pagination.decodeCursor;
48
47
  exports.encodeCursor = require_pagination.encodeCursor;
49
48
  exports.paginatedSearch = paginatedSearch;
49
+
50
50
  //# sourceMappingURL=pagination.cjs.map
@@ -1 +1 @@
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
+ {"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\tInvalidCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\tInvalidCursor,\n\ttype PaginationResult,\n};\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":";;;;;;;;;;;;;;;;;;;;AAuDA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAA,SAGC;CAED,MAAM,QAAQ,MAAM,MAAM,WAAW;CAGrC,IAAI,iBAAiB,MAAM,MAAM;CACjC,IAAI,QAAQ;EACX,MAAM,WAAW,oBAAA,QAAoC,MAAM;EAC3D,iBAAiB,eAAe,MAAM,aAAa,UAAU,MAAM;CACpE;CAGA,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAa,eAAe,CAAC,CACrC,MAAM,QAAQ,CAAC;CAEjB,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,KAAK,IAAI;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UACR,OAAQ,QAAoC,YAAY,IACxD,KAAA;CAEJ,MAAM,SAAS,YAAY,QAAgB;CAK3C,OAAO;EACN,OAAA,MALoB,QAAQ,IAAI,KAAK,IAAI,MAAM,CAAC;EAMhD,YAAY;GACX;GACA;GACA,QAAQ;EACT;CACD;AACD"}
@@ -1,12 +1,10 @@
1
- import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-BAFX7C1I.cjs";
1
+ import { a as encodeCursor, i as decodeCursor, n as InvalidCursor, r as PaginationResult, t as Direction } from "../pagination-CrU89125.cjs";
2
2
  import { Model, QueryBuilder } from "objection";
3
-
4
3
  //#region src/objection/pagination.d.ts
5
-
6
4
  /**
7
5
  * Options for paginated search with Objection.js models.
8
6
  */
9
- interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
7
+ export interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
10
8
  /** The Objection QueryBuilder to paginate (e.g. User.query(trx).where(...)) */
11
9
  query: QueryBuilder<TModel>;
12
10
  /** Cursor value for pagination (value of cursorField from previous page) */
@@ -37,15 +35,7 @@ interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends
37
35
  * });
38
36
  * ```
39
37
  */
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
38
+ export declare function paginatedSearch<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel>({ query, cursor, limit, mapRow, cursorField, cursorDirection }: ObjectionPaginatedSearchOptions<TModel, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
49
39
  //#endregion
50
- export { Direction, ObjectionPaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
40
+ export { Direction, InvalidCursor, type PaginationResult, decodeCursor, encodeCursor };
51
41
  //# sourceMappingURL=pagination.d.cts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"pagination.d.cts","names":[],"sources":["../../src/objection/pagination.ts"],"mappings":";;;;;;iBAoBiB,gCAChB,eAAe,OACf,iBAAiB,KAAK,sBAAsB,KAAK,WAAW;;EAG5D,OAAO,aAAa;;EAEpB;;EAEA;;EAEA,SAAS;;EAET;;EAEA,kBAAkB;;;;;;;;;;;;;;;;;;;wBAoBG,gBACrB,eAAe,OACf,iBAAiB,KAAK,sBAAsB,KAAK,WAAW,UAE5D,OACA,QACA,OACA,QACA,aACA,mBACE,gCAAgC,QAAQ,WAAW,QACrD,iBAAiB,QAAQ,WAAW"}
@@ -1,12 +1,10 @@
1
- import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-kv-KWS-7.mjs";
1
+ import { a as encodeCursor, i as decodeCursor, n as InvalidCursor, r as PaginationResult, t as Direction } from "../pagination-CrU89125.mjs";
2
2
  import { Model, QueryBuilder } from "objection";
3
-
4
3
  //#region src/objection/pagination.d.ts
5
-
6
4
  /**
7
5
  * Options for paginated search with Objection.js models.
8
6
  */
9
- interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
7
+ export interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel> {
10
8
  /** The Objection QueryBuilder to paginate (e.g. User.query(trx).where(...)) */
11
9
  query: QueryBuilder<TModel>;
12
10
  /** Cursor value for pagination (value of cursorField from previous page) */
@@ -37,15 +35,7 @@ interface ObjectionPaginatedSearchOptions<TModel extends Model, TMapRow extends
37
35
  * });
38
36
  * ```
39
37
  */
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
38
+ export declare function paginatedSearch<TModel extends Model, TMapRow extends (row: TModel) => unknown = (row: TModel) => TModel>({ query, cursor, limit, mapRow, cursorField, cursorDirection }: ObjectionPaginatedSearchOptions<TModel, TMapRow>): Promise<PaginationResult<Awaited<ReturnType<TMapRow>>>>;
49
39
  //#endregion
50
- export { Direction, ObjectionPaginatedSearchOptions, PaginationResult, decodeCursor, encodeCursor, paginatedSearch };
40
+ export { Direction, InvalidCursor, type PaginationResult, decodeCursor, encodeCursor };
51
41
  //# sourceMappingURL=pagination.d.mts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"pagination.d.mts","names":[],"sources":["../../src/objection/pagination.ts"],"mappings":";;;;;;iBAoBiB,gCAChB,eAAe,OACf,iBAAiB,KAAK,sBAAsB,KAAK,WAAW;;EAG5D,OAAO,aAAa;;EAEpB;;EAEA;;EAEA,SAAS;;EAET;;EAEA,kBAAkB;;;;;;;;;;;;;;;;;;;wBAoBG,gBACrB,eAAe,OACf,iBAAiB,KAAK,sBAAsB,KAAK,WAAW,UAE5D,OACA,QACA,OACA,QACA,aACA,mBACE,gCAAgC,QAAQ,WAAW,QACrD,iBAAiB,QAAQ,WAAW"}
@@ -1,5 +1,4 @@
1
- import { Direction, decodeCursor, encodeCursor } from "../pagination-CQ8QHXaL.mjs";
2
-
1
+ import { Direction, InvalidCursor, decodeCursor, encodeCursor } from "../pagination.mjs";
3
2
  //#region src/objection/pagination.ts
4
3
  /**
5
4
  * Cursor-based paginated search for Objection.js models.
@@ -18,11 +17,11 @@ import { Direction, decodeCursor, encodeCursor } from "../pagination-CQ8QHXaL.mj
18
17
  * });
19
18
  * ```
20
19
  */
21
- async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = Direction.Asc }) {
20
+ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField = "id", cursorDirection = "asc" }) {
22
21
  const total = await query.resultSize();
23
22
  let paginatedQuery = query.clone();
24
23
  if (cursor) {
25
- const operator = cursorDirection === Direction.Asc ? ">" : "<";
24
+ const operator = cursorDirection === "asc" ? ">" : "<";
26
25
  paginatedQuery = paginatedQuery.where(cursorField, operator, cursor);
27
26
  }
28
27
  const data = await paginatedQuery.orderBy(cursorField, cursorDirection).limit(limit + 1);
@@ -31,9 +30,8 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
31
30
  const lastRow = rows[rows.length - 1];
32
31
  const nextCursor = hasMore && lastRow ? String(lastRow[cursorField]) : void 0;
33
32
  const mapper = mapRow ?? ((row) => row);
34
- const items = await Promise.all(rows.map(mapper));
35
33
  return {
36
- items,
34
+ items: await Promise.all(rows.map(mapper)),
37
35
  pagination: {
38
36
  total,
39
37
  hasMore,
@@ -41,7 +39,7 @@ async function paginatedSearch({ query, cursor, limit = 20, mapRow, cursorField
41
39
  }
42
40
  };
43
41
  }
44
-
45
42
  //#endregion
46
- export { Direction, decodeCursor, encodeCursor, paginatedSearch };
43
+ export { Direction, InvalidCursor, decodeCursor, encodeCursor, paginatedSearch };
44
+
47
45
  //# sourceMappingURL=pagination.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.mjs","names":["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,kBAAkB,UAAU,KACsB,EAEjD;CAED,MAAM,QAAQ,MAAM,MAAM,YAAY;CAGtC,IAAI,iBAAiB,MAAM,OAAO;AAClC,KAAI,QAAQ;EACX,MAAM,WAAW,oBAAoB,UAAU,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,CAACA,QAAgB;CAC3C,MAAM,QAAS,MAAM,QAAQ,IAAI,KAAK,IAAI,OAAO,CAAC;AAIlD,QAAO;EACN;EACA,YAAY;GACX;GACA;GACA,QAAQ;EACR;CACD;AACD"}
1
+ {"version":3,"file":"pagination.mjs","names":[],"sources":["../../src/objection/pagination.ts"],"sourcesContent":["import type { Model, QueryBuilder } from 'objection';\nimport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\tInvalidCursor,\n\ttype PaginationResult,\n} from '../pagination';\n\nexport {\n\tDirection,\n\tdecodeCursor,\n\tencodeCursor,\n\tInvalidCursor,\n\ttype PaginationResult,\n};\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":";;;;;;;;;;;;;;;;;;;AAuDA,eAAsB,gBAGpB,EACD,OACA,QACA,QAAQ,IACR,QACA,cAAc,MACd,kBAAA,SAGC;CAED,MAAM,QAAQ,MAAM,MAAM,WAAW;CAGrC,IAAI,iBAAiB,MAAM,MAAM;CACjC,IAAI,QAAQ;EACX,MAAM,WAAW,oBAAA,QAAoC,MAAM;EAC3D,iBAAiB,eAAe,MAAM,aAAa,UAAU,MAAM;CACpE;CAGA,MAAM,OAAO,MAAM,eACjB,QAAQ,aAAa,eAAe,CAAC,CACrC,MAAM,QAAQ,CAAC;CAEjB,MAAM,UAAU,KAAK,SAAS;CAC9B,MAAM,OAAO,UAAU,KAAK,MAAM,GAAG,KAAK,IAAI;CAC9C,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,aACL,WAAW,UACR,OAAQ,QAAoC,YAAY,IACxD,KAAA;CAEJ,MAAM,SAAS,YAAY,QAAgB;CAK3C,OAAO;EACN,OAAA,MALoB,QAAQ,IAAI,KAAK,IAAI,MAAM,CAAC;EAMhD,YAAY;GACX;GACA;GACA,QAAQ;EACT;CACD;AACD"}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  declare enum Direction {
6
6
  Asc = "asc",
7
- Desc = "desc",
7
+ Desc = "desc"
8
8
  }
9
9
  /**
10
10
  * Result of a paginated query.
@@ -26,7 +26,17 @@ declare function encodeCursor(value: unknown): string;
26
26
  * Decode a cursor string back to its original value.
27
27
  */
28
28
  declare function decodeCursor(cursor: string): unknown;
29
- //# sourceMappingURL=pagination.d.ts.map
29
+ /**
30
+ * A cursor that did not come from `encodeCursor`.
31
+ *
32
+ * Usually a cursor from a different page size or sort that was edited by hand,
33
+ * or truncated on its way through a URL. The fix is the same either way: start
34
+ * again from the first page.
35
+ */
36
+ declare class InvalidCursor extends Error {
37
+ readonly cursor: string;
38
+ constructor(cursor: string);
39
+ }
30
40
  //#endregion
31
- export { Direction, PaginationResult, decodeCursor, encodeCursor };
32
- //# sourceMappingURL=pagination-kv-KWS-7.d.mts.map
41
+ export { encodeCursor as a, decodeCursor as i, InvalidCursor as n, PaginationResult as r, Direction as t };
42
+ //# sourceMappingURL=pagination-CrU89125.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination-CrU89125.d.cts","names":[],"sources":["../src/pagination.ts"],"mappings":";;;;aAGY;EACX;EACA;;;;;UAMgB,iBAAiB;EACjC,OAAO;EACP;IACC;IACA;IACA;;;;;;;iBAQc,aAAa;;;;iBAWb,aAAa;;;;;;;;cAsBhB,sBAAsB;WACb;EAArB,YAAqB"}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  declare enum Direction {
6
6
  Asc = "asc",
7
- Desc = "desc",
7
+ Desc = "desc"
8
8
  }
9
9
  /**
10
10
  * Result of a paginated query.
@@ -26,7 +26,17 @@ declare function encodeCursor(value: unknown): string;
26
26
  * Decode a cursor string back to its original value.
27
27
  */
28
28
  declare function decodeCursor(cursor: string): unknown;
29
- //# sourceMappingURL=pagination.d.ts.map
29
+ /**
30
+ * A cursor that did not come from `encodeCursor`.
31
+ *
32
+ * Usually a cursor from a different page size or sort that was edited by hand,
33
+ * or truncated on its way through a URL. The fix is the same either way: start
34
+ * again from the first page.
35
+ */
36
+ declare class InvalidCursor extends Error {
37
+ readonly cursor: string;
38
+ constructor(cursor: string);
39
+ }
30
40
  //#endregion
31
- export { Direction, PaginationResult, decodeCursor, encodeCursor };
32
- //# sourceMappingURL=pagination-BAFX7C1I.d.cts.map
41
+ export { encodeCursor as a, decodeCursor as i, InvalidCursor as n, PaginationResult as r, Direction as t };
42
+ //# sourceMappingURL=pagination-CrU89125.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination-CrU89125.d.mts","names":[],"sources":["../src/pagination.ts"],"mappings":";;;;aAGY;EACX;EACA;;;;;UAMgB,iBAAiB;EACjC,OAAO;EACP;IACC;IACA;IACA;;;;;;;iBAQc,aAAa;;;;iBAWb,aAAa;;;;;;;;cAsBhB,sBAAsB;WACb;EAArB,YAAqB"}
@@ -1,5 +1,56 @@
1
- const require_pagination = require('./pagination-Bu1dqOy0.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/pagination.ts
3
+ /**
4
+ * Sort direction for cursor-based pagination.
5
+ */
6
+ let Direction = /* @__PURE__ */ function(Direction) {
7
+ Direction["Asc"] = "asc";
8
+ Direction["Desc"] = "desc";
9
+ return Direction;
10
+ }({});
11
+ /**
12
+ * Encode a cursor value for safe URL transmission.
13
+ * Supports various types: string, number, Date, etc.
14
+ */
15
+ function encodeCursor(value) {
16
+ const payload = {
17
+ v: value instanceof Date ? value.toISOString() : value,
18
+ t: value instanceof Date ? "date" : typeof value
19
+ };
20
+ return Buffer.from(JSON.stringify(payload)).toString("base64url");
21
+ }
22
+ /**
23
+ * Decode a cursor string back to its original value.
24
+ */
25
+ function decodeCursor(cursor) {
26
+ try {
27
+ const json = Buffer.from(cursor, "base64url").toString("utf-8");
28
+ const payload = JSON.parse(json);
29
+ if (payload.t === "date") return new Date(payload.v);
30
+ return payload.v;
31
+ } catch {
32
+ throw new InvalidCursor(cursor);
33
+ }
34
+ }
35
+ /**
36
+ * A cursor that did not come from `encodeCursor`.
37
+ *
38
+ * Usually a cursor from a different page size or sort that was edited by hand,
39
+ * or truncated on its way through a URL. The fix is the same either way: start
40
+ * again from the first page.
41
+ */
42
+ var InvalidCursor = class extends Error {
43
+ cursor;
44
+ constructor(cursor) {
45
+ super("This cursor was not produced by encodeCursor. Drop it and request the first page again.");
46
+ this.cursor = cursor;
47
+ this.name = "InvalidCursor";
48
+ }
49
+ };
50
+ //#endregion
51
+ exports.Direction = Direction;
52
+ exports.InvalidCursor = InvalidCursor;
53
+ exports.decodeCursor = decodeCursor;
54
+ exports.encodeCursor = encodeCursor;
2
55
 
3
- exports.Direction = require_pagination.Direction;
4
- exports.decodeCursor = require_pagination.decodeCursor;
5
- exports.encodeCursor = require_pagination.encodeCursor;
56
+ //# sourceMappingURL=pagination.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.cjs","names":[],"sources":["../src/pagination.ts"],"sourcesContent":["/**\n * Sort direction for cursor-based pagination.\n */\nexport enum Direction {\n\tAsc = 'asc',\n\tDesc = 'desc',\n}\n\n/**\n * Result of a paginated query.\n */\nexport interface PaginationResult<TItem> {\n\titems: TItem[];\n\tpagination: {\n\t\ttotal: number;\n\t\thasMore: boolean;\n\t\tcursor?: string;\n\t};\n}\n\n/**\n * Encode a cursor value for safe URL transmission.\n * Supports various types: string, number, Date, etc.\n */\nexport function encodeCursor(value: unknown): string {\n\tconst payload = {\n\t\tv: value instanceof Date ? value.toISOString() : value,\n\t\tt: value instanceof Date ? 'date' : typeof value,\n\t};\n\treturn Buffer.from(JSON.stringify(payload)).toString('base64url');\n}\n\n/**\n * Decode a cursor string back to its original value.\n */\nexport function decodeCursor(cursor: string): unknown {\n\ttry {\n\t\tconst json = Buffer.from(cursor, 'base64url').toString('utf-8');\n\t\tconst payload = JSON.parse(json);\n\n\t\tif (payload.t === 'date') {\n\t\t\treturn new Date(payload.v);\n\t\t}\n\n\t\treturn payload.v;\n\t} catch {\n\t\tthrow new InvalidCursor(cursor);\n\t}\n}\n\n/**\n * A cursor that did not come from `encodeCursor`.\n *\n * Usually a cursor from a different page size or sort that was edited by hand,\n * or truncated on its way through a URL. The fix is the same either way: start\n * again from the first page.\n */\nexport class InvalidCursor extends Error {\n\tconstructor(readonly cursor: string) {\n\t\tsuper(\n\t\t\t'This cursor was not produced by encodeCursor. Drop it and request the first page again.',\n\t\t);\n\t\tthis.name = 'InvalidCursor';\n\t}\n}\n"],"mappings":";;;;;AAGA,IAAY,YAAL,yBAAA,WAAA;CACN,UAAA,SAAA;CACA,UAAA,UAAA;;AACD,EAAA,CAAA,CAAA;;;;;AAkBA,SAAgB,aAAa,OAAwB;CACpD,MAAM,UAAU;EACf,GAAG,iBAAiB,OAAO,MAAM,YAAY,IAAI;EACjD,GAAG,iBAAiB,OAAO,SAAS,OAAO;CAC5C;CACA,OAAO,OAAO,KAAK,KAAK,UAAU,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW;AACjE;;;;AAKA,SAAgB,aAAa,QAAyB;CACrD,IAAI;EACH,MAAM,OAAO,OAAO,KAAK,QAAQ,WAAW,CAAC,CAAC,SAAS,OAAO;EAC9D,MAAM,UAAU,KAAK,MAAM,IAAI;EAE/B,IAAI,QAAQ,MAAM,QACjB,OAAO,IAAI,KAAK,QAAQ,CAAC;EAG1B,OAAO,QAAQ;CAChB,QAAQ;EACP,MAAM,IAAI,cAAc,MAAM;CAC/B;AACD;;;;;;;;AASA,IAAa,gBAAb,cAAmC,MAAM;CACnB;CAArB,YAAY,QAAyB;EACpC,MACC,yFACD;EAHoB,KAAA,SAAA;EAIpB,KAAK,OAAO;CACb;AACD"}
@@ -1,2 +1,2 @@
1
- import { Direction, PaginationResult, decodeCursor, encodeCursor } from "./pagination-BAFX7C1I.cjs";
2
- export { Direction, PaginationResult, decodeCursor, encodeCursor };
1
+ import { a as encodeCursor, i as decodeCursor, n as InvalidCursor, r as PaginationResult, t as Direction } from "./pagination-CrU89125.cjs";
2
+ export { Direction, InvalidCursor, PaginationResult, decodeCursor, encodeCursor };
@@ -1,2 +1,2 @@
1
- import { Direction, PaginationResult, decodeCursor, encodeCursor } from "./pagination-kv-KWS-7.mjs";
2
- export { Direction, PaginationResult, decodeCursor, encodeCursor };
1
+ import { a as encodeCursor, i as decodeCursor, n as InvalidCursor, r as PaginationResult, t as Direction } from "./pagination-CrU89125.mjs";
2
+ export { Direction, InvalidCursor, PaginationResult, decodeCursor, encodeCursor };
@@ -1,3 +1,52 @@
1
- import { Direction, decodeCursor, encodeCursor } from "./pagination-CQ8QHXaL.mjs";
1
+ //#region src/pagination.ts
2
+ /**
3
+ * Sort direction for cursor-based pagination.
4
+ */
5
+ let Direction = /* @__PURE__ */ function(Direction) {
6
+ Direction["Asc"] = "asc";
7
+ Direction["Desc"] = "desc";
8
+ return Direction;
9
+ }({});
10
+ /**
11
+ * Encode a cursor value for safe URL transmission.
12
+ * Supports various types: string, number, Date, etc.
13
+ */
14
+ function encodeCursor(value) {
15
+ const payload = {
16
+ v: value instanceof Date ? value.toISOString() : value,
17
+ t: value instanceof Date ? "date" : typeof value
18
+ };
19
+ return Buffer.from(JSON.stringify(payload)).toString("base64url");
20
+ }
21
+ /**
22
+ * Decode a cursor string back to its original value.
23
+ */
24
+ function decodeCursor(cursor) {
25
+ try {
26
+ const json = Buffer.from(cursor, "base64url").toString("utf-8");
27
+ const payload = JSON.parse(json);
28
+ if (payload.t === "date") return new Date(payload.v);
29
+ return payload.v;
30
+ } catch {
31
+ throw new InvalidCursor(cursor);
32
+ }
33
+ }
34
+ /**
35
+ * A cursor that did not come from `encodeCursor`.
36
+ *
37
+ * Usually a cursor from a different page size or sort that was edited by hand,
38
+ * or truncated on its way through a URL. The fix is the same either way: start
39
+ * again from the first page.
40
+ */
41
+ var InvalidCursor = class extends Error {
42
+ cursor;
43
+ constructor(cursor) {
44
+ super("This cursor was not produced by encodeCursor. Drop it and request the first page again.");
45
+ this.cursor = cursor;
46
+ this.name = "InvalidCursor";
47
+ }
48
+ };
49
+ //#endregion
50
+ export { Direction, InvalidCursor, decodeCursor, encodeCursor };
2
51
 
3
- export { Direction, decodeCursor, encodeCursor };
52
+ //# sourceMappingURL=pagination.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.mjs","names":[],"sources":["../src/pagination.ts"],"sourcesContent":["/**\n * Sort direction for cursor-based pagination.\n */\nexport enum Direction {\n\tAsc = 'asc',\n\tDesc = 'desc',\n}\n\n/**\n * Result of a paginated query.\n */\nexport interface PaginationResult<TItem> {\n\titems: TItem[];\n\tpagination: {\n\t\ttotal: number;\n\t\thasMore: boolean;\n\t\tcursor?: string;\n\t};\n}\n\n/**\n * Encode a cursor value for safe URL transmission.\n * Supports various types: string, number, Date, etc.\n */\nexport function encodeCursor(value: unknown): string {\n\tconst payload = {\n\t\tv: value instanceof Date ? value.toISOString() : value,\n\t\tt: value instanceof Date ? 'date' : typeof value,\n\t};\n\treturn Buffer.from(JSON.stringify(payload)).toString('base64url');\n}\n\n/**\n * Decode a cursor string back to its original value.\n */\nexport function decodeCursor(cursor: string): unknown {\n\ttry {\n\t\tconst json = Buffer.from(cursor, 'base64url').toString('utf-8');\n\t\tconst payload = JSON.parse(json);\n\n\t\tif (payload.t === 'date') {\n\t\t\treturn new Date(payload.v);\n\t\t}\n\n\t\treturn payload.v;\n\t} catch {\n\t\tthrow new InvalidCursor(cursor);\n\t}\n}\n\n/**\n * A cursor that did not come from `encodeCursor`.\n *\n * Usually a cursor from a different page size or sort that was edited by hand,\n * or truncated on its way through a URL. The fix is the same either way: start\n * again from the first page.\n */\nexport class InvalidCursor extends Error {\n\tconstructor(readonly cursor: string) {\n\t\tsuper(\n\t\t\t'This cursor was not produced by encodeCursor. Drop it and request the first page again.',\n\t\t);\n\t\tthis.name = 'InvalidCursor';\n\t}\n}\n"],"mappings":";;;;AAGA,IAAY,YAAL,yBAAA,WAAA;CACN,UAAA,SAAA;CACA,UAAA,UAAA;;AACD,EAAA,CAAA,CAAA;;;;;AAkBA,SAAgB,aAAa,OAAwB;CACpD,MAAM,UAAU;EACf,GAAG,iBAAiB,OAAO,MAAM,YAAY,IAAI;EACjD,GAAG,iBAAiB,OAAO,SAAS,OAAO;CAC5C;CACA,OAAO,OAAO,KAAK,KAAK,UAAU,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW;AACjE;;;;AAKA,SAAgB,aAAa,QAAyB;CACrD,IAAI;EACH,MAAM,OAAO,OAAO,KAAK,QAAQ,WAAW,CAAC,CAAC,SAAS,OAAO;EAC9D,MAAM,UAAU,KAAK,MAAM,IAAI;EAE/B,IAAI,QAAQ,MAAM,QACjB,OAAO,IAAI,KAAK,QAAQ,CAAC;EAG1B,OAAO,QAAQ;CAChB,QAAQ;EACP,MAAM,IAAI,cAAc,MAAM;CAC/B;AACD;;;;;;;;AASA,IAAa,gBAAb,cAAmC,MAAM;CACnB;CAArB,YAAY,QAAyB;EACpC,MACC,yFACD;EAHoB,KAAA,SAAA;EAIpB,KAAK,OAAO;CACb;AACD"}