@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.
Files changed (146) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +0 -17
  3. package/dist/kysely/pagination.cjs +9 -8
  4. package/dist/kysely/pagination.cjs.map +1 -1
  5. package/dist/kysely/pagination.d.cts +14 -4
  6. package/dist/kysely/pagination.d.cts.map +1 -1
  7. package/dist/kysely/pagination.d.mts +14 -4
  8. package/dist/kysely/pagination.d.mts.map +1 -1
  9. package/dist/kysely/pagination.mjs +10 -7
  10. package/dist/kysely/pagination.mjs.map +1 -1
  11. package/dist/kysely-8WPSKCZG.cjs +17 -0
  12. package/dist/kysely-8WPSKCZG.cjs.map +1 -0
  13. package/dist/kysely-D3eeuId4.d.cts +13 -0
  14. package/dist/kysely-D3eeuId4.d.cts.map +1 -0
  15. package/dist/kysely-Dm1w5gAY.d.mts +13 -0
  16. package/dist/kysely-Dm1w5gAY.d.mts.map +1 -0
  17. package/dist/kysely-DmfA94RY.mjs +11 -0
  18. package/dist/kysely-DmfA94RY.mjs.map +1 -0
  19. package/dist/kysely.cjs +2 -11
  20. package/dist/kysely.d.cts +2 -9
  21. package/dist/kysely.d.mts +2 -9
  22. package/dist/kysely.mjs +2 -10
  23. package/dist/objection/pagination.cjs +7 -7
  24. package/dist/objection/pagination.cjs.map +1 -1
  25. package/dist/objection/pagination.d.cts +14 -4
  26. package/dist/objection/pagination.d.cts.map +1 -1
  27. package/dist/objection/pagination.d.mts +14 -4
  28. package/dist/objection/pagination.d.mts.map +1 -1
  29. package/dist/objection/pagination.mjs +8 -6
  30. package/dist/objection/pagination.mjs.map +1 -1
  31. package/dist/{pagination-CrU89125.d.cts → pagination-BAFX7C1I.d.cts} +4 -14
  32. package/dist/pagination-BAFX7C1I.d.cts.map +1 -0
  33. package/dist/pagination-BDLa7Yb_.mjs +37 -0
  34. package/dist/pagination-BDLa7Yb_.mjs.map +1 -0
  35. package/dist/pagination-Bdoa4PVj.cjs +55 -0
  36. package/dist/pagination-Bdoa4PVj.cjs.map +1 -0
  37. package/dist/{pagination-CrU89125.d.mts → pagination-BziGl-B8.d.mts} +4 -14
  38. package/dist/pagination-BziGl-B8.d.mts.map +1 -0
  39. package/dist/pagination.cjs +4 -55
  40. package/dist/pagination.d.cts +2 -2
  41. package/dist/pagination.d.mts +2 -2
  42. package/dist/pagination.mjs +2 -51
  43. package/dist/rls.cjs +29 -5
  44. package/dist/rls.cjs.map +1 -1
  45. package/dist/rls.d.cts +10 -6
  46. package/dist/rls.d.cts.map +1 -1
  47. package/dist/rls.d.mts +10 -6
  48. package/dist/rls.d.mts.map +1 -1
  49. package/dist/rls.mjs +5 -3
  50. package/dist/rls.mjs.map +1 -1
  51. package/package.json +9 -53
  52. package/src/__tests__/kysely.integration.spec.ts +741 -0
  53. package/src/__tests__/kysely.spec.ts +394 -0
  54. package/src/__tests__/rls.spec.ts +716 -0
  55. package/src/kysely/__tests__/pagination.integration.spec.ts +341 -0
  56. package/src/kysely/pagination.ts +113 -0
  57. package/src/kysely.ts +33 -0
  58. package/src/objection/__tests__/pagination.integration.spec.ts +291 -0
  59. package/src/objection/pagination.ts +98 -0
  60. package/src/pagination.ts +49 -0
  61. package/src/rls.ts +90 -0
  62. package/tsconfig.json +9 -0
  63. package/dist/errors.cjs +0 -73
  64. package/dist/errors.cjs.map +0 -1
  65. package/dist/errors.d.cts +0 -51
  66. package/dist/errors.d.cts.map +0 -1
  67. package/dist/errors.d.mts +0 -51
  68. package/dist/errors.d.mts.map +0 -1
  69. package/dist/errors.mjs +0 -69
  70. package/dist/errors.mjs.map +0 -1
  71. package/dist/introspect/DataBrowser.cjs +0 -117
  72. package/dist/introspect/DataBrowser.cjs.map +0 -1
  73. package/dist/introspect/DataBrowser.d.cts +0 -51
  74. package/dist/introspect/DataBrowser.d.cts.map +0 -1
  75. package/dist/introspect/DataBrowser.d.mts +0 -51
  76. package/dist/introspect/DataBrowser.d.mts.map +0 -1
  77. package/dist/introspect/DataBrowser.mjs +0 -116
  78. package/dist/introspect/DataBrowser.mjs.map +0 -1
  79. package/dist/introspect/errors.cjs +0 -48
  80. package/dist/introspect/errors.cjs.map +0 -1
  81. package/dist/introspect/errors.d.cts +0 -27
  82. package/dist/introspect/errors.d.cts.map +0 -1
  83. package/dist/introspect/errors.d.mts +0 -27
  84. package/dist/introspect/errors.d.mts.map +0 -1
  85. package/dist/introspect/errors.mjs +0 -45
  86. package/dist/introspect/errors.mjs.map +0 -1
  87. package/dist/introspect/filtering.cjs +0 -101
  88. package/dist/introspect/filtering.cjs.map +0 -1
  89. package/dist/introspect/filtering.d.cts +0 -29
  90. package/dist/introspect/filtering.d.cts.map +0 -1
  91. package/dist/introspect/filtering.d.mts +0 -29
  92. package/dist/introspect/filtering.d.mts.map +0 -1
  93. package/dist/introspect/filtering.mjs +0 -98
  94. package/dist/introspect/filtering.mjs.map +0 -1
  95. package/dist/introspect/handler.cjs +0 -159
  96. package/dist/introspect/handler.cjs.map +0 -1
  97. package/dist/introspect/handler.d.cts +0 -43
  98. package/dist/introspect/handler.d.cts.map +0 -1
  99. package/dist/introspect/handler.d.mts +0 -43
  100. package/dist/introspect/handler.d.mts.map +0 -1
  101. package/dist/introspect/handler.mjs +0 -158
  102. package/dist/introspect/handler.mjs.map +0 -1
  103. package/dist/introspect/index.cjs +0 -22
  104. package/dist/introspect/index.d.cts +0 -8
  105. package/dist/introspect/index.d.mts +0 -8
  106. package/dist/introspect/index.mjs +0 -8
  107. package/dist/introspect/introspection.cjs +0 -149
  108. package/dist/introspect/introspection.cjs.map +0 -1
  109. package/dist/introspect/introspection.d.cts +0 -25
  110. package/dist/introspect/introspection.d.cts.map +0 -1
  111. package/dist/introspect/introspection.d.mts +0 -25
  112. package/dist/introspect/introspection.d.mts.map +0 -1
  113. package/dist/introspect/introspection.mjs +0 -146
  114. package/dist/introspect/introspection.mjs.map +0 -1
  115. package/dist/introspect/types.cjs +0 -24
  116. package/dist/introspect/types.cjs.map +0 -1
  117. package/dist/introspect/types.d.cts +0 -113
  118. package/dist/introspect/types.d.cts.map +0 -1
  119. package/dist/introspect/types.d.mts +0 -113
  120. package/dist/introspect/types.d.mts.map +0 -1
  121. package/dist/introspect/types.mjs +0 -23
  122. package/dist/introspect/types.mjs.map +0 -1
  123. package/dist/kysely.cjs.map +0 -1
  124. package/dist/kysely.d.cts.map +0 -1
  125. package/dist/kysely.d.mts.map +0 -1
  126. package/dist/kysely.mjs.map +0 -1
  127. package/dist/pagination-CrU89125.d.cts.map +0 -1
  128. package/dist/pagination-CrU89125.d.mts.map +0 -1
  129. package/dist/pagination.cjs.map +0 -1
  130. package/dist/pagination.mjs.map +0 -1
  131. package/dist/pg/roles.cjs +0 -177
  132. package/dist/pg/roles.cjs.map +0 -1
  133. package/dist/pg/roles.d.cts +0 -90
  134. package/dist/pg/roles.d.cts.map +0 -1
  135. package/dist/pg/roles.d.mts +0 -90
  136. package/dist/pg/roles.d.mts.map +0 -1
  137. package/dist/pg/roles.mjs +0 -173
  138. package/dist/pg/roles.mjs.map +0 -1
  139. package/dist/pg/url.cjs +0 -48
  140. package/dist/pg/url.cjs.map +0 -1
  141. package/dist/pg/url.d.cts +0 -45
  142. package/dist/pg/url.d.cts.map +0 -1
  143. package/dist/pg/url.d.mts +0 -45
  144. package/dist/pg/url.d.mts.map +0 -1
  145. package/dist/pg/url.mjs +0 -47
  146. package/dist/pg/url.mjs.map +0 -1
@@ -1,45 +0,0 @@
1
- //#region src/introspect/errors.ts
2
- /**
3
- * What a row query can get wrong. Each is the caller's mistake rather than the
4
- * database's, so the JSON handler answers them as 4xx with the class name as
5
- * the error code — a client matches on that, not on the message.
6
- */
7
- /** A table that is not in the browsable schemas, or was excluded. */
8
- var TableNotFound = class extends Error {
9
- table;
10
- schema;
11
- constructor(table, schema) {
12
- super(`There is no table '${table}' in schema '${schema}'. List the tables to see what can be browsed; an excluded table is left out on purpose.`);
13
- this.table = table;
14
- this.schema = schema;
15
- this.name = "TableNotFound";
16
- }
17
- };
18
- /** A filter or sort naming a column the table does not have. */
19
- var ColumnNotFound = class extends Error {
20
- column;
21
- table;
22
- constructor(column, table) {
23
- super(`Table '${table}' has no column '${column}'. Use a column name exactly as the table description lists it.`);
24
- this.column = column;
25
- this.table = table;
26
- this.name = "ColumnNotFound";
27
- }
28
- };
29
- /** A filter operator that does not apply to the column's type. */
30
- var UnsupportedFilterOperator = class extends Error {
31
- operator;
32
- column;
33
- columnType;
34
- constructor(operator, column, columnType) {
35
- super(`'${operator}' cannot filter '${column}', a ${columnType} column. Use an operator that applies to ${columnType} values.`);
36
- this.operator = operator;
37
- this.column = column;
38
- this.columnType = columnType;
39
- this.name = "UnsupportedFilterOperator";
40
- }
41
- };
42
- //#endregion
43
- export { ColumnNotFound, TableNotFound, UnsupportedFilterOperator };
44
-
45
- //# sourceMappingURL=errors.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/introspect/errors.ts"],"sourcesContent":["/**\n * What a row query can get wrong. Each is the caller's mistake rather than the\n * database's, so the JSON handler answers them as 4xx with the class name as\n * the error code — a client matches on that, not on the message.\n */\n\n/** A table that is not in the browsable schemas, or was excluded. */\nexport class TableNotFound extends Error {\n\tconstructor(\n\t\treadonly table: string,\n\t\treadonly schema: string,\n\t) {\n\t\tsuper(\n\t\t\t`There is no table '${table}' in schema '${schema}'. List the tables to see what can be browsed; an excluded table is left out on purpose.`,\n\t\t);\n\t\tthis.name = 'TableNotFound';\n\t}\n}\n\n/** A filter or sort naming a column the table does not have. */\nexport class ColumnNotFound extends Error {\n\tconstructor(\n\t\treadonly column: string,\n\t\treadonly table: string,\n\t) {\n\t\tsuper(\n\t\t\t`Table '${table}' has no column '${column}'. Use a column name exactly as the table description lists it.`,\n\t\t);\n\t\tthis.name = 'ColumnNotFound';\n\t}\n}\n\n/** A filter operator that does not apply to the column's type. */\nexport class UnsupportedFilterOperator extends Error {\n\tconstructor(\n\t\treadonly operator: string,\n\t\treadonly column: string,\n\t\treadonly columnType: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${operator}' cannot filter '${column}', a ${columnType} column. Use an operator that applies to ${columnType} values.`,\n\t\t);\n\t\tthis.name = 'UnsupportedFilterOperator';\n\t}\n}\n"],"mappings":";;;;;;;AAOA,IAAa,gBAAb,cAAmC,MAAM;CAE9B;CACA;CAFV,YACC,OACA,QACC;EACD,MACC,sBAAsB,MAAM,eAAe,OAAO,yFACnD;EALS,KAAA,QAAA;EACA,KAAA,SAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,iBAAb,cAAoC,MAAM;CAE/B;CACA;CAFV,YACC,QACA,OACC;EACD,MACC,UAAU,MAAM,mBAAmB,OAAO,gEAC3C;EALS,KAAA,SAAA;EACA,KAAA,QAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,4BAAb,cAA+C,MAAM;CAE1C;CACA;CACA;CAHV,YACC,UACA,QACA,YACC;EACD,MACC,IAAI,SAAS,mBAAmB,OAAO,OAAO,WAAW,2CAA2C,WAAW,SAChH;EANS,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,aAAA;EAKT,KAAK,OAAO;CACb;AACD"}
@@ -1,101 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("../pagination.cjs");
3
- const require_introspect_errors = require("./errors.cjs");
4
- require("./types.cjs");
5
- //#region src/introspect/filtering.ts
6
- const NULLS = ["is_null", "is_not_null"];
7
- const EQUALITY = [
8
- "eq",
9
- "neq",
10
- ...NULLS
11
- ];
12
- const ORDERED = [
13
- ...EQUALITY,
14
- "gt",
15
- "gte",
16
- "lt",
17
- "lte"
18
- ];
19
- const MEMBERSHIP = ["in", "nin"];
20
- /** Which operators make sense for each column type. */
21
- const OPERATORS = {
22
- string: [
23
- ...EQUALITY,
24
- "like",
25
- "ilike",
26
- ...MEMBERSHIP
27
- ],
28
- number: [...ORDERED, ...MEMBERSHIP],
29
- boolean: EQUALITY,
30
- date: ORDERED,
31
- datetime: ORDERED,
32
- uuid: [...EQUALITY, ...MEMBERSHIP],
33
- json: NULLS,
34
- binary: NULLS,
35
- unknown: EQUALITY
36
- };
37
- /**
38
- * Whether a filter's operator applies to the column it names.
39
- */
40
- function validateFilter(filter, column) {
41
- if (OPERATORS[column.type].includes(filter.operator)) return { valid: true };
42
- return {
43
- valid: false,
44
- error: new require_introspect_errors.UnsupportedFilterOperator(filter.operator, column.name, column.type)
45
- };
46
- }
47
- /**
48
- * Adds each filter to the query as a `where`, after checking the column exists
49
- * and the operator applies to it.
50
- *
51
- * @throws {ColumnNotFound} a filter names a column the table does not have
52
- * @throws {UnsupportedFilterOperator} an operator does not apply to its column
53
- */
54
- function applyFilters(query, filters, table) {
55
- let result = query;
56
- for (const filter of filters) {
57
- const column = table.columns.find((c) => c.name === filter.column);
58
- if (!column) throw new require_introspect_errors.ColumnNotFound(filter.column, table.name);
59
- const validation = validateFilter(filter, column);
60
- if (!validation.valid) throw validation.error;
61
- result = applyFilterCondition(result, filter);
62
- }
63
- return result;
64
- }
65
- function applyFilterCondition(query, filter) {
66
- const column = filter.column;
67
- const { value } = filter;
68
- switch (filter.operator) {
69
- case "eq": return query.where(column, "=", value);
70
- case "neq": return query.where(column, "!=", value);
71
- case "gt": return query.where(column, ">", value);
72
- case "gte": return query.where(column, ">=", value);
73
- case "lt": return query.where(column, "<", value);
74
- case "lte": return query.where(column, "<=", value);
75
- case "like": return query.where(column, "like", value);
76
- case "ilike": return query.where(column, "ilike", value);
77
- case "in": return query.where(column, "in", value);
78
- case "nin": return query.where(column, "not in", value);
79
- case "is_null": return query.where(column, "is", null);
80
- case "is_not_null": return query.where(column, "is not", null);
81
- }
82
- }
83
- /**
84
- * Adds an `order by` per sort, in the order given.
85
- *
86
- * @throws {ColumnNotFound} a sort names a column the table does not have
87
- */
88
- function applySorting(query, sorts, table) {
89
- let result = query;
90
- for (const sort of sorts) {
91
- if (!table.columns.some((c) => c.name === sort.column)) throw new require_introspect_errors.ColumnNotFound(sort.column, table.name);
92
- result = result.orderBy(sort.column, sort.direction === "asc" ? "asc" : "desc");
93
- }
94
- return result;
95
- }
96
- //#endregion
97
- exports.applyFilters = applyFilters;
98
- exports.applySorting = applySorting;
99
- exports.validateFilter = validateFilter;
100
-
101
- //# sourceMappingURL=filtering.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.cjs","names":["UnsupportedFilterOperator","ColumnNotFound"],"sources":["../../src/introspect/filtering.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport { Direction } from '../pagination';\nimport { ColumnNotFound, UnsupportedFilterOperator } from './errors';\nimport {\n\ttype ColumnInfo,\n\ttype ColumnType,\n\ttype FilterCondition,\n\tFilterOperator,\n\ttype SortConfig,\n\ttype TableInfo,\n} from './types';\n\nconst NULLS = [FilterOperator.IsNull, FilterOperator.IsNotNull];\nconst EQUALITY = [FilterOperator.Eq, FilterOperator.Neq, ...NULLS];\nconst ORDERED = [\n\t...EQUALITY,\n\tFilterOperator.Gt,\n\tFilterOperator.Gte,\n\tFilterOperator.Lt,\n\tFilterOperator.Lte,\n];\nconst MEMBERSHIP = [FilterOperator.In, FilterOperator.Nin];\n\n/** Which operators make sense for each column type. */\nconst OPERATORS: Record<ColumnType, FilterOperator[]> = {\n\tstring: [\n\t\t...EQUALITY,\n\t\tFilterOperator.Like,\n\t\tFilterOperator.Ilike,\n\t\t...MEMBERSHIP,\n\t],\n\tnumber: [...ORDERED, ...MEMBERSHIP],\n\tboolean: EQUALITY,\n\tdate: ORDERED,\n\tdatetime: ORDERED,\n\tuuid: [...EQUALITY, ...MEMBERSHIP],\n\tjson: NULLS,\n\tbinary: NULLS,\n\tunknown: EQUALITY,\n};\n\n/**\n * Whether a filter's operator applies to the column it names.\n */\nexport function validateFilter(\n\tfilter: FilterCondition,\n\tcolumn: ColumnInfo,\n): { valid: true } | { valid: false; error: UnsupportedFilterOperator } {\n\tif (OPERATORS[column.type].includes(filter.operator)) {\n\t\treturn { valid: true };\n\t}\n\n\treturn {\n\t\tvalid: false,\n\t\terror: new UnsupportedFilterOperator(\n\t\t\tfilter.operator,\n\t\t\tcolumn.name,\n\t\t\tcolumn.type,\n\t\t),\n\t};\n}\n\n/**\n * Adds each filter to the query as a `where`, after checking the column exists\n * and the operator applies to it.\n *\n * @throws {ColumnNotFound} a filter names a column the table does not have\n * @throws {UnsupportedFilterOperator} an operator does not apply to its column\n */\nexport function applyFilters<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tfilters: FilterCondition[],\n\ttable: TableInfo,\n): SelectQueryBuilder<DB, TB, O> {\n\tlet result = query;\n\n\tfor (const filter of filters) {\n\t\tconst column = table.columns.find((c) => c.name === filter.column);\n\t\tif (!column) {\n\t\t\tthrow new ColumnNotFound(filter.column, table.name);\n\t\t}\n\n\t\tconst validation = validateFilter(filter, column);\n\t\tif (!validation.valid) {\n\t\t\tthrow validation.error;\n\t\t}\n\n\t\tresult = applyFilterCondition(result, filter);\n\t}\n\n\treturn result;\n}\n\nfunction applyFilterCondition<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tfilter: FilterCondition,\n): SelectQueryBuilder<DB, TB, O> {\n\t// The column was checked against the introspected table, which the query's\n\t// static types know nothing about.\n\tconst column = filter.column as any;\n\tconst { value } = filter;\n\n\tswitch (filter.operator) {\n\t\tcase FilterOperator.Eq:\n\t\t\treturn query.where(column, '=', value);\n\t\tcase FilterOperator.Neq:\n\t\t\treturn query.where(column, '!=', value);\n\t\tcase FilterOperator.Gt:\n\t\t\treturn query.where(column, '>', value);\n\t\tcase FilterOperator.Gte:\n\t\t\treturn query.where(column, '>=', value);\n\t\tcase FilterOperator.Lt:\n\t\t\treturn query.where(column, '<', value);\n\t\tcase FilterOperator.Lte:\n\t\t\treturn query.where(column, '<=', value);\n\t\tcase FilterOperator.Like:\n\t\t\treturn query.where(column, 'like', value);\n\t\tcase FilterOperator.Ilike:\n\t\t\treturn query.where(column, 'ilike', value);\n\t\tcase FilterOperator.In:\n\t\t\treturn query.where(column, 'in', value as unknown[]);\n\t\tcase FilterOperator.Nin:\n\t\t\treturn query.where(column, 'not in', value as unknown[]);\n\t\tcase FilterOperator.IsNull:\n\t\t\treturn query.where(column, 'is', null);\n\t\tcase FilterOperator.IsNotNull:\n\t\t\treturn query.where(column, 'is not', null);\n\t}\n}\n\n/**\n * Adds an `order by` per sort, in the order given.\n *\n * @throws {ColumnNotFound} a sort names a column the table does not have\n */\nexport function applySorting<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tsorts: SortConfig[],\n\ttable: TableInfo,\n): SelectQueryBuilder<DB, TB, O> {\n\tlet result = query;\n\n\tfor (const sort of sorts) {\n\t\tif (!table.columns.some((c) => c.name === sort.column)) {\n\t\t\tthrow new ColumnNotFound(sort.column, table.name);\n\t\t}\n\n\t\tresult = result.orderBy(\n\t\t\tsort.column as any,\n\t\t\tsort.direction === Direction.Asc ? 'asc' : 'desc',\n\t\t);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;AAYA,MAAM,QAAQ,CAAA,WAAA,aAAgD;AAC9D,MAAM,WAAW;;;CAAwC,GAAG;AAAK;AACjE,MAAM,UAAU;CACf,GAAG;;;;;AAKJ;AACA,MAAM,aAAa,CAAA,MAAA,KAAsC;;AAGzD,MAAM,YAAkD;CACvD,QAAQ;EACP,GAAG;;;EAGH,GAAG;CACJ;CACA,QAAQ,CAAC,GAAG,SAAS,GAAG,UAAU;CAClC,SAAS;CACT,MAAM;CACN,UAAU;CACV,MAAM,CAAC,GAAG,UAAU,GAAG,UAAU;CACjC,MAAM;CACN,QAAQ;CACR,SAAS;AACV;;;;AAKA,SAAgB,eACf,QACA,QACuE;CACvE,IAAI,UAAU,OAAO,KAAK,CAAC,SAAS,OAAO,QAAQ,GAClD,OAAO,EAAE,OAAO,KAAK;CAGtB,OAAO;E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AAOA,SAAgB,aACf,OACA,OACA,OACgC;CAChC,IAAI,SAAS;CAEb,KAAK,MAAM,QAAQ,OAAO;EACzB,IAAI,CAAC,MAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,KAAK,MAAM,GACpD,MAAM,IAAIA,0BAAAA,eAAe,KAAK,QAAQ,MAAM,IAAI;EAGjD,SAAS,OAAO,QACf,KAAK,QACL,KAAK,cAAA,QAA8B,QAAQ,MAC5C;CACD;CAEA,OAAO;AACR"}
@@ -1,29 +0,0 @@
1
- import { ColumnInfo, FilterCondition, SortConfig, TableInfo } from "./types.cjs";
2
- import { UnsupportedFilterOperator } from "./errors.cjs";
3
- import { SelectQueryBuilder } from "kysely";
4
- //#region src/introspect/filtering.d.ts
5
- /**
6
- * Whether a filter's operator applies to the column it names.
7
- */
8
- export declare function validateFilter(filter: FilterCondition, column: ColumnInfo): {
9
- valid: true;
10
- } | {
11
- valid: false;
12
- error: UnsupportedFilterOperator;
13
- };
14
- /**
15
- * Adds each filter to the query as a `where`, after checking the column exists
16
- * and the operator applies to it.
17
- *
18
- * @throws {ColumnNotFound} a filter names a column the table does not have
19
- * @throws {UnsupportedFilterOperator} an operator does not apply to its column
20
- */
21
- export declare function applyFilters<DB, TB extends keyof DB, O>(query: SelectQueryBuilder<DB, TB, O>, filters: FilterCondition[], table: TableInfo): SelectQueryBuilder<DB, TB, O>;
22
- /**
23
- * Adds an `order by` per sort, in the order given.
24
- *
25
- * @throws {ColumnNotFound} a sort names a column the table does not have
26
- */
27
- export declare function applySorting<DB, TB extends keyof DB, O>(query: SelectQueryBuilder<DB, TB, O>, sorts: SortConfig[], table: TableInfo): SelectQueryBuilder<DB, TB, O>;
28
- //#endregion
29
- //# sourceMappingURL=filtering.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.d.cts","names":[],"sources":["../../src/introspect/filtering.ts"],"mappings":";;;;;;;wBA4CgB,eACf,QAAQ,iBACR,QAAQ;EACJ;;EAAkB;EAAc,OAAO;;;;;;;;;wBAsB5B,aAAa,IAAI,iBAAiB,IAAI,GACrD,OAAO,mBAAmB,IAAI,IAAI,IAClC,SAAS,mBACT,OAAO,YACL,mBAAmB,IAAI,IAAI;;;;;;wBA8Dd,aAAa,IAAI,iBAAiB,IAAI,GACrD,OAAO,mBAAmB,IAAI,IAAI,IAClC,OAAO,cACP,OAAO,YACL,mBAAmB,IAAI,IAAI"}
@@ -1,29 +0,0 @@
1
- import { ColumnInfo, FilterCondition, SortConfig, TableInfo } from "./types.mjs";
2
- import { UnsupportedFilterOperator } from "./errors.mjs";
3
- import { SelectQueryBuilder } from "kysely";
4
- //#region src/introspect/filtering.d.ts
5
- /**
6
- * Whether a filter's operator applies to the column it names.
7
- */
8
- export declare function validateFilter(filter: FilterCondition, column: ColumnInfo): {
9
- valid: true;
10
- } | {
11
- valid: false;
12
- error: UnsupportedFilterOperator;
13
- };
14
- /**
15
- * Adds each filter to the query as a `where`, after checking the column exists
16
- * and the operator applies to it.
17
- *
18
- * @throws {ColumnNotFound} a filter names a column the table does not have
19
- * @throws {UnsupportedFilterOperator} an operator does not apply to its column
20
- */
21
- export declare function applyFilters<DB, TB extends keyof DB, O>(query: SelectQueryBuilder<DB, TB, O>, filters: FilterCondition[], table: TableInfo): SelectQueryBuilder<DB, TB, O>;
22
- /**
23
- * Adds an `order by` per sort, in the order given.
24
- *
25
- * @throws {ColumnNotFound} a sort names a column the table does not have
26
- */
27
- export declare function applySorting<DB, TB extends keyof DB, O>(query: SelectQueryBuilder<DB, TB, O>, sorts: SortConfig[], table: TableInfo): SelectQueryBuilder<DB, TB, O>;
28
- //#endregion
29
- //# sourceMappingURL=filtering.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.d.mts","names":[],"sources":["../../src/introspect/filtering.ts"],"mappings":";;;;;;;wBA4CgB,eACf,QAAQ,iBACR,QAAQ;EACJ;;EAAkB;EAAc,OAAO;;;;;;;;;wBAsB5B,aAAa,IAAI,iBAAiB,IAAI,GACrD,OAAO,mBAAmB,IAAI,IAAI,IAClC,SAAS,mBACT,OAAO,YACL,mBAAmB,IAAI,IAAI;;;;;;wBA8Dd,aAAa,IAAI,iBAAiB,IAAI,GACrD,OAAO,mBAAmB,IAAI,IAAI,IAClC,OAAO,cACP,OAAO,YACL,mBAAmB,IAAI,IAAI"}
@@ -1,98 +0,0 @@
1
- import "../pagination.mjs";
2
- import { ColumnNotFound, UnsupportedFilterOperator } from "./errors.mjs";
3
- import "./types.mjs";
4
- //#region src/introspect/filtering.ts
5
- const NULLS = ["is_null", "is_not_null"];
6
- const EQUALITY = [
7
- "eq",
8
- "neq",
9
- ...NULLS
10
- ];
11
- const ORDERED = [
12
- ...EQUALITY,
13
- "gt",
14
- "gte",
15
- "lt",
16
- "lte"
17
- ];
18
- const MEMBERSHIP = ["in", "nin"];
19
- /** Which operators make sense for each column type. */
20
- const OPERATORS = {
21
- string: [
22
- ...EQUALITY,
23
- "like",
24
- "ilike",
25
- ...MEMBERSHIP
26
- ],
27
- number: [...ORDERED, ...MEMBERSHIP],
28
- boolean: EQUALITY,
29
- date: ORDERED,
30
- datetime: ORDERED,
31
- uuid: [...EQUALITY, ...MEMBERSHIP],
32
- json: NULLS,
33
- binary: NULLS,
34
- unknown: EQUALITY
35
- };
36
- /**
37
- * Whether a filter's operator applies to the column it names.
38
- */
39
- function validateFilter(filter, column) {
40
- if (OPERATORS[column.type].includes(filter.operator)) return { valid: true };
41
- return {
42
- valid: false,
43
- error: new UnsupportedFilterOperator(filter.operator, column.name, column.type)
44
- };
45
- }
46
- /**
47
- * Adds each filter to the query as a `where`, after checking the column exists
48
- * and the operator applies to it.
49
- *
50
- * @throws {ColumnNotFound} a filter names a column the table does not have
51
- * @throws {UnsupportedFilterOperator} an operator does not apply to its column
52
- */
53
- function applyFilters(query, filters, table) {
54
- let result = query;
55
- for (const filter of filters) {
56
- const column = table.columns.find((c) => c.name === filter.column);
57
- if (!column) throw new ColumnNotFound(filter.column, table.name);
58
- const validation = validateFilter(filter, column);
59
- if (!validation.valid) throw validation.error;
60
- result = applyFilterCondition(result, filter);
61
- }
62
- return result;
63
- }
64
- function applyFilterCondition(query, filter) {
65
- const column = filter.column;
66
- const { value } = filter;
67
- switch (filter.operator) {
68
- case "eq": return query.where(column, "=", value);
69
- case "neq": return query.where(column, "!=", value);
70
- case "gt": return query.where(column, ">", value);
71
- case "gte": return query.where(column, ">=", value);
72
- case "lt": return query.where(column, "<", value);
73
- case "lte": return query.where(column, "<=", value);
74
- case "like": return query.where(column, "like", value);
75
- case "ilike": return query.where(column, "ilike", value);
76
- case "in": return query.where(column, "in", value);
77
- case "nin": return query.where(column, "not in", value);
78
- case "is_null": return query.where(column, "is", null);
79
- case "is_not_null": return query.where(column, "is not", null);
80
- }
81
- }
82
- /**
83
- * Adds an `order by` per sort, in the order given.
84
- *
85
- * @throws {ColumnNotFound} a sort names a column the table does not have
86
- */
87
- function applySorting(query, sorts, table) {
88
- let result = query;
89
- for (const sort of sorts) {
90
- if (!table.columns.some((c) => c.name === sort.column)) throw new ColumnNotFound(sort.column, table.name);
91
- result = result.orderBy(sort.column, sort.direction === "asc" ? "asc" : "desc");
92
- }
93
- return result;
94
- }
95
- //#endregion
96
- export { applyFilters, applySorting, validateFilter };
97
-
98
- //# sourceMappingURL=filtering.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.mjs","names":[],"sources":["../../src/introspect/filtering.ts"],"sourcesContent":["import type { SelectQueryBuilder } from 'kysely';\nimport { Direction } from '../pagination';\nimport { ColumnNotFound, UnsupportedFilterOperator } from './errors';\nimport {\n\ttype ColumnInfo,\n\ttype ColumnType,\n\ttype FilterCondition,\n\tFilterOperator,\n\ttype SortConfig,\n\ttype TableInfo,\n} from './types';\n\nconst NULLS = [FilterOperator.IsNull, FilterOperator.IsNotNull];\nconst EQUALITY = [FilterOperator.Eq, FilterOperator.Neq, ...NULLS];\nconst ORDERED = [\n\t...EQUALITY,\n\tFilterOperator.Gt,\n\tFilterOperator.Gte,\n\tFilterOperator.Lt,\n\tFilterOperator.Lte,\n];\nconst MEMBERSHIP = [FilterOperator.In, FilterOperator.Nin];\n\n/** Which operators make sense for each column type. */\nconst OPERATORS: Record<ColumnType, FilterOperator[]> = {\n\tstring: [\n\t\t...EQUALITY,\n\t\tFilterOperator.Like,\n\t\tFilterOperator.Ilike,\n\t\t...MEMBERSHIP,\n\t],\n\tnumber: [...ORDERED, ...MEMBERSHIP],\n\tboolean: EQUALITY,\n\tdate: ORDERED,\n\tdatetime: ORDERED,\n\tuuid: [...EQUALITY, ...MEMBERSHIP],\n\tjson: NULLS,\n\tbinary: NULLS,\n\tunknown: EQUALITY,\n};\n\n/**\n * Whether a filter's operator applies to the column it names.\n */\nexport function validateFilter(\n\tfilter: FilterCondition,\n\tcolumn: ColumnInfo,\n): { valid: true } | { valid: false; error: UnsupportedFilterOperator } {\n\tif (OPERATORS[column.type].includes(filter.operator)) {\n\t\treturn { valid: true };\n\t}\n\n\treturn {\n\t\tvalid: false,\n\t\terror: new UnsupportedFilterOperator(\n\t\t\tfilter.operator,\n\t\t\tcolumn.name,\n\t\t\tcolumn.type,\n\t\t),\n\t};\n}\n\n/**\n * Adds each filter to the query as a `where`, after checking the column exists\n * and the operator applies to it.\n *\n * @throws {ColumnNotFound} a filter names a column the table does not have\n * @throws {UnsupportedFilterOperator} an operator does not apply to its column\n */\nexport function applyFilters<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tfilters: FilterCondition[],\n\ttable: TableInfo,\n): SelectQueryBuilder<DB, TB, O> {\n\tlet result = query;\n\n\tfor (const filter of filters) {\n\t\tconst column = table.columns.find((c) => c.name === filter.column);\n\t\tif (!column) {\n\t\t\tthrow new ColumnNotFound(filter.column, table.name);\n\t\t}\n\n\t\tconst validation = validateFilter(filter, column);\n\t\tif (!validation.valid) {\n\t\t\tthrow validation.error;\n\t\t}\n\n\t\tresult = applyFilterCondition(result, filter);\n\t}\n\n\treturn result;\n}\n\nfunction applyFilterCondition<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tfilter: FilterCondition,\n): SelectQueryBuilder<DB, TB, O> {\n\t// The column was checked against the introspected table, which the query's\n\t// static types know nothing about.\n\tconst column = filter.column as any;\n\tconst { value } = filter;\n\n\tswitch (filter.operator) {\n\t\tcase FilterOperator.Eq:\n\t\t\treturn query.where(column, '=', value);\n\t\tcase FilterOperator.Neq:\n\t\t\treturn query.where(column, '!=', value);\n\t\tcase FilterOperator.Gt:\n\t\t\treturn query.where(column, '>', value);\n\t\tcase FilterOperator.Gte:\n\t\t\treturn query.where(column, '>=', value);\n\t\tcase FilterOperator.Lt:\n\t\t\treturn query.where(column, '<', value);\n\t\tcase FilterOperator.Lte:\n\t\t\treturn query.where(column, '<=', value);\n\t\tcase FilterOperator.Like:\n\t\t\treturn query.where(column, 'like', value);\n\t\tcase FilterOperator.Ilike:\n\t\t\treturn query.where(column, 'ilike', value);\n\t\tcase FilterOperator.In:\n\t\t\treturn query.where(column, 'in', value as unknown[]);\n\t\tcase FilterOperator.Nin:\n\t\t\treturn query.where(column, 'not in', value as unknown[]);\n\t\tcase FilterOperator.IsNull:\n\t\t\treturn query.where(column, 'is', null);\n\t\tcase FilterOperator.IsNotNull:\n\t\t\treturn query.where(column, 'is not', null);\n\t}\n}\n\n/**\n * Adds an `order by` per sort, in the order given.\n *\n * @throws {ColumnNotFound} a sort names a column the table does not have\n */\nexport function applySorting<DB, TB extends keyof DB, O>(\n\tquery: SelectQueryBuilder<DB, TB, O>,\n\tsorts: SortConfig[],\n\ttable: TableInfo,\n): SelectQueryBuilder<DB, TB, O> {\n\tlet result = query;\n\n\tfor (const sort of sorts) {\n\t\tif (!table.columns.some((c) => c.name === sort.column)) {\n\t\t\tthrow new ColumnNotFound(sort.column, table.name);\n\t\t}\n\n\t\tresult = result.orderBy(\n\t\t\tsort.column as any,\n\t\t\tsort.direction === Direction.Asc ? 'asc' : 'desc',\n\t\t);\n\t}\n\n\tre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KAAK;EACtC,KAAA,OACC,OAAO,MAAM,MAAM,QAAQ,MAAM,KAAK;EACvC,KAAA,MACC,OAAO,MAAM,MAAM,QAAQ,KAAK,KAAK;EACtC,KAAA,OACC,OAAO,MAAM,MAAM,QAAQ,MAAM,KAAK;EACvC,KAAA,QACC,OAAO,MAAM,MAAM,QAAQ,QAAQ,KAAK;EACzC,KAAA,SACC,OAAO,MAAM,MAAM,QAAQ,SAAS,KAAK;EAC1C,KAAA,MACC,OAAO,MAAM,MAAM,QAAQ,MAAM,KAAkB;EACpD,KAAA,OACC,OAAO,MAAM,MAAM,QAAQ,UAAU,KAAkB;EACxD,KAAA,WACC,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;EACtC,KAAA,eACC,OAAO,MAAM,MAAM,QAAQ,UAAU,IAAI;CAC3C;AACD;;;;;;AAOA,SAAgB,aACf,OACA,OACA,OACgC;CAChC,IAAI,SAAS;CAEb,KAAK,MAAM,QAAQ,OAAO;EACzB,IAAI,CAAC,MAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,KAAK,MAAM,GACpD,MAAM,IAAI,eAAe,KAAK,QAAQ,MAAM,IAAI;EAGjD,SAAS,OAAO,QACf,KAAK,QACL,KAAK,cAAA,QAA8B,QAAQ,MAC5C;CACD;CAEA,OAAO;AACR"}
@@ -1,159 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_pagination = require("../pagination.cjs");
3
- const require_introspect_errors = require("./errors.cjs");
4
- const require_introspect_types = require("./types.cjs");
5
- const require_introspect_DataBrowser = require("./DataBrowser.cjs");
6
- //#region src/introspect/handler.ts
7
- const OPERATORS = new Set(Object.values(require_introspect_types.FilterOperator));
8
- /**
9
- * A read-only JSON API over a Postgres database's structure and rows.
10
- *
11
- * A plain `(Request) => Promise<Response>` rather than a router, so it mounts
12
- * in anything that speaks web `Request`s — Hono, Bun, Deno, a Node adapter —
13
- * and `@geekmidas/db` takes on no HTTP framework to provide it.
14
- *
15
- * | Route | Returns |
16
- * | ----------------------------- | ----------------------------------------------- |
17
- * | `GET /schemas` | `{ schemas, browsable }` |
18
- * | `GET /tables?schema=&refresh=`| `{ tables }` with columns and foreign keys |
19
- * | `GET /tables/:name?schema=` | one table |
20
- * | `GET /tables/:name/rows` | a page of rows: `{ rows, hasMore, nextCursor }` |
21
- *
22
- * Rows take `pageSize` (≤ 100), `cursor`, `sort=col:asc,col2:desc` and filters
23
- * as `filter[column][operator]=value` — `in`/`nin` take a comma-separated
24
- * list, `is_null`/`is_not_null` take no value.
25
- *
26
- * It exposes every row of every browsable table to whoever can reach it. Mount
27
- * it only where that is the developer: `gkm dev` serves it at `/__gkm/db` and
28
- * nothing in a production build does.
29
- *
30
- * @example
31
- * ```typescript
32
- * const handler = createIntrospectionHandler({ db, basePath: '/__gkm/db' });
33
- * app.all('/__gkm/db/*', (c) => handler(c.req.raw));
34
- * ```
35
- */
36
- function createIntrospectionHandler(options) {
37
- const browser = new require_introspect_DataBrowser.DataBrowser(options);
38
- const basePath = (options.basePath ?? "").replace(/\/+$/, "");
39
- return async (request) => {
40
- if (request.method !== "GET") return json({
41
- error: "MethodNotAllowed",
42
- message: "The database API is read-only; only GET is served."
43
- }, 405, { allow: "GET" });
44
- const url = new URL(request.url);
45
- const path = url.pathname.startsWith(basePath) ? url.pathname.slice(basePath.length) : url.pathname;
46
- const segments = path.split("/").filter(Boolean).map(decodeURIComponent);
47
- const schema = url.searchParams.get("schema") ?? void 0;
48
- try {
49
- if (segments.length === 1 && segments[0] === "schemas") return json({
50
- schemas: await browser.listSchemas(),
51
- browsable: browser.schemas
52
- });
53
- if (segments.length === 1 && segments[0] === "tables") {
54
- const refresh = url.searchParams.get("refresh") === "true";
55
- const { tables, updatedAt } = await browser.getSchema(refresh);
56
- return json({
57
- tables: schema ? tables.filter((t) => t.schema === schema) : tables,
58
- updatedAt
59
- });
60
- }
61
- if (segments[0] === "tables" && segments[1] && segments.length === 2) {
62
- const table = await browser.getTableInfo(segments[1], schema);
63
- if (!table) throw new require_introspect_errors.TableNotFound(segments[1], schema ?? browser.schemas[0] ?? "public");
64
- return json(table);
65
- }
66
- if (segments[0] === "tables" && segments[1] && segments[2] === "rows" && segments.length === 3) {
67
- const pageSize = Number.parseInt(url.searchParams.get("pageSize") ?? "", 10);
68
- const filters = parseFilters(url.searchParams);
69
- const sort = parseSort(url.searchParams.get("sort"));
70
- return json(await browser.query({
71
- table: segments[1],
72
- schema,
73
- pageSize: Number.isNaN(pageSize) ? void 0 : pageSize,
74
- cursor: url.searchParams.get("cursor") || void 0,
75
- filters: filters.length > 0 ? filters : void 0,
76
- sort: sort.length > 0 ? sort : void 0
77
- }));
78
- }
79
- return json({
80
- error: "NotFound",
81
- message: `No database route at '${path || "/"}'. Routes: /schemas, /tables, /tables/:name, /tables/:name/rows.`
82
- }, 404);
83
- } catch (error) {
84
- const status = statusFor(error);
85
- if (status === void 0) throw error;
86
- return json({
87
- error: error.name,
88
- message: error.message
89
- }, status);
90
- }
91
- };
92
- }
93
- /** The caller's mistakes, answered; anything else is the server's and thrown. */
94
- function statusFor(error) {
95
- if (error instanceof require_introspect_errors.TableNotFound) return 404;
96
- if (error instanceof require_introspect_errors.ColumnNotFound || error instanceof require_introspect_errors.UnsupportedFilterOperator || error instanceof require_pagination.InvalidCursor) return 400;
97
- }
98
- /**
99
- * `filter[column][operator]=value`. An unknown operator is ignored rather than
100
- * rejected, as a misspelt one in a hand-typed URL is easier to see in the
101
- * results than to debug from an error.
102
- */
103
- function parseFilters(params) {
104
- const filters = [];
105
- for (const [key, value] of params) {
106
- const match = key.match(/^filter\[(\w+)\]\[(\w+)\]$/);
107
- const column = match?.[1];
108
- const operator = match?.[2];
109
- if (!column || !operator || !OPERATORS.has(operator)) continue;
110
- const op = operator;
111
- if (op === "in" || op === "nin") filters.push({
112
- column,
113
- operator: op,
114
- value: value.split(",")
115
- });
116
- else if (op === "is_null" || op === "is_not_null") filters.push({
117
- column,
118
- operator: op
119
- });
120
- else filters.push({
121
- column,
122
- operator: op,
123
- value: parseScalar(value)
124
- });
125
- }
126
- return filters;
127
- }
128
- function parseScalar(value) {
129
- if (value === "true") return true;
130
- if (value === "false") return false;
131
- if (value !== "" && !Number.isNaN(Number(value))) return Number(value);
132
- return value;
133
- }
134
- /** `sort=name:asc,created_at:desc`; a column with no direction is ascending. */
135
- function parseSort(param) {
136
- if (!param) return [];
137
- return param.split(",").flatMap((part) => {
138
- const [column, direction] = part.split(":");
139
- if (!column) return [];
140
- return [{
141
- column,
142
- direction: direction === "desc" ? "desc" : "asc"
143
- }];
144
- });
145
- }
146
- function json(body, status = 200, headers = {}) {
147
- const text = JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value);
148
- return new Response(text, {
149
- status,
150
- headers: {
151
- "content-type": "application/json; charset=utf-8",
152
- ...headers
153
- }
154
- });
155
- }
156
- //#endregion
157
- exports.createIntrospectionHandler = createIntrospectionHandler;
158
-
159
- //# sourceMappingURL=handler.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler.cjs","names":["FilterOperator","DataBrowser","TableNotFound","ColumnNotFound","UnsupportedFilterOperator","InvalidCursor"],"sources":["../../src/introspect/handler.ts"],"sourcesContent":["import { Direction, InvalidCursor } from '../pagination';\nimport { DataBrowser } from './DataBrowser';\nimport {\n\tColumnNotFound,\n\tTableNotFound,\n\tUnsupportedFilterOperator,\n} from './errors';\nimport {\n\ttype DataBrowserOptions,\n\ttype FilterCondition,\n\tFilterOperator,\n\ttype SortConfig,\n} from './types';\n\nexport interface IntrospectionHandlerOptions<DB = unknown>\n\textends DataBrowserOptions<DB> {\n\t/**\n\t * The path the handler is mounted under, e.g. `/__gkm/db`. Stripped from\n\t * each request's path before routing, so the handler can be mounted\n\t * anywhere without a router of its own.\n\t */\n\tbasePath?: string;\n}\n\n/** A fetch-style handler: a web `Request` in, a JSON `Response` out. */\nexport type IntrospectionHandler = (request: Request) => Promise<Response>;\n\nconst OPERATORS = new Set<string>(Object.values(FilterOperator));\n\n/**\n * A read-only JSON API over a Postgres database's structure and rows.\n *\n * A plain `(Request) => Promise<Response>` rather than a router, so it mounts\n * in anything that speaks web `Request`s — Hono, Bun, Deno, a Node adapter —\n * and `@geekmidas/db` takes on no HTTP framework to provide it.\n *\n * | Route | Returns |\n * | ----------------------------- | ----------------------------------------------- |\n * | `GET /schemas` | `{ schemas, browsable }` |\n * | `GET /tables?schema=&refresh=`| `{ tables }` with columns and foreign keys |\n * | `GET /tables/:name?schema=` | one table |\n * | `GET /tables/:name/rows` | a page of rows: `{ rows, hasMore, nextCursor }` |\n *\n * Rows take `pageSize` (≤ 100), `cursor`, `sort=col:asc,col2:desc` and filters\n * as `filter[column][operator]=value` — `in`/`nin` take a comma-separated\n * list, `is_null`/`is_not_null` take no value.\n *\n * It exposes every row of every browsable table to whoever can reach it. Mount\n * it only where that is the developer: `gkm dev` serves it at `/__gkm/db` and\n * nothing in a production build does.\n *\n * @example\n * ```typescript\n * const handler = createIntrospectionHandler({ db, basePath: '/__gkm/db' });\n * app.all('/__gkm/db/*', (c) => handler(c.req.raw));\n * ```\n */\nexport function createIntrospectionHandler<DB>(\n\toptions: IntrospectionHandlerOptions<DB>,\n): IntrospectionHandler {\n\tconst browser = new DataBrowser(options);\n\tconst basePath = (options.basePath ?? '').replace(/\\/+$/, '');\n\n\treturn async (request) => {\n\t\tif (request.method !== 'GET') {\n\t\t\treturn json(\n\t\t\t\t{\n\t\t\t\t\terror: 'MethodNotAllowed',\n\t\t\t\t\tmessage: 'The database API is read-only; only GET is served.',\n\t\t\t\t},\n\t\t\t\t405,\n\t\t\t\t{ allow: 'GET' },\n\t\t\t);\n\t\t}\n\n\t\tconst url = new URL(request.url);\n\t\tconst path = url.pathname.startsWith(basePath)\n\t\t\t? url.pathname.slice(basePath.length)\n\t\t\t: url.pathname;\n\t\tconst segments = path.split('/').filter(Boolean).map(decodeURIComponent);\n\t\tconst schema = url.searchParams.get('schema') ?? undefined;\n\n\t\ttry {\n\t\t\tif (segments.length === 1 && segments[0] === 'schemas') {\n\t\t\t\treturn json({\n\t\t\t\t\tschemas: await browser.listSchemas(),\n\t\t\t\t\tbrowsable: browser.schemas,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (segments.length === 1 && segments[0] === 'tables') {\n\t\t\t\tconst refresh = url.searchParams.get('refresh') === 'true';\n\t\t\t\tconst { tables, updatedAt } = await browser.getSchema(refresh);\n\t\t\t\treturn json({\n\t\t\t\t\ttables: schema ? tables.filter((t) => t.schema === schema) : tables,\n\t\t\t\t\tupdatedAt,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (segments[0] === 'tables' && segments[1] && segments.length === 2) {\n\t\t\t\tconst table = await browser.getTableInfo(segments[1], schema);\n\t\t\t\tif (!table) {\n\t\t\t\t\tthrow new TableNotFound(\n\t\t\t\t\t\tsegments[1],\n\t\t\t\t\t\tschema ?? browser.schemas[0] ?? 'public',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn json(table);\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tsegments[0] === 'tables' &&\n\t\t\t\tsegments[1] &&\n\t\t\t\tsegments[2] === 'rows' &&\n\t\t\t\tsegments.length === 3\n\t\t\t) {\n\t\t\t\tconst pageSize = Number.parseInt(\n\t\t\t\t\turl.searchParams.get('pageSize') ?? '',\n\t\t\t\t\t10,\n\t\t\t\t);\n\t\t\t\tconst filters = parseFilters(url.searchParams);\n\t\t\t\tconst sort = parseSort(url.searchParams.get('sort'));\n\n\t\t\t\treturn json(\n\t\t\t\t\tawait browser.query({\n\t\t\t\t\t\ttable: segments[1],\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tpageSize: Number.isNaN(pageSize) ? undefined : pageSize,\n\t\t\t\t\t\tcursor: url.searchParams.get('cursor') || undefined,\n\t\t\t\t\t\tfilters: filters.length > 0 ? filters : undefined,\n\t\t\t\t\t\tsort: sort.length > 0 ? sort : undefined,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn json(\n\t\t\t\t{\n\t\t\t\t\terror: 'NotFound',\n\t\t\t\t\tmessage: `No database route at '${path || '/'}'. Routes: /schemas, /tables, /tables/:name, /tables/:name/rows.`,\n\t\t\t\t},\n\t\t\t\t404,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst status = statusFor(error);\n\t\t\tif (status === undefined) throw error;\n\t\t\treturn json(\n\t\t\t\t{ error: (error as Error).name, message: (error as Error).message },\n\t\t\t\tstatus,\n\t\t\t);\n\t\t}\n\t};\n}\n\n/** The caller's mistakes, answered; anything else is the server's and thrown. */\nfunction statusFor(error: unknown): number | undefined {\n\tif (error instanceof TableNotFound) return 404;\n\tif (\n\t\terror instanceof ColumnNotFound ||\n\t\terror instanceof UnsupportedFilterOperator ||\n\t\terror instanceof InvalidCursor\n\t) {\n\t\treturn 400;\n\t}\n\treturn undefined;\n}\n\n/**\n * `filter[column][operator]=value`. An unknown operator is ignored rather than\n * rejected, as a misspelt one in a hand-typed URL is easier to see in the\n * results than to debug from an error.\n */\nfunction parseFilters(params: URLSearchParams): FilterCondition[] {\n\tconst filters: FilterCondition[] = [];\n\n\tfor (const [key, value] of params) {\n\t\tconst match = key.match(/^filter\\[(\\w+)\\]\\[(\\w+)\\]$/);\n\t\tconst column = match?.[1];\n\t\tconst operator = match?.[2];\n\t\tif (!column || !operator || !OPERATORS.has(operator)) continue;\n\n\t\tconst op = operator as FilterOperator;\n\t\tif (op === FilterOperator.In || op === FilterOperator.Nin) {\n\t\t\tfilters.push({ column, operator: op, value: value.split(',') });\n\t\t} else if (\n\t\t\top === FilterOperator.IsNull ||\n\t\t\top === FilterOperator.IsNotNull\n\t\t) {\n\t\t\tfilters.push({ column, operator: op });\n\t\t} else {\n\t\t\tfilters.push({ column, operator: op, value: parseScalar(value) });\n\t\t}\n\t}\n\n\treturn filters;\n}\n\nfunction parseScalar(value: string): unknown {\n\tif (value === 'true') return true;\n\tif (value === 'false') return false;\n\tif (value !== '' && !Number.isNaN(Number(value))) return Number(value);\n\treturn value;\n}\n\n/** `sort=name:asc,created_at:desc`; a column with no direction is ascending. */\nfunction parseSort(param: string | null): SortConfig[] {\n\tif (!param) return [];\n\n\treturn param.split(',').flatMap((part) => {\n\t\tconst [column, direction] = part.split(':');\n\t\tif (!column) return [];\n\t\treturn [\n\t\t\t{\n\t\t\t\tcolumn,\n\t\t\t\tdirection: direction === 'desc' ? Direction.Desc : Direction.Asc,\n\t\t\t},\n\t\t];\n\t});\n}\n\nfunction json(\n\tbody: unknown,\n\tstatus = 200,\n\theaders: Record<string, string> = {},\n): Response {\n\t// A row can hold a bigint when the pg client is configured to parse int8,\n\t// and JSON.stringify throws on one.\n\tconst text = JSON.stringify(body, (_key, value) =>\n\t\ttypeof value === 'bigint' ? value.toString() : value,\n\t);\n\treturn new Response(text, {\n\t\tstatus,\n\t\theaders: { 'content-type': 'application/json; charset=utf-8', ...headers },\n\t});\n}\n"],"mappings":";;;;;;AA2BA,MAAM,YAAY,IAAI,IAAY,OAAO,OAAOA,yBAAAA,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B/D,SAAgB,2BACf,SACuB;CACvB,MAAM,UAAU,IAAIC,+BAAAA,YAAY,OAAO;CACvC,MAAM,YAAY,QAAQ,YAAY,GAAA,CAAI,QAAQ,QAAQ,EAAE;CAE5D,OAAO,OAAO,YAAY;EACzB,IAAI,QAAQ,WAAW,OACtB,OAAO,KACN;GACC,OAAO;GACP,SAAS;EACV,GACA,KACA,EAAE,OAAO,MAAM,CAChB;EAGD,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;EAC/B,MAAM,OAAO,IAAI,SAAS,WAAW,QAAQ,IAC1C,IAAI,SAAS,MAAM,SAAS,MAAM,IAClC,IAAI;EACP,MAAM,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,kBAAkB;EACvE,MAAM,SAAS,IAAI,aAAa,IAAI,QAAQ,KAAK,KAAA;EAEjD,IAAI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G;EAC1C,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,OAAO,CACN;GACC;GACA,WAAW,cAAc,SAAA,SAAA;EAC1B,CACD;CACD,CAAC;AACF;AAEA,SAAS,KACR,MACA,SAAS,KACT,UAAkC,CAAC,GACxB;CAGX,MAAM,OAAO,KAAK,UAAU,OAAO,MAAM,UACxC,OAAO,UAAU,WAAW,MAAM,SAAS,IAAI,KAChD;CACA,OAAO,IAAI,SAAS,MAAM;EACzB;EACA,SAAS;GAAE,gBAAgB;GAAmC,GAAG;EAAQ;CAC1E,CAAC;AACF"}
@@ -1,43 +0,0 @@
1
- import { DataBrowserOptions } from "./types.cjs";
2
- //#region src/introspect/handler.d.ts
3
- export interface IntrospectionHandlerOptions<DB = unknown> extends DataBrowserOptions<DB> {
4
- /**
5
- * The path the handler is mounted under, e.g. `/__gkm/db`. Stripped from
6
- * each request's path before routing, so the handler can be mounted
7
- * anywhere without a router of its own.
8
- */
9
- basePath?: string;
10
- }
11
- /** A fetch-style handler: a web `Request` in, a JSON `Response` out. */
12
- export type IntrospectionHandler = (request: Request) => Promise<Response>;
13
- /**
14
- * A read-only JSON API over a Postgres database's structure and rows.
15
- *
16
- * A plain `(Request) => Promise<Response>` rather than a router, so it mounts
17
- * in anything that speaks web `Request`s — Hono, Bun, Deno, a Node adapter —
18
- * and `@geekmidas/db` takes on no HTTP framework to provide it.
19
- *
20
- * | Route | Returns |
21
- * | ----------------------------- | ----------------------------------------------- |
22
- * | `GET /schemas` | `{ schemas, browsable }` |
23
- * | `GET /tables?schema=&refresh=`| `{ tables }` with columns and foreign keys |
24
- * | `GET /tables/:name?schema=` | one table |
25
- * | `GET /tables/:name/rows` | a page of rows: `{ rows, hasMore, nextCursor }` |
26
- *
27
- * Rows take `pageSize` (≤ 100), `cursor`, `sort=col:asc,col2:desc` and filters
28
- * as `filter[column][operator]=value` — `in`/`nin` take a comma-separated
29
- * list, `is_null`/`is_not_null` take no value.
30
- *
31
- * It exposes every row of every browsable table to whoever can reach it. Mount
32
- * it only where that is the developer: `gkm dev` serves it at `/__gkm/db` and
33
- * nothing in a production build does.
34
- *
35
- * @example
36
- * ```typescript
37
- * const handler = createIntrospectionHandler({ db, basePath: '/__gkm/db' });
38
- * app.all('/__gkm/db/*', (c) => handler(c.req.raw));
39
- * ```
40
- */
41
- export declare function createIntrospectionHandler<DB>(options: IntrospectionHandlerOptions<DB>): IntrospectionHandler;
42
- //#endregion
43
- //# sourceMappingURL=handler.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler.d.cts","names":[],"sources":["../../src/introspect/handler.ts"],"mappings":";;iBAciB,4BAA4B,sBACpC,mBAAmB;;;;;;EAM3B;;;YAIW,wBAAwB,SAAS,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCjD,2BAA2B,IAC1C,SAAS,4BAA4B,MACnC"}
@@ -1,43 +0,0 @@
1
- import { DataBrowserOptions } from "./types.mjs";
2
- //#region src/introspect/handler.d.ts
3
- export interface IntrospectionHandlerOptions<DB = unknown> extends DataBrowserOptions<DB> {
4
- /**
5
- * The path the handler is mounted under, e.g. `/__gkm/db`. Stripped from
6
- * each request's path before routing, so the handler can be mounted
7
- * anywhere without a router of its own.
8
- */
9
- basePath?: string;
10
- }
11
- /** A fetch-style handler: a web `Request` in, a JSON `Response` out. */
12
- export type IntrospectionHandler = (request: Request) => Promise<Response>;
13
- /**
14
- * A read-only JSON API over a Postgres database's structure and rows.
15
- *
16
- * A plain `(Request) => Promise<Response>` rather than a router, so it mounts
17
- * in anything that speaks web `Request`s — Hono, Bun, Deno, a Node adapter —
18
- * and `@geekmidas/db` takes on no HTTP framework to provide it.
19
- *
20
- * | Route | Returns |
21
- * | ----------------------------- | ----------------------------------------------- |
22
- * | `GET /schemas` | `{ schemas, browsable }` |
23
- * | `GET /tables?schema=&refresh=`| `{ tables }` with columns and foreign keys |
24
- * | `GET /tables/:name?schema=` | one table |
25
- * | `GET /tables/:name/rows` | a page of rows: `{ rows, hasMore, nextCursor }` |
26
- *
27
- * Rows take `pageSize` (≤ 100), `cursor`, `sort=col:asc,col2:desc` and filters
28
- * as `filter[column][operator]=value` — `in`/`nin` take a comma-separated
29
- * list, `is_null`/`is_not_null` take no value.
30
- *
31
- * It exposes every row of every browsable table to whoever can reach it. Mount
32
- * it only where that is the developer: `gkm dev` serves it at `/__gkm/db` and
33
- * nothing in a production build does.
34
- *
35
- * @example
36
- * ```typescript
37
- * const handler = createIntrospectionHandler({ db, basePath: '/__gkm/db' });
38
- * app.all('/__gkm/db/*', (c) => handler(c.req.raw));
39
- * ```
40
- */
41
- export declare function createIntrospectionHandler<DB>(options: IntrospectionHandlerOptions<DB>): IntrospectionHandler;
42
- //#endregion
43
- //# sourceMappingURL=handler.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler.d.mts","names":[],"sources":["../../src/introspect/handler.ts"],"mappings":";;iBAciB,4BAA4B,sBACpC,mBAAmB;;;;;;EAM3B;;;YAIW,wBAAwB,SAAS,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCjD,2BAA2B,IAC1C,SAAS,4BAA4B,MACnC"}