@stardeck-customer-apps/data-store-sdk 0.1.0-preview.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/dist/chunk-7YN3WP4H.mjs +43 -0
- package/dist/cli/generate-types.d.mts +1 -0
- package/dist/cli/generate-types.d.ts +1 -0
- package/dist/cli/generate-types.js +174 -0
- package/dist/cli/generate-types.mjs +151 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +73 -0
- package/dist/index.mjs +14 -0
- package/dist/server/index.d.mts +108 -0
- package/dist/server/index.d.ts +108 -0
- package/dist/server/index.js +265 -0
- package/dist/server/index.mjs +213 -0
- package/dist/types-CqVD-TLQ.d.mts +68 -0
- package/dist/types-CqVD-TLQ.d.ts +68 -0
- package/package.json +65 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var DataStoreError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
statusCode;
|
|
5
|
+
constructor(message, code, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "DataStoreError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var AuthenticationError = class extends DataStoreError {
|
|
13
|
+
constructor(message = "Authentication failed") {
|
|
14
|
+
super(message, "AUTHENTICATION_ERROR", 401);
|
|
15
|
+
this.name = "AuthenticationError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var ForbiddenError = class extends DataStoreError {
|
|
19
|
+
constructor(message = "Insufficient access level") {
|
|
20
|
+
super(message, "FORBIDDEN", 403);
|
|
21
|
+
this.name = "ForbiddenError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var ValidationError = class extends DataStoreError {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message, "VALIDATION_ERROR", 400);
|
|
27
|
+
this.name = "ValidationError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var NotFoundError = class extends DataStoreError {
|
|
31
|
+
constructor(message = "Resource not found") {
|
|
32
|
+
super(message, "NOT_FOUND", 404);
|
|
33
|
+
this.name = "NotFoundError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
DataStoreError,
|
|
39
|
+
AuthenticationError,
|
|
40
|
+
ForbiddenError,
|
|
41
|
+
ValidationError,
|
|
42
|
+
NotFoundError
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/cli/generate-types.ts
|
|
27
|
+
var import_fs = require("fs");
|
|
28
|
+
var import_serverless = require("@neondatabase/serverless");
|
|
29
|
+
var PG_TYPE_MAP = {
|
|
30
|
+
text: "string",
|
|
31
|
+
varchar: "string",
|
|
32
|
+
"character varying": "string",
|
|
33
|
+
char: "string",
|
|
34
|
+
character: "string",
|
|
35
|
+
uuid: "string",
|
|
36
|
+
integer: "number",
|
|
37
|
+
int: "number",
|
|
38
|
+
smallint: "number",
|
|
39
|
+
bigint: "string",
|
|
40
|
+
// bigint as string to avoid precision loss
|
|
41
|
+
numeric: "string",
|
|
42
|
+
decimal: "string",
|
|
43
|
+
real: "number",
|
|
44
|
+
"double precision": "number",
|
|
45
|
+
boolean: "boolean",
|
|
46
|
+
jsonb: "unknown",
|
|
47
|
+
json: "unknown",
|
|
48
|
+
"timestamp with time zone": "Date",
|
|
49
|
+
"timestamp without time zone": "Date",
|
|
50
|
+
timestamp: "Date",
|
|
51
|
+
date: "string",
|
|
52
|
+
time: "string",
|
|
53
|
+
"time with time zone": "string",
|
|
54
|
+
"time without time zone": "string",
|
|
55
|
+
bytea: "Buffer",
|
|
56
|
+
"ARRAY": "unknown[]"
|
|
57
|
+
};
|
|
58
|
+
function pgTypeToTs(pgType) {
|
|
59
|
+
return PG_TYPE_MAP[pgType] ?? "unknown";
|
|
60
|
+
}
|
|
61
|
+
function toPascalCase(name) {
|
|
62
|
+
return name.split("_").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
63
|
+
}
|
|
64
|
+
async function introspectSchema(connectionString) {
|
|
65
|
+
const pool = new import_serverless.Pool({ connectionString });
|
|
66
|
+
try {
|
|
67
|
+
const { rows } = await pool.query(`
|
|
68
|
+
SELECT
|
|
69
|
+
c.table_name,
|
|
70
|
+
c.column_name,
|
|
71
|
+
c.data_type,
|
|
72
|
+
c.is_nullable,
|
|
73
|
+
c.column_default
|
|
74
|
+
FROM information_schema.columns c
|
|
75
|
+
JOIN information_schema.tables t
|
|
76
|
+
ON c.table_name = t.table_name AND c.table_schema = t.table_schema
|
|
77
|
+
WHERE c.table_schema = 'public'
|
|
78
|
+
AND t.table_type = 'BASE TABLE'
|
|
79
|
+
AND t.table_name NOT LIKE '_deleted_%'
|
|
80
|
+
ORDER BY c.table_name, c.ordinal_position
|
|
81
|
+
`);
|
|
82
|
+
const tables = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const row of rows) {
|
|
84
|
+
if (!tables.has(row.table_name)) {
|
|
85
|
+
tables.set(row.table_name, []);
|
|
86
|
+
}
|
|
87
|
+
tables.get(row.table_name).push(row);
|
|
88
|
+
}
|
|
89
|
+
return tables;
|
|
90
|
+
} finally {
|
|
91
|
+
await pool.end();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function generateTypeScript(tables) {
|
|
95
|
+
const lines = [
|
|
96
|
+
"// Auto-generated by @stardeck-customer-apps/data-store-sdk",
|
|
97
|
+
"// Do not edit manually \u2014 regenerate with: npx stardeck-data-store generate-types",
|
|
98
|
+
"",
|
|
99
|
+
'import type { Generated } from "kysely";',
|
|
100
|
+
""
|
|
101
|
+
];
|
|
102
|
+
for (const [tableName, columns] of tables) {
|
|
103
|
+
const interfaceName = toPascalCase(tableName) + "Table";
|
|
104
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
105
|
+
for (const col of columns) {
|
|
106
|
+
const tsType = pgTypeToTs(col.data_type);
|
|
107
|
+
const isGenerated = col.column_default !== null;
|
|
108
|
+
const isNullable = col.is_nullable === "YES";
|
|
109
|
+
let type = tsType;
|
|
110
|
+
if (isNullable) {
|
|
111
|
+
type = `${tsType} | null`;
|
|
112
|
+
}
|
|
113
|
+
if (isGenerated) {
|
|
114
|
+
type = `Generated<${type}>`;
|
|
115
|
+
}
|
|
116
|
+
lines.push(` ${col.column_name}: ${type};`);
|
|
117
|
+
}
|
|
118
|
+
lines.push("}");
|
|
119
|
+
lines.push("");
|
|
120
|
+
}
|
|
121
|
+
lines.push("export interface DB {");
|
|
122
|
+
for (const tableName of tables.keys()) {
|
|
123
|
+
const interfaceName = toPascalCase(tableName) + "Table";
|
|
124
|
+
lines.push(` ${tableName}: ${interfaceName};`);
|
|
125
|
+
}
|
|
126
|
+
lines.push("}");
|
|
127
|
+
lines.push("");
|
|
128
|
+
return lines.join("\n");
|
|
129
|
+
}
|
|
130
|
+
async function main() {
|
|
131
|
+
const args = process.argv.slice(2);
|
|
132
|
+
let connectionString = process.env.DATA_STORE_URL;
|
|
133
|
+
let outputPath = "./src/generated/data-store-types.ts";
|
|
134
|
+
for (let i = 0; i < args.length; i++) {
|
|
135
|
+
if (args[i] === "--connection-string" && args[i + 1]) {
|
|
136
|
+
connectionString = args[++i];
|
|
137
|
+
} else if (args[i] === "--output" && args[i + 1]) {
|
|
138
|
+
outputPath = args[++i];
|
|
139
|
+
} else if (args[i] === "--help") {
|
|
140
|
+
console.log(`Usage: stardeck-data-store generate-types [options]
|
|
141
|
+
|
|
142
|
+
Options:
|
|
143
|
+
--connection-string <url> Postgres connection string (default: DATA_STORE_URL env var)
|
|
144
|
+
--output <path> Output file path (default: ./src/generated/data-store-types.ts)
|
|
145
|
+
--help Show this help message`);
|
|
146
|
+
process.exit(0);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!connectionString) {
|
|
150
|
+
console.error(
|
|
151
|
+
"Error: No connection string provided. Set DATA_STORE_URL or use --connection-string."
|
|
152
|
+
);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
console.log("Introspecting database schema...");
|
|
156
|
+
const tables = await introspectSchema(connectionString);
|
|
157
|
+
if (tables.size === 0) {
|
|
158
|
+
console.log("No tables found in database.");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
console.log(`Found ${tables.size} table(s): ${Array.from(tables.keys()).join(", ")}`);
|
|
162
|
+
const typeScript = generateTypeScript(tables);
|
|
163
|
+
const dir = outputPath.substring(0, outputPath.lastIndexOf("/"));
|
|
164
|
+
if (dir) {
|
|
165
|
+
const { mkdirSync } = await import("fs");
|
|
166
|
+
mkdirSync(dir, { recursive: true });
|
|
167
|
+
}
|
|
168
|
+
(0, import_fs.writeFileSync)(outputPath, typeScript, "utf-8");
|
|
169
|
+
console.log(`Types written to ${outputPath}`);
|
|
170
|
+
}
|
|
171
|
+
main().catch((error) => {
|
|
172
|
+
console.error("Failed to generate types:", error);
|
|
173
|
+
process.exit(1);
|
|
174
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli/generate-types.ts
|
|
4
|
+
import { writeFileSync } from "fs";
|
|
5
|
+
import { Pool } from "@neondatabase/serverless";
|
|
6
|
+
var PG_TYPE_MAP = {
|
|
7
|
+
text: "string",
|
|
8
|
+
varchar: "string",
|
|
9
|
+
"character varying": "string",
|
|
10
|
+
char: "string",
|
|
11
|
+
character: "string",
|
|
12
|
+
uuid: "string",
|
|
13
|
+
integer: "number",
|
|
14
|
+
int: "number",
|
|
15
|
+
smallint: "number",
|
|
16
|
+
bigint: "string",
|
|
17
|
+
// bigint as string to avoid precision loss
|
|
18
|
+
numeric: "string",
|
|
19
|
+
decimal: "string",
|
|
20
|
+
real: "number",
|
|
21
|
+
"double precision": "number",
|
|
22
|
+
boolean: "boolean",
|
|
23
|
+
jsonb: "unknown",
|
|
24
|
+
json: "unknown",
|
|
25
|
+
"timestamp with time zone": "Date",
|
|
26
|
+
"timestamp without time zone": "Date",
|
|
27
|
+
timestamp: "Date",
|
|
28
|
+
date: "string",
|
|
29
|
+
time: "string",
|
|
30
|
+
"time with time zone": "string",
|
|
31
|
+
"time without time zone": "string",
|
|
32
|
+
bytea: "Buffer",
|
|
33
|
+
"ARRAY": "unknown[]"
|
|
34
|
+
};
|
|
35
|
+
function pgTypeToTs(pgType) {
|
|
36
|
+
return PG_TYPE_MAP[pgType] ?? "unknown";
|
|
37
|
+
}
|
|
38
|
+
function toPascalCase(name) {
|
|
39
|
+
return name.split("_").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
40
|
+
}
|
|
41
|
+
async function introspectSchema(connectionString) {
|
|
42
|
+
const pool = new Pool({ connectionString });
|
|
43
|
+
try {
|
|
44
|
+
const { rows } = await pool.query(`
|
|
45
|
+
SELECT
|
|
46
|
+
c.table_name,
|
|
47
|
+
c.column_name,
|
|
48
|
+
c.data_type,
|
|
49
|
+
c.is_nullable,
|
|
50
|
+
c.column_default
|
|
51
|
+
FROM information_schema.columns c
|
|
52
|
+
JOIN information_schema.tables t
|
|
53
|
+
ON c.table_name = t.table_name AND c.table_schema = t.table_schema
|
|
54
|
+
WHERE c.table_schema = 'public'
|
|
55
|
+
AND t.table_type = 'BASE TABLE'
|
|
56
|
+
AND t.table_name NOT LIKE '_deleted_%'
|
|
57
|
+
ORDER BY c.table_name, c.ordinal_position
|
|
58
|
+
`);
|
|
59
|
+
const tables = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
if (!tables.has(row.table_name)) {
|
|
62
|
+
tables.set(row.table_name, []);
|
|
63
|
+
}
|
|
64
|
+
tables.get(row.table_name).push(row);
|
|
65
|
+
}
|
|
66
|
+
return tables;
|
|
67
|
+
} finally {
|
|
68
|
+
await pool.end();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function generateTypeScript(tables) {
|
|
72
|
+
const lines = [
|
|
73
|
+
"// Auto-generated by @stardeck-customer-apps/data-store-sdk",
|
|
74
|
+
"// Do not edit manually \u2014 regenerate with: npx stardeck-data-store generate-types",
|
|
75
|
+
"",
|
|
76
|
+
'import type { Generated } from "kysely";',
|
|
77
|
+
""
|
|
78
|
+
];
|
|
79
|
+
for (const [tableName, columns] of tables) {
|
|
80
|
+
const interfaceName = toPascalCase(tableName) + "Table";
|
|
81
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
82
|
+
for (const col of columns) {
|
|
83
|
+
const tsType = pgTypeToTs(col.data_type);
|
|
84
|
+
const isGenerated = col.column_default !== null;
|
|
85
|
+
const isNullable = col.is_nullable === "YES";
|
|
86
|
+
let type = tsType;
|
|
87
|
+
if (isNullable) {
|
|
88
|
+
type = `${tsType} | null`;
|
|
89
|
+
}
|
|
90
|
+
if (isGenerated) {
|
|
91
|
+
type = `Generated<${type}>`;
|
|
92
|
+
}
|
|
93
|
+
lines.push(` ${col.column_name}: ${type};`);
|
|
94
|
+
}
|
|
95
|
+
lines.push("}");
|
|
96
|
+
lines.push("");
|
|
97
|
+
}
|
|
98
|
+
lines.push("export interface DB {");
|
|
99
|
+
for (const tableName of tables.keys()) {
|
|
100
|
+
const interfaceName = toPascalCase(tableName) + "Table";
|
|
101
|
+
lines.push(` ${tableName}: ${interfaceName};`);
|
|
102
|
+
}
|
|
103
|
+
lines.push("}");
|
|
104
|
+
lines.push("");
|
|
105
|
+
return lines.join("\n");
|
|
106
|
+
}
|
|
107
|
+
async function main() {
|
|
108
|
+
const args = process.argv.slice(2);
|
|
109
|
+
let connectionString = process.env.DATA_STORE_URL;
|
|
110
|
+
let outputPath = "./src/generated/data-store-types.ts";
|
|
111
|
+
for (let i = 0; i < args.length; i++) {
|
|
112
|
+
if (args[i] === "--connection-string" && args[i + 1]) {
|
|
113
|
+
connectionString = args[++i];
|
|
114
|
+
} else if (args[i] === "--output" && args[i + 1]) {
|
|
115
|
+
outputPath = args[++i];
|
|
116
|
+
} else if (args[i] === "--help") {
|
|
117
|
+
console.log(`Usage: stardeck-data-store generate-types [options]
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
--connection-string <url> Postgres connection string (default: DATA_STORE_URL env var)
|
|
121
|
+
--output <path> Output file path (default: ./src/generated/data-store-types.ts)
|
|
122
|
+
--help Show this help message`);
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!connectionString) {
|
|
127
|
+
console.error(
|
|
128
|
+
"Error: No connection string provided. Set DATA_STORE_URL or use --connection-string."
|
|
129
|
+
);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
console.log("Introspecting database schema...");
|
|
133
|
+
const tables = await introspectSchema(connectionString);
|
|
134
|
+
if (tables.size === 0) {
|
|
135
|
+
console.log("No tables found in database.");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
console.log(`Found ${tables.size} table(s): ${Array.from(tables.keys()).join(", ")}`);
|
|
139
|
+
const typeScript = generateTypeScript(tables);
|
|
140
|
+
const dir = outputPath.substring(0, outputPath.lastIndexOf("/"));
|
|
141
|
+
if (dir) {
|
|
142
|
+
const { mkdirSync } = await import("fs");
|
|
143
|
+
mkdirSync(dir, { recursive: true });
|
|
144
|
+
}
|
|
145
|
+
writeFileSync(outputPath, typeScript, "utf-8");
|
|
146
|
+
console.log(`Types written to ${outputPath}`);
|
|
147
|
+
}
|
|
148
|
+
main().catch((error) => {
|
|
149
|
+
console.error("Failed to generate types:", error);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
});
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { C as ColumnDefinition, D as DataStoreClientConfig, F as FilterOperator, L as ListObjectsResult, Q as QueryFilter, b as QueryOptions, c as QueryResult, S as StorageObject, T as TableColumn, a as TableSchema } from './types-CqVD-TLQ.mjs';
|
|
2
|
+
|
|
3
|
+
declare class DataStoreError extends Error {
|
|
4
|
+
code: string;
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(message: string, code: string, statusCode: number);
|
|
7
|
+
}
|
|
8
|
+
declare class AuthenticationError extends DataStoreError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
declare class ForbiddenError extends DataStoreError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
declare class ValidationError extends DataStoreError {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
declare class NotFoundError extends DataStoreError {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { AuthenticationError, DataStoreError, ForbiddenError, NotFoundError, ValidationError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { C as ColumnDefinition, D as DataStoreClientConfig, F as FilterOperator, L as ListObjectsResult, Q as QueryFilter, b as QueryOptions, c as QueryResult, S as StorageObject, T as TableColumn, a as TableSchema } from './types-CqVD-TLQ.js';
|
|
2
|
+
|
|
3
|
+
declare class DataStoreError extends Error {
|
|
4
|
+
code: string;
|
|
5
|
+
statusCode: number;
|
|
6
|
+
constructor(message: string, code: string, statusCode: number);
|
|
7
|
+
}
|
|
8
|
+
declare class AuthenticationError extends DataStoreError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
declare class ForbiddenError extends DataStoreError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
declare class ValidationError extends DataStoreError {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
declare class NotFoundError extends DataStoreError {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { AuthenticationError, DataStoreError, ForbiddenError, NotFoundError, ValidationError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AuthenticationError: () => AuthenticationError,
|
|
24
|
+
DataStoreError: () => DataStoreError,
|
|
25
|
+
ForbiddenError: () => ForbiddenError,
|
|
26
|
+
NotFoundError: () => NotFoundError,
|
|
27
|
+
ValidationError: () => ValidationError
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/errors.ts
|
|
32
|
+
var DataStoreError = class extends Error {
|
|
33
|
+
code;
|
|
34
|
+
statusCode;
|
|
35
|
+
constructor(message, code, statusCode) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "DataStoreError";
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.statusCode = statusCode;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var AuthenticationError = class extends DataStoreError {
|
|
43
|
+
constructor(message = "Authentication failed") {
|
|
44
|
+
super(message, "AUTHENTICATION_ERROR", 401);
|
|
45
|
+
this.name = "AuthenticationError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ForbiddenError = class extends DataStoreError {
|
|
49
|
+
constructor(message = "Insufficient access level") {
|
|
50
|
+
super(message, "FORBIDDEN", 403);
|
|
51
|
+
this.name = "ForbiddenError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var ValidationError = class extends DataStoreError {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message, "VALIDATION_ERROR", 400);
|
|
57
|
+
this.name = "ValidationError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var NotFoundError = class extends DataStoreError {
|
|
61
|
+
constructor(message = "Resource not found") {
|
|
62
|
+
super(message, "NOT_FOUND", 404);
|
|
63
|
+
this.name = "NotFoundError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
AuthenticationError,
|
|
69
|
+
DataStoreError,
|
|
70
|
+
ForbiddenError,
|
|
71
|
+
NotFoundError,
|
|
72
|
+
ValidationError
|
|
73
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { D as DataStoreClientConfig, a as TableSchema, C as ColumnDefinition, b as QueryOptions, c as QueryResult, L as ListObjectsResult } from '../types-CqVD-TLQ.mjs';
|
|
2
|
+
import { KyselyConfig, Kysely } from 'kysely';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Data Store client for server-side use in deployed projects.
|
|
6
|
+
*
|
|
7
|
+
* Provides three capabilities:
|
|
8
|
+
* - Schema management (create/alter tables and columns)
|
|
9
|
+
* - Dynamic queries (read/write data without generated types)
|
|
10
|
+
* - Storage operations (upload/download/list files for storage-type stores)
|
|
11
|
+
*
|
|
12
|
+
* All operations go through the Stardeck platform API with HMAC authentication.
|
|
13
|
+
* For type-safe queries, use Kysely with a direct connection string instead.
|
|
14
|
+
*/
|
|
15
|
+
declare class DataStoreClient {
|
|
16
|
+
private baseUrl;
|
|
17
|
+
private storeId;
|
|
18
|
+
private deploymentSecret;
|
|
19
|
+
private organizationId;
|
|
20
|
+
private projectId;
|
|
21
|
+
private deploymentId;
|
|
22
|
+
private maxRetries;
|
|
23
|
+
private debug;
|
|
24
|
+
constructor(config: DataStoreClientConfig);
|
|
25
|
+
private getEnv;
|
|
26
|
+
private log;
|
|
27
|
+
private getAuthHeader;
|
|
28
|
+
private request;
|
|
29
|
+
getSchema(): Promise<{
|
|
30
|
+
tables: TableSchema[];
|
|
31
|
+
}>;
|
|
32
|
+
createTable(name: string, columns: ColumnDefinition[]): Promise<{
|
|
33
|
+
tableName: string;
|
|
34
|
+
}>;
|
|
35
|
+
addColumn(tableName: string, column: ColumnDefinition): Promise<{
|
|
36
|
+
columnName: string;
|
|
37
|
+
}>;
|
|
38
|
+
updateColumn(tableName: string, columnName: string, changes: {
|
|
39
|
+
newName?: string;
|
|
40
|
+
newType?: string;
|
|
41
|
+
currentType?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
deleteColumn(tableName: string, columnName: string): Promise<{
|
|
46
|
+
deletedAs: string;
|
|
47
|
+
}>;
|
|
48
|
+
query(tableName: string, options?: QueryOptions): Promise<QueryResult>;
|
|
49
|
+
insert(tableName: string, row: Record<string, unknown>): Promise<{
|
|
50
|
+
row: Record<string, unknown>;
|
|
51
|
+
}>;
|
|
52
|
+
update(tableName: string, primaryKey: Record<string, unknown>, column: string, value: unknown): Promise<{
|
|
53
|
+
row: Record<string, unknown>;
|
|
54
|
+
}>;
|
|
55
|
+
delete(tableName: string, primaryKey: Record<string, unknown>): Promise<{
|
|
56
|
+
deleted: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
listFiles(options?: {
|
|
59
|
+
prefix?: string;
|
|
60
|
+
cursor?: string;
|
|
61
|
+
}): Promise<ListObjectsResult>;
|
|
62
|
+
getUploadUrl(key: string, contentType: string, size: number): Promise<{
|
|
63
|
+
uploadUrl: string;
|
|
64
|
+
key: string;
|
|
65
|
+
}>;
|
|
66
|
+
getDownloadUrl(key: string): Promise<{
|
|
67
|
+
downloadUrl: string;
|
|
68
|
+
}>;
|
|
69
|
+
deleteFiles(keys: string[]): Promise<{
|
|
70
|
+
deleted: number;
|
|
71
|
+
}>;
|
|
72
|
+
createFolder(path: string): Promise<{
|
|
73
|
+
key: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare function signDeploymentRequest(deploymentSecret: string, payload: {
|
|
78
|
+
organizationId: string;
|
|
79
|
+
projectId: string;
|
|
80
|
+
deploymentId: string;
|
|
81
|
+
}): string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Kysely instance for direct database access to a data store.
|
|
85
|
+
* Use this for type-safe queries when you have generated types and a connection string.
|
|
86
|
+
*
|
|
87
|
+
* Requires `@neondatabase/serverless` and `kysely-neon` as peer dependencies.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { createDataStore } from "@stardeck-customer-apps/data-store-sdk/server";
|
|
92
|
+
* import type { DB } from "./generated/data-store-types";
|
|
93
|
+
*
|
|
94
|
+
* const db = await createDataStore<DB>();
|
|
95
|
+
*
|
|
96
|
+
* const users = await db
|
|
97
|
+
* .selectFrom("users")
|
|
98
|
+
* .where("status", "=", "active")
|
|
99
|
+
* .selectAll()
|
|
100
|
+
* .execute();
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare function createDataStore<DB>(options?: {
|
|
104
|
+
connectionString?: string;
|
|
105
|
+
kyselyConfig?: Partial<KyselyConfig>;
|
|
106
|
+
}): Promise<Kysely<DB>>;
|
|
107
|
+
|
|
108
|
+
export { DataStoreClient, createDataStore, signDeploymentRequest };
|