@palbase/modules-db 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/admin.cjs +258 -0
- package/dist/admin.cjs.map +1 -0
- package/dist/admin.d.cts +178 -0
- package/dist/admin.d.ts +178 -0
- package/dist/admin.js +13 -0
- package/dist/admin.js.map +1 -0
- package/dist/chunk-AQ6ZQNXC.js +229 -0
- package/dist/chunk-AQ6ZQNXC.js.map +1 -0
- package/dist/index.cjs +665 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +415 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Palbase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/admin.cjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/admin.ts
|
|
21
|
+
var admin_exports = {};
|
|
22
|
+
__export(admin_exports, {
|
|
23
|
+
AdminClient: () => AdminClient,
|
|
24
|
+
ColumnsClient: () => ColumnsClient,
|
|
25
|
+
SchemasClient: () => SchemasClient,
|
|
26
|
+
TablesClient: () => TablesClient
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(admin_exports);
|
|
29
|
+
|
|
30
|
+
// src/admin-validation.ts
|
|
31
|
+
var IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_.]*$/;
|
|
32
|
+
function validateIdentifier(value, label) {
|
|
33
|
+
if (!IDENTIFIER_RE.test(value)) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Invalid ${label}: "${value}". Identifiers must match ${IDENTIFIER_RE.source}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/admin-columns.ts
|
|
41
|
+
var ColumnsClient = class {
|
|
42
|
+
httpClient;
|
|
43
|
+
constructor(httpClient) {
|
|
44
|
+
this.httpClient = httpClient;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a new column on the given table. Sends `POST /v1/meta/columns`.
|
|
48
|
+
*
|
|
49
|
+
* The column name is validated against the standard SQL identifier regex.
|
|
50
|
+
* The `type` field is forwarded as-is to postgres-meta — callers SHOULD
|
|
51
|
+
* restrict types to a known allowlist before calling this.
|
|
52
|
+
*/
|
|
53
|
+
async create(def) {
|
|
54
|
+
validateIdentifier(def.name, "column name");
|
|
55
|
+
const response = await this.httpClient.request("POST", "/v1/meta/columns", {
|
|
56
|
+
body: def
|
|
57
|
+
});
|
|
58
|
+
if (response.error) {
|
|
59
|
+
throw response.error;
|
|
60
|
+
}
|
|
61
|
+
return response.data;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Drop a column. Sends `DELETE /v1/meta/columns/:tableId.:ordinalPosition`.
|
|
65
|
+
*
|
|
66
|
+
* postgres-meta identifies columns by `{tableId}.{ordinalPosition}` (the
|
|
67
|
+
* column's 1-based attnum within its table). Use `TablesClient.get(id)` to
|
|
68
|
+
* find a column id from a column name if needed.
|
|
69
|
+
*/
|
|
70
|
+
async drop(columnId, options) {
|
|
71
|
+
if (!/^\d+\.\d+$/.test(columnId)) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Invalid column id: "${columnId}". Expected format "{tableId}.{ordinalPosition}"`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const params = new URLSearchParams();
|
|
77
|
+
if (options?.cascade) {
|
|
78
|
+
params.set("cascade", "true");
|
|
79
|
+
}
|
|
80
|
+
const queryString = params.toString();
|
|
81
|
+
const path = queryString ? `/v1/meta/columns/${columnId}?${queryString}` : `/v1/meta/columns/${columnId}`;
|
|
82
|
+
const response = await this.httpClient.request("DELETE", path);
|
|
83
|
+
if (response.error) {
|
|
84
|
+
throw response.error;
|
|
85
|
+
}
|
|
86
|
+
return response.data;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/admin-schemas.ts
|
|
91
|
+
var SchemasClient = class {
|
|
92
|
+
httpClient;
|
|
93
|
+
constructor(httpClient) {
|
|
94
|
+
this.httpClient = httpClient;
|
|
95
|
+
}
|
|
96
|
+
async list() {
|
|
97
|
+
const response = await this.httpClient.request("GET", "/v1/meta/schemas");
|
|
98
|
+
if (response.error) {
|
|
99
|
+
throw response.error;
|
|
100
|
+
}
|
|
101
|
+
return response.data ?? [];
|
|
102
|
+
}
|
|
103
|
+
async create(name) {
|
|
104
|
+
validateIdentifier(name, "schema name");
|
|
105
|
+
const response = await this.httpClient.request("POST", "/v1/meta/schemas", {
|
|
106
|
+
body: { name }
|
|
107
|
+
});
|
|
108
|
+
if (response.error) {
|
|
109
|
+
throw response.error;
|
|
110
|
+
}
|
|
111
|
+
return response.data;
|
|
112
|
+
}
|
|
113
|
+
async drop(name, options) {
|
|
114
|
+
validateIdentifier(name, "schema name");
|
|
115
|
+
const schemas = await this.list();
|
|
116
|
+
const schema = schemas.find((s) => s.name === name);
|
|
117
|
+
if (!schema) {
|
|
118
|
+
throw new Error(`Schema "${name}" not found`);
|
|
119
|
+
}
|
|
120
|
+
const params = new URLSearchParams();
|
|
121
|
+
if (options?.cascade) {
|
|
122
|
+
params.set("cascade", "true");
|
|
123
|
+
}
|
|
124
|
+
const queryString = params.toString();
|
|
125
|
+
const path = queryString ? `/v1/meta/schemas/${schema.id}?${queryString}` : `/v1/meta/schemas/${schema.id}`;
|
|
126
|
+
const response = await this.httpClient.request("DELETE", path);
|
|
127
|
+
if (response.error) {
|
|
128
|
+
throw response.error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/admin-tables.ts
|
|
134
|
+
var TablesClient = class {
|
|
135
|
+
httpClient;
|
|
136
|
+
constructor(httpClient) {
|
|
137
|
+
this.httpClient = httpClient;
|
|
138
|
+
}
|
|
139
|
+
async list(options) {
|
|
140
|
+
const params = new URLSearchParams();
|
|
141
|
+
if (options?.schema) {
|
|
142
|
+
validateIdentifier(options.schema, "schema name");
|
|
143
|
+
params.set("included_schemas", options.schema);
|
|
144
|
+
}
|
|
145
|
+
const queryString = params.toString();
|
|
146
|
+
const path = queryString ? `/v1/meta/tables?${queryString}` : "/v1/meta/tables";
|
|
147
|
+
const response = await this.httpClient.request("GET", path);
|
|
148
|
+
if (response.error) {
|
|
149
|
+
throw response.error;
|
|
150
|
+
}
|
|
151
|
+
return response.data ?? [];
|
|
152
|
+
}
|
|
153
|
+
async get(id) {
|
|
154
|
+
const response = await this.httpClient.request("GET", `/v1/meta/tables/${id}`);
|
|
155
|
+
if (response.error) {
|
|
156
|
+
throw response.error;
|
|
157
|
+
}
|
|
158
|
+
return response.data;
|
|
159
|
+
}
|
|
160
|
+
async create(def) {
|
|
161
|
+
validateIdentifier(def.name, "table name");
|
|
162
|
+
if (def.schema) {
|
|
163
|
+
validateIdentifier(def.schema, "schema name");
|
|
164
|
+
}
|
|
165
|
+
const response = await this.httpClient.request("POST", "/v1/meta/tables", {
|
|
166
|
+
body: def
|
|
167
|
+
});
|
|
168
|
+
if (response.error) {
|
|
169
|
+
throw response.error;
|
|
170
|
+
}
|
|
171
|
+
return response.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Apply table-level updates (rename, schema move, RLS toggle, comment, etc).
|
|
175
|
+
* Sends `PATCH /v1/meta/tables/:id`.
|
|
176
|
+
*
|
|
177
|
+
* Note: this does NOT add or drop columns. For column changes, use
|
|
178
|
+
* `ColumnsClient.create()` / `ColumnsClient.drop()`.
|
|
179
|
+
*/
|
|
180
|
+
async update(id, patch) {
|
|
181
|
+
if (patch.name !== void 0) {
|
|
182
|
+
validateIdentifier(patch.name, "table name");
|
|
183
|
+
}
|
|
184
|
+
if (patch.schema !== void 0) {
|
|
185
|
+
validateIdentifier(patch.schema, "schema name");
|
|
186
|
+
}
|
|
187
|
+
if (patch.primary_keys) {
|
|
188
|
+
for (const pk of patch.primary_keys) {
|
|
189
|
+
validateIdentifier(pk.name, "primary key column name");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const response = await this.httpClient.request("PATCH", `/v1/meta/tables/${id}`, {
|
|
193
|
+
body: patch
|
|
194
|
+
});
|
|
195
|
+
if (response.error) {
|
|
196
|
+
throw response.error;
|
|
197
|
+
}
|
|
198
|
+
return response.data;
|
|
199
|
+
}
|
|
200
|
+
async drop(id, options) {
|
|
201
|
+
const params = new URLSearchParams();
|
|
202
|
+
if (options?.cascade) {
|
|
203
|
+
params.set("cascade", "true");
|
|
204
|
+
}
|
|
205
|
+
const queryString = params.toString();
|
|
206
|
+
const path = queryString ? `/v1/meta/tables/${id}?${queryString}` : `/v1/meta/tables/${id}`;
|
|
207
|
+
const response = await this.httpClient.request("DELETE", path);
|
|
208
|
+
if (response.error) {
|
|
209
|
+
throw response.error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/admin-client.ts
|
|
215
|
+
var AdminClient = class {
|
|
216
|
+
schemas;
|
|
217
|
+
tables;
|
|
218
|
+
columns;
|
|
219
|
+
httpClient;
|
|
220
|
+
constructor(httpClient) {
|
|
221
|
+
this.httpClient = httpClient;
|
|
222
|
+
this.schemas = new SchemasClient(httpClient);
|
|
223
|
+
this.tables = new TablesClient(httpClient);
|
|
224
|
+
this.columns = new ColumnsClient(httpClient);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Execute a raw SQL query with full privileges (service role).
|
|
228
|
+
*
|
|
229
|
+
* Always use parameterized queries to prevent SQL injection.
|
|
230
|
+
* Never interpolate user input directly into the SQL string.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* // GOOD — parameterized
|
|
235
|
+
* await admin.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
236
|
+
*
|
|
237
|
+
* // BAD — string interpolation (SQL injection risk)
|
|
238
|
+
* await admin.query(`SELECT * FROM users WHERE id = '${userId}'`);
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
async query(sql, params) {
|
|
242
|
+
const response = await this.httpClient.request("POST", "/v1/meta/query", {
|
|
243
|
+
body: { query: sql, params }
|
|
244
|
+
});
|
|
245
|
+
if (response.error) {
|
|
246
|
+
throw response.error;
|
|
247
|
+
}
|
|
248
|
+
return response.data ?? [];
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
+
0 && (module.exports = {
|
|
253
|
+
AdminClient,
|
|
254
|
+
ColumnsClient,
|
|
255
|
+
SchemasClient,
|
|
256
|
+
TablesClient
|
|
257
|
+
});
|
|
258
|
+
//# sourceMappingURL=admin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/admin.ts","../src/admin-validation.ts","../src/admin-columns.ts","../src/admin-schemas.ts","../src/admin-tables.ts","../src/admin-client.ts"],"sourcesContent":["export { AdminClient } from './admin-client.js';\nexport { ColumnsClient } from './admin-columns.js';\nexport { SchemasClient } from './admin-schemas.js';\nexport { TablesClient } from './admin-tables.js';\nexport type {\n Column,\n ColumnDef,\n CreateColumnDef,\n CreateTableDef,\n Schema,\n Table,\n UpdateTableDef,\n} from './admin-types.js';\n","const IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_.]*$/;\n\nexport function validateIdentifier(value: string, label: string): void {\n if (!IDENTIFIER_RE.test(value)) {\n throw new Error(\n `Invalid ${label}: \"${value}\". Identifiers must match ${IDENTIFIER_RE.source}`,\n );\n }\n}\n","import type { HttpClient } from '@palbase/core';\nimport type { Column, CreateColumnDef } from './admin-types.js';\nimport { validateIdentifier } from './admin-validation.js';\n\n/**\n * Postgres-meta column admin client.\n *\n * Wraps the `/v1/meta/columns` endpoints exposed by postgres-meta.\n * Use this to add or drop columns on an existing table — `TablesClient.update()`\n * does not handle column structure changes.\n */\nexport class ColumnsClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n /**\n * Create a new column on the given table. Sends `POST /v1/meta/columns`.\n *\n * The column name is validated against the standard SQL identifier regex.\n * The `type` field is forwarded as-is to postgres-meta — callers SHOULD\n * restrict types to a known allowlist before calling this.\n */\n async create(def: CreateColumnDef): Promise<Column> {\n validateIdentifier(def.name, 'column name');\n\n const response = await this.httpClient.request<Column>('POST', '/v1/meta/columns', {\n body: def,\n });\n if (response.error) {\n throw response.error;\n }\n return response.data as Column;\n }\n\n /**\n * Drop a column. Sends `DELETE /v1/meta/columns/:tableId.:ordinalPosition`.\n *\n * postgres-meta identifies columns by `{tableId}.{ordinalPosition}` (the\n * column's 1-based attnum within its table). Use `TablesClient.get(id)` to\n * find a column id from a column name if needed.\n */\n async drop(columnId: string, options?: { cascade?: boolean }): Promise<Column> {\n if (!/^\\d+\\.\\d+$/.test(columnId)) {\n throw new Error(\n `Invalid column id: \"${columnId}\". Expected format \"{tableId}.{ordinalPosition}\"`,\n );\n }\n\n const params = new URLSearchParams();\n if (options?.cascade) {\n params.set('cascade', 'true');\n }\n\n const queryString = params.toString();\n const path = queryString\n ? `/v1/meta/columns/${columnId}?${queryString}`\n : `/v1/meta/columns/${columnId}`;\n\n const response = await this.httpClient.request<Column>('DELETE', path);\n if (response.error) {\n throw response.error;\n }\n return response.data as Column;\n }\n}\n","import type { HttpClient } from '@palbase/core';\nimport type { Schema } from './admin-types.js';\nimport { validateIdentifier } from './admin-validation.js';\n\nexport class SchemasClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n async list(): Promise<Schema[]> {\n const response = await this.httpClient.request<Schema[]>('GET', '/v1/meta/schemas');\n if (response.error) {\n throw response.error;\n }\n return response.data ?? [];\n }\n\n async create(name: string): Promise<Schema> {\n validateIdentifier(name, 'schema name');\n\n const response = await this.httpClient.request<Schema>('POST', '/v1/meta/schemas', {\n body: { name },\n });\n if (response.error) {\n throw response.error;\n }\n return response.data as Schema;\n }\n\n async drop(name: string, options?: { cascade?: boolean }): Promise<void> {\n validateIdentifier(name, 'schema name');\n\n // Resolve name to id first\n const schemas = await this.list();\n const schema = schemas.find((s) => s.name === name);\n if (!schema) {\n throw new Error(`Schema \"${name}\" not found`);\n }\n\n const params = new URLSearchParams();\n if (options?.cascade) {\n params.set('cascade', 'true');\n }\n\n const queryString = params.toString();\n const path = queryString\n ? `/v1/meta/schemas/${schema.id}?${queryString}`\n : `/v1/meta/schemas/${schema.id}`;\n\n const response = await this.httpClient.request<void>('DELETE', path);\n if (response.error) {\n throw response.error;\n }\n }\n}\n","import type { HttpClient } from '@palbase/core';\nimport type { CreateTableDef, Table, UpdateTableDef } from './admin-types.js';\nimport { validateIdentifier } from './admin-validation.js';\n\nexport class TablesClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n async list(options?: { schema?: string }): Promise<Table[]> {\n const params = new URLSearchParams();\n if (options?.schema) {\n validateIdentifier(options.schema, 'schema name');\n params.set('included_schemas', options.schema);\n }\n\n const queryString = params.toString();\n const path = queryString ? `/v1/meta/tables?${queryString}` : '/v1/meta/tables';\n\n const response = await this.httpClient.request<Table[]>('GET', path);\n if (response.error) {\n throw response.error;\n }\n return response.data ?? [];\n }\n\n async get(id: number): Promise<Table> {\n const response = await this.httpClient.request<Table>('GET', `/v1/meta/tables/${id}`);\n if (response.error) {\n throw response.error;\n }\n return response.data as Table;\n }\n\n async create(def: CreateTableDef): Promise<Table> {\n validateIdentifier(def.name, 'table name');\n if (def.schema) {\n validateIdentifier(def.schema, 'schema name');\n }\n\n const response = await this.httpClient.request<Table>('POST', '/v1/meta/tables', {\n body: def,\n });\n if (response.error) {\n throw response.error;\n }\n return response.data as Table;\n }\n\n /**\n * Apply table-level updates (rename, schema move, RLS toggle, comment, etc).\n * Sends `PATCH /v1/meta/tables/:id`.\n *\n * Note: this does NOT add or drop columns. For column changes, use\n * `ColumnsClient.create()` / `ColumnsClient.drop()`.\n */\n async update(id: number, patch: UpdateTableDef): Promise<Table> {\n if (patch.name !== undefined) {\n validateIdentifier(patch.name, 'table name');\n }\n if (patch.schema !== undefined) {\n validateIdentifier(patch.schema, 'schema name');\n }\n if (patch.primary_keys) {\n for (const pk of patch.primary_keys) {\n validateIdentifier(pk.name, 'primary key column name');\n }\n }\n\n const response = await this.httpClient.request<Table>('PATCH', `/v1/meta/tables/${id}`, {\n body: patch,\n });\n if (response.error) {\n throw response.error;\n }\n return response.data as Table;\n }\n\n async drop(id: number, options?: { cascade?: boolean }): Promise<void> {\n const params = new URLSearchParams();\n if (options?.cascade) {\n params.set('cascade', 'true');\n }\n\n const queryString = params.toString();\n const path = queryString\n ? `/v1/meta/tables/${id}?${queryString}`\n : `/v1/meta/tables/${id}`;\n\n const response = await this.httpClient.request<void>('DELETE', path);\n if (response.error) {\n throw response.error;\n }\n }\n}\n","import type { HttpClient } from '@palbase/core';\nimport { ColumnsClient } from './admin-columns.js';\nimport { SchemasClient } from './admin-schemas.js';\nimport { TablesClient } from './admin-tables.js';\n\nexport class AdminClient {\n readonly schemas: SchemasClient;\n readonly tables: TablesClient;\n readonly columns: ColumnsClient;\n\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n this.schemas = new SchemasClient(httpClient);\n this.tables = new TablesClient(httpClient);\n this.columns = new ColumnsClient(httpClient);\n }\n\n /**\n * Execute a raw SQL query with full privileges (service role).\n *\n * Always use parameterized queries to prevent SQL injection.\n * Never interpolate user input directly into the SQL string.\n *\n * @example\n * ```ts\n * // GOOD — parameterized\n * await admin.query('SELECT * FROM users WHERE id = $1', [userId]);\n *\n * // BAD — string interpolation (SQL injection risk)\n * await admin.query(`SELECT * FROM users WHERE id = '${userId}'`);\n * ```\n */\n async query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]> {\n const response = await this.httpClient.request<T[]>('POST', '/v1/meta/query', {\n body: { query: sql, params },\n });\n if (response.error) {\n throw response.error;\n }\n return response.data ?? [];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,gBAAgB;AAEf,SAAS,mBAAmB,OAAe,OAAqB;AACrE,MAAI,CAAC,cAAc,KAAK,KAAK,GAAG;AAC9B,UAAM,IAAI;AAAA,MACR,WAAW,KAAK,MAAM,KAAK,6BAA6B,cAAc,MAAM;AAAA,IAC9E;AAAA,EACF;AACF;;;ACGO,IAAM,gBAAN,MAAoB;AAAA,EACR;AAAA,EAEjB,YAAY,YAAwB;AAClC,SAAK,aAAa;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OAAO,KAAuC;AAClD,uBAAmB,IAAI,MAAM,aAAa;AAE1C,UAAM,WAAW,MAAM,KAAK,WAAW,QAAgB,QAAQ,oBAAoB;AAAA,MACjF,MAAM;AAAA,IACR,CAAC;AACD,QAAI,SAAS,OAAO;AAClB,YAAM,SAAS;AAAA,IACjB;AACA,WAAO,SAAS;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,KAAK,UAAkB,SAAkD;AAC7E,QAAI,CAAC,aAAa,KAAK,QAAQ,GAAG;AAChC,YAAM,IAAI;AAAA,QACR,uBAAuB,QAAQ;AAAA,MACjC;AAAA,IACF;AAEA,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,SAAS,SAAS;AACpB,aAAO,IAAI,WAA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AA,MAC5E,MAAM,EAAE,OAAO,KAAK,OAAO;AAAA,IAC7B,CAAC;AACD,QAAI,SAAS,OAAO;AAClB,YAAM,SAAS;AAAA,IACjB;AACA,WAAO,SAAS,QAAQ,CAAC;AAAA,EAC3B;AACF;","names":[]}
|
package/dist/admin.d.cts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { HttpClient } from '@palbase/core';
|
|
2
|
+
|
|
3
|
+
interface Schema {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
owner: string;
|
|
7
|
+
}
|
|
8
|
+
interface Column {
|
|
9
|
+
table_id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
schema: string;
|
|
12
|
+
table: string;
|
|
13
|
+
data_type: string;
|
|
14
|
+
format: string;
|
|
15
|
+
is_identity: boolean;
|
|
16
|
+
identity_generation: string | null;
|
|
17
|
+
is_nullable: boolean;
|
|
18
|
+
is_unique: boolean;
|
|
19
|
+
is_updatable: boolean;
|
|
20
|
+
default_value: string | null;
|
|
21
|
+
enums: string[];
|
|
22
|
+
comment: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface Table {
|
|
25
|
+
id: number;
|
|
26
|
+
schema: string;
|
|
27
|
+
name: string;
|
|
28
|
+
rls_enabled: boolean;
|
|
29
|
+
rls_forced: boolean;
|
|
30
|
+
replica_identity: string;
|
|
31
|
+
bytes: number;
|
|
32
|
+
size: string;
|
|
33
|
+
live_rows_estimate: number;
|
|
34
|
+
dead_rows_estimate: number;
|
|
35
|
+
comment: string | null;
|
|
36
|
+
columns: Column[];
|
|
37
|
+
}
|
|
38
|
+
interface ColumnDef {
|
|
39
|
+
name: string;
|
|
40
|
+
type: string;
|
|
41
|
+
default_value?: string;
|
|
42
|
+
is_identity?: boolean;
|
|
43
|
+
identity_generation?: 'BY DEFAULT' | 'ALWAYS';
|
|
44
|
+
is_nullable?: boolean;
|
|
45
|
+
is_unique?: boolean;
|
|
46
|
+
is_primary_key?: boolean;
|
|
47
|
+
comment?: string;
|
|
48
|
+
}
|
|
49
|
+
interface CreateTableDef {
|
|
50
|
+
name: string;
|
|
51
|
+
schema?: string;
|
|
52
|
+
columns: ColumnDef[];
|
|
53
|
+
comment?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Patch for `TablesClient.update()`. Mirrors postgres-meta's
|
|
57
|
+
* `PATCH /v1/meta/tables/:id` body — table-level fields only.
|
|
58
|
+
*
|
|
59
|
+
* Column add/drop is NOT done here; use `ColumnsClient.create()` /
|
|
60
|
+
* `ColumnsClient.drop()` for that.
|
|
61
|
+
*/
|
|
62
|
+
interface UpdateTableDef {
|
|
63
|
+
name?: string;
|
|
64
|
+
schema?: string;
|
|
65
|
+
rls_enabled?: boolean;
|
|
66
|
+
rls_forced?: boolean;
|
|
67
|
+
replica_identity?: 'DEFAULT' | 'INDEX' | 'FULL' | 'NOTHING';
|
|
68
|
+
replica_identity_index?: string;
|
|
69
|
+
primary_keys?: {
|
|
70
|
+
name: string;
|
|
71
|
+
}[];
|
|
72
|
+
comment?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* New column definition for `ColumnsClient.create()`. Mirrors postgres-meta's
|
|
76
|
+
* `POST /v1/meta/columns` body.
|
|
77
|
+
*/
|
|
78
|
+
interface CreateColumnDef {
|
|
79
|
+
table_id: number;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
default_value?: unknown;
|
|
83
|
+
default_value_format?: 'expression' | 'literal';
|
|
84
|
+
is_identity?: boolean;
|
|
85
|
+
identity_generation?: 'BY DEFAULT' | 'ALWAYS';
|
|
86
|
+
is_nullable?: boolean;
|
|
87
|
+
is_primary_key?: boolean;
|
|
88
|
+
is_unique?: boolean;
|
|
89
|
+
comment?: string;
|
|
90
|
+
check?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Postgres-meta column admin client.
|
|
95
|
+
*
|
|
96
|
+
* Wraps the `/v1/meta/columns` endpoints exposed by postgres-meta.
|
|
97
|
+
* Use this to add or drop columns on an existing table — `TablesClient.update()`
|
|
98
|
+
* does not handle column structure changes.
|
|
99
|
+
*/
|
|
100
|
+
declare class ColumnsClient {
|
|
101
|
+
private readonly httpClient;
|
|
102
|
+
constructor(httpClient: HttpClient);
|
|
103
|
+
/**
|
|
104
|
+
* Create a new column on the given table. Sends `POST /v1/meta/columns`.
|
|
105
|
+
*
|
|
106
|
+
* The column name is validated against the standard SQL identifier regex.
|
|
107
|
+
* The `type` field is forwarded as-is to postgres-meta — callers SHOULD
|
|
108
|
+
* restrict types to a known allowlist before calling this.
|
|
109
|
+
*/
|
|
110
|
+
create(def: CreateColumnDef): Promise<Column>;
|
|
111
|
+
/**
|
|
112
|
+
* Drop a column. Sends `DELETE /v1/meta/columns/:tableId.:ordinalPosition`.
|
|
113
|
+
*
|
|
114
|
+
* postgres-meta identifies columns by `{tableId}.{ordinalPosition}` (the
|
|
115
|
+
* column's 1-based attnum within its table). Use `TablesClient.get(id)` to
|
|
116
|
+
* find a column id from a column name if needed.
|
|
117
|
+
*/
|
|
118
|
+
drop(columnId: string, options?: {
|
|
119
|
+
cascade?: boolean;
|
|
120
|
+
}): Promise<Column>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class SchemasClient {
|
|
124
|
+
private readonly httpClient;
|
|
125
|
+
constructor(httpClient: HttpClient);
|
|
126
|
+
list(): Promise<Schema[]>;
|
|
127
|
+
create(name: string): Promise<Schema>;
|
|
128
|
+
drop(name: string, options?: {
|
|
129
|
+
cascade?: boolean;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class TablesClient {
|
|
134
|
+
private readonly httpClient;
|
|
135
|
+
constructor(httpClient: HttpClient);
|
|
136
|
+
list(options?: {
|
|
137
|
+
schema?: string;
|
|
138
|
+
}): Promise<Table[]>;
|
|
139
|
+
get(id: number): Promise<Table>;
|
|
140
|
+
create(def: CreateTableDef): Promise<Table>;
|
|
141
|
+
/**
|
|
142
|
+
* Apply table-level updates (rename, schema move, RLS toggle, comment, etc).
|
|
143
|
+
* Sends `PATCH /v1/meta/tables/:id`.
|
|
144
|
+
*
|
|
145
|
+
* Note: this does NOT add or drop columns. For column changes, use
|
|
146
|
+
* `ColumnsClient.create()` / `ColumnsClient.drop()`.
|
|
147
|
+
*/
|
|
148
|
+
update(id: number, patch: UpdateTableDef): Promise<Table>;
|
|
149
|
+
drop(id: number, options?: {
|
|
150
|
+
cascade?: boolean;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare class AdminClient {
|
|
155
|
+
readonly schemas: SchemasClient;
|
|
156
|
+
readonly tables: TablesClient;
|
|
157
|
+
readonly columns: ColumnsClient;
|
|
158
|
+
private readonly httpClient;
|
|
159
|
+
constructor(httpClient: HttpClient);
|
|
160
|
+
/**
|
|
161
|
+
* Execute a raw SQL query with full privileges (service role).
|
|
162
|
+
*
|
|
163
|
+
* Always use parameterized queries to prevent SQL injection.
|
|
164
|
+
* Never interpolate user input directly into the SQL string.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* // GOOD — parameterized
|
|
169
|
+
* await admin.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
170
|
+
*
|
|
171
|
+
* // BAD — string interpolation (SQL injection risk)
|
|
172
|
+
* await admin.query(`SELECT * FROM users WHERE id = '${userId}'`);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { AdminClient, type Column, type ColumnDef, ColumnsClient, type CreateColumnDef, type CreateTableDef, type Schema, SchemasClient, type Table, TablesClient, type UpdateTableDef };
|
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { HttpClient } from '@palbase/core';
|
|
2
|
+
|
|
3
|
+
interface Schema {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
owner: string;
|
|
7
|
+
}
|
|
8
|
+
interface Column {
|
|
9
|
+
table_id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
schema: string;
|
|
12
|
+
table: string;
|
|
13
|
+
data_type: string;
|
|
14
|
+
format: string;
|
|
15
|
+
is_identity: boolean;
|
|
16
|
+
identity_generation: string | null;
|
|
17
|
+
is_nullable: boolean;
|
|
18
|
+
is_unique: boolean;
|
|
19
|
+
is_updatable: boolean;
|
|
20
|
+
default_value: string | null;
|
|
21
|
+
enums: string[];
|
|
22
|
+
comment: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface Table {
|
|
25
|
+
id: number;
|
|
26
|
+
schema: string;
|
|
27
|
+
name: string;
|
|
28
|
+
rls_enabled: boolean;
|
|
29
|
+
rls_forced: boolean;
|
|
30
|
+
replica_identity: string;
|
|
31
|
+
bytes: number;
|
|
32
|
+
size: string;
|
|
33
|
+
live_rows_estimate: number;
|
|
34
|
+
dead_rows_estimate: number;
|
|
35
|
+
comment: string | null;
|
|
36
|
+
columns: Column[];
|
|
37
|
+
}
|
|
38
|
+
interface ColumnDef {
|
|
39
|
+
name: string;
|
|
40
|
+
type: string;
|
|
41
|
+
default_value?: string;
|
|
42
|
+
is_identity?: boolean;
|
|
43
|
+
identity_generation?: 'BY DEFAULT' | 'ALWAYS';
|
|
44
|
+
is_nullable?: boolean;
|
|
45
|
+
is_unique?: boolean;
|
|
46
|
+
is_primary_key?: boolean;
|
|
47
|
+
comment?: string;
|
|
48
|
+
}
|
|
49
|
+
interface CreateTableDef {
|
|
50
|
+
name: string;
|
|
51
|
+
schema?: string;
|
|
52
|
+
columns: ColumnDef[];
|
|
53
|
+
comment?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Patch for `TablesClient.update()`. Mirrors postgres-meta's
|
|
57
|
+
* `PATCH /v1/meta/tables/:id` body — table-level fields only.
|
|
58
|
+
*
|
|
59
|
+
* Column add/drop is NOT done here; use `ColumnsClient.create()` /
|
|
60
|
+
* `ColumnsClient.drop()` for that.
|
|
61
|
+
*/
|
|
62
|
+
interface UpdateTableDef {
|
|
63
|
+
name?: string;
|
|
64
|
+
schema?: string;
|
|
65
|
+
rls_enabled?: boolean;
|
|
66
|
+
rls_forced?: boolean;
|
|
67
|
+
replica_identity?: 'DEFAULT' | 'INDEX' | 'FULL' | 'NOTHING';
|
|
68
|
+
replica_identity_index?: string;
|
|
69
|
+
primary_keys?: {
|
|
70
|
+
name: string;
|
|
71
|
+
}[];
|
|
72
|
+
comment?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* New column definition for `ColumnsClient.create()`. Mirrors postgres-meta's
|
|
76
|
+
* `POST /v1/meta/columns` body.
|
|
77
|
+
*/
|
|
78
|
+
interface CreateColumnDef {
|
|
79
|
+
table_id: number;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
default_value?: unknown;
|
|
83
|
+
default_value_format?: 'expression' | 'literal';
|
|
84
|
+
is_identity?: boolean;
|
|
85
|
+
identity_generation?: 'BY DEFAULT' | 'ALWAYS';
|
|
86
|
+
is_nullable?: boolean;
|
|
87
|
+
is_primary_key?: boolean;
|
|
88
|
+
is_unique?: boolean;
|
|
89
|
+
comment?: string;
|
|
90
|
+
check?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Postgres-meta column admin client.
|
|
95
|
+
*
|
|
96
|
+
* Wraps the `/v1/meta/columns` endpoints exposed by postgres-meta.
|
|
97
|
+
* Use this to add or drop columns on an existing table — `TablesClient.update()`
|
|
98
|
+
* does not handle column structure changes.
|
|
99
|
+
*/
|
|
100
|
+
declare class ColumnsClient {
|
|
101
|
+
private readonly httpClient;
|
|
102
|
+
constructor(httpClient: HttpClient);
|
|
103
|
+
/**
|
|
104
|
+
* Create a new column on the given table. Sends `POST /v1/meta/columns`.
|
|
105
|
+
*
|
|
106
|
+
* The column name is validated against the standard SQL identifier regex.
|
|
107
|
+
* The `type` field is forwarded as-is to postgres-meta — callers SHOULD
|
|
108
|
+
* restrict types to a known allowlist before calling this.
|
|
109
|
+
*/
|
|
110
|
+
create(def: CreateColumnDef): Promise<Column>;
|
|
111
|
+
/**
|
|
112
|
+
* Drop a column. Sends `DELETE /v1/meta/columns/:tableId.:ordinalPosition`.
|
|
113
|
+
*
|
|
114
|
+
* postgres-meta identifies columns by `{tableId}.{ordinalPosition}` (the
|
|
115
|
+
* column's 1-based attnum within its table). Use `TablesClient.get(id)` to
|
|
116
|
+
* find a column id from a column name if needed.
|
|
117
|
+
*/
|
|
118
|
+
drop(columnId: string, options?: {
|
|
119
|
+
cascade?: boolean;
|
|
120
|
+
}): Promise<Column>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare class SchemasClient {
|
|
124
|
+
private readonly httpClient;
|
|
125
|
+
constructor(httpClient: HttpClient);
|
|
126
|
+
list(): Promise<Schema[]>;
|
|
127
|
+
create(name: string): Promise<Schema>;
|
|
128
|
+
drop(name: string, options?: {
|
|
129
|
+
cascade?: boolean;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class TablesClient {
|
|
134
|
+
private readonly httpClient;
|
|
135
|
+
constructor(httpClient: HttpClient);
|
|
136
|
+
list(options?: {
|
|
137
|
+
schema?: string;
|
|
138
|
+
}): Promise<Table[]>;
|
|
139
|
+
get(id: number): Promise<Table>;
|
|
140
|
+
create(def: CreateTableDef): Promise<Table>;
|
|
141
|
+
/**
|
|
142
|
+
* Apply table-level updates (rename, schema move, RLS toggle, comment, etc).
|
|
143
|
+
* Sends `PATCH /v1/meta/tables/:id`.
|
|
144
|
+
*
|
|
145
|
+
* Note: this does NOT add or drop columns. For column changes, use
|
|
146
|
+
* `ColumnsClient.create()` / `ColumnsClient.drop()`.
|
|
147
|
+
*/
|
|
148
|
+
update(id: number, patch: UpdateTableDef): Promise<Table>;
|
|
149
|
+
drop(id: number, options?: {
|
|
150
|
+
cascade?: boolean;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare class AdminClient {
|
|
155
|
+
readonly schemas: SchemasClient;
|
|
156
|
+
readonly tables: TablesClient;
|
|
157
|
+
readonly columns: ColumnsClient;
|
|
158
|
+
private readonly httpClient;
|
|
159
|
+
constructor(httpClient: HttpClient);
|
|
160
|
+
/**
|
|
161
|
+
* Execute a raw SQL query with full privileges (service role).
|
|
162
|
+
*
|
|
163
|
+
* Always use parameterized queries to prevent SQL injection.
|
|
164
|
+
* Never interpolate user input directly into the SQL string.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* // GOOD — parameterized
|
|
169
|
+
* await admin.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
170
|
+
*
|
|
171
|
+
* // BAD — string interpolation (SQL injection risk)
|
|
172
|
+
* await admin.query(`SELECT * FROM users WHERE id = '${userId}'`);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { AdminClient, type Column, type ColumnDef, ColumnsClient, type CreateColumnDef, type CreateTableDef, type Schema, SchemasClient, type Table, TablesClient, type UpdateTableDef };
|
package/dist/admin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|