bonescript-compiler 0.7.0 → 0.8.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/cli.js +61 -4
- package/dist/cli.js.map +1 -1
- package/dist/emit_full.js +11 -1
- package/dist/emit_full.js.map +1 -1
- package/dist/emit_notify.js +49 -1
- package/dist/emit_notify.js.map +1 -1
- package/dist/emit_react.d.ts +24 -0
- package/dist/emit_react.js +222 -0
- package/dist/emit_react.js.map +1 -0
- package/dist/emit_sqlite.d.ts +33 -0
- package/dist/emit_sqlite.js +539 -0
- package/dist/emit_sqlite.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/test_notify.d.ts +11 -0
- package/dist/test_notify.js +220 -0
- package/dist/test_notify.js.map +1 -0
- package/dist/test_react.d.ts +10 -0
- package/dist/test_react.js +177 -0
- package/dist/test_react.js.map +1 -0
- package/dist/test_sqlite.d.ts +13 -0
- package/dist/test_sqlite.js +262 -0
- package/dist/test_sqlite.js.map +1 -0
- package/package.json +7 -4
- package/src/cli.ts +68 -5
- package/src/emit_full.ts +11 -1
- package/src/emit_notify.ts +49 -1
- package/src/emit_react.ts +236 -0
- package/src/emit_sqlite.ts +562 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BoneScript React Hooks Emitter
|
|
4
|
+
*
|
|
5
|
+
* Generates a typed React hooks file (sdk/react.ts) on top of the existing
|
|
6
|
+
* fetch SDK. Hooks are zero-dep — they use React's built-in useState +
|
|
7
|
+
* useEffect rather than pulling in @tanstack/react-query so consumers can
|
|
8
|
+
* decide their own data layer.
|
|
9
|
+
*
|
|
10
|
+
* For each entity:
|
|
11
|
+
* useList<Entity>() → { data, loading, error, refetch }
|
|
12
|
+
* use<Entity>(id) → { data, loading, error, refetch }
|
|
13
|
+
* useCreate<Entity>() → mutate(input) → Promise<Entity>
|
|
14
|
+
* useUpdate<Entity>() → mutate(id, patch) → Promise<Entity>
|
|
15
|
+
* useDelete<Entity>() → mutate(id) → Promise<void>
|
|
16
|
+
*
|
|
17
|
+
* For each capability:
|
|
18
|
+
* useCapability<Name>() → mutate(input) → Promise<unknown>
|
|
19
|
+
*
|
|
20
|
+
* Hooks are framework-agnostic in shape (no react-query, no SWR) so they work
|
|
21
|
+
* with Next.js, Vite, CRA, or any plain React app.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.emitReactHooks = void 0;
|
|
25
|
+
function toSnakeCase(s) {
|
|
26
|
+
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
function toPascalCase(s) {
|
|
29
|
+
return s.replace(/(^|[-_\s])(\w)/g, (_, __, c) => c.toUpperCase());
|
|
30
|
+
}
|
|
31
|
+
const TS_TYPE_MAP = {
|
|
32
|
+
string: "string", uint: "number", int: "number", float: "number",
|
|
33
|
+
bool: "boolean", timestamp: "string", uuid: "string", bytes: "string", json: "unknown",
|
|
34
|
+
};
|
|
35
|
+
function toTsType(irType) {
|
|
36
|
+
if (TS_TYPE_MAP[irType])
|
|
37
|
+
return TS_TYPE_MAP[irType];
|
|
38
|
+
const m = irType.match(/^(list|set)<(.+)>$/);
|
|
39
|
+
if (m)
|
|
40
|
+
return `${toTsType(m[2])}[]`;
|
|
41
|
+
const om = irType.match(/^optional<(.+)>$/);
|
|
42
|
+
if (om)
|
|
43
|
+
return `${toTsType(om[1])} | null`;
|
|
44
|
+
return irType;
|
|
45
|
+
}
|
|
46
|
+
function emitReactHooks(system) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
lines.push(`// Generated by BoneScript compiler. DO NOT EDIT.`);
|
|
49
|
+
lines.push(`// React hooks for the ${system.name} API.`);
|
|
50
|
+
lines.push(`//`);
|
|
51
|
+
lines.push(`// Pair with sdk/client.ts. Pass an instance of <System>Client to <ApiProvider>.`);
|
|
52
|
+
lines.push(``);
|
|
53
|
+
lines.push(`import { useCallback, useEffect, useState, createContext, useContext, ReactNode, createElement } from "react";`);
|
|
54
|
+
lines.push(``);
|
|
55
|
+
// Entity types (forward-declared so the hooks compile without importing the SDK)
|
|
56
|
+
// We re-declare them here to keep this file independent — the consumer can
|
|
57
|
+
// also import these types from sdk/client.ts if they prefer.
|
|
58
|
+
const apiModules = system.modules.filter(m => m.kind === "api_service" && m.models.length > 0);
|
|
59
|
+
for (const mod of apiModules) {
|
|
60
|
+
const model = mod.models[0];
|
|
61
|
+
lines.push(`export interface ${toPascalCase(model.name)} {`);
|
|
62
|
+
for (const field of model.fields) {
|
|
63
|
+
const optional = field.nullable ? "?" : "";
|
|
64
|
+
lines.push(` ${field.name}${optional}: ${toTsType(field.type)};`);
|
|
65
|
+
}
|
|
66
|
+
lines.push(`}`);
|
|
67
|
+
lines.push(``);
|
|
68
|
+
}
|
|
69
|
+
lines.push(`export interface ApiClient {`);
|
|
70
|
+
lines.push(` baseUrl: string;`);
|
|
71
|
+
lines.push(` getToken: () => string | null;`);
|
|
72
|
+
lines.push(`}`);
|
|
73
|
+
lines.push(``);
|
|
74
|
+
lines.push(`async function apiFetch<T>(client: ApiClient, method: string, path: string, body?: unknown): Promise<T> {`);
|
|
75
|
+
lines.push(` const headers: Record<string, string> = { "Content-Type": "application/json" };`);
|
|
76
|
+
lines.push(` const token = client.getToken();`);
|
|
77
|
+
lines.push(` if (token) headers["Authorization"] = "Bearer " + token;`);
|
|
78
|
+
lines.push(` const res = await fetch(client.baseUrl + path, {`);
|
|
79
|
+
lines.push(` method,`);
|
|
80
|
+
lines.push(` headers,`);
|
|
81
|
+
lines.push(` body: body !== undefined ? JSON.stringify(body) : undefined,`);
|
|
82
|
+
lines.push(` });`);
|
|
83
|
+
lines.push(` if (!res.ok) {`);
|
|
84
|
+
lines.push(` let errMsg = "Request failed: " + res.status;`);
|
|
85
|
+
lines.push(` try { const j = await res.json() as { error?: { message?: string } }; if (j.error?.message) errMsg = j.error.message; } catch {}`);
|
|
86
|
+
lines.push(` throw new Error(errMsg);`);
|
|
87
|
+
lines.push(` }`);
|
|
88
|
+
lines.push(` if (res.status === 204) return undefined as unknown as T;`);
|
|
89
|
+
lines.push(` return await res.json() as T;`);
|
|
90
|
+
lines.push(`}`);
|
|
91
|
+
lines.push(``);
|
|
92
|
+
// Provider + context. createElement avoids needing JSX in this generated file.
|
|
93
|
+
lines.push(`const ApiContext = createContext<ApiClient | null>(null);`);
|
|
94
|
+
lines.push(``);
|
|
95
|
+
lines.push(`export interface ApiProviderProps {`);
|
|
96
|
+
lines.push(` client: ApiClient;`);
|
|
97
|
+
lines.push(` children: ReactNode;`);
|
|
98
|
+
lines.push(`}`);
|
|
99
|
+
lines.push(``);
|
|
100
|
+
lines.push(`export function ApiProvider(props: ApiProviderProps) {`);
|
|
101
|
+
lines.push(` return createElement(ApiContext.Provider, { value: props.client }, props.children);`);
|
|
102
|
+
lines.push(`}`);
|
|
103
|
+
lines.push(``);
|
|
104
|
+
lines.push(`function useApi(): ApiClient {`);
|
|
105
|
+
lines.push(` const ctx = useContext(ApiContext);`);
|
|
106
|
+
lines.push(` if (!ctx) throw new Error("useApi must be used inside <ApiProvider>");`);
|
|
107
|
+
lines.push(` return ctx;`);
|
|
108
|
+
lines.push(`}`);
|
|
109
|
+
lines.push(``);
|
|
110
|
+
// Generic shape helpers
|
|
111
|
+
lines.push(`export interface QueryState<T> {`);
|
|
112
|
+
lines.push(` data: T | null;`);
|
|
113
|
+
lines.push(` loading: boolean;`);
|
|
114
|
+
lines.push(` error: Error | null;`);
|
|
115
|
+
lines.push(` refetch: () => Promise<void>;`);
|
|
116
|
+
lines.push(`}`);
|
|
117
|
+
lines.push(``);
|
|
118
|
+
lines.push(`export interface MutationState<TInput, TOutput> {`);
|
|
119
|
+
lines.push(` mutate: (input: TInput) => Promise<TOutput>;`);
|
|
120
|
+
lines.push(` loading: boolean;`);
|
|
121
|
+
lines.push(` error: Error | null;`);
|
|
122
|
+
lines.push(` reset: () => void;`);
|
|
123
|
+
lines.push(`}`);
|
|
124
|
+
lines.push(``);
|
|
125
|
+
lines.push(`export interface PaginatedResponse<T> {`);
|
|
126
|
+
lines.push(` items: T[];`);
|
|
127
|
+
lines.push(` total: number;`);
|
|
128
|
+
lines.push(` page: number;`);
|
|
129
|
+
lines.push(` page_size: number;`);
|
|
130
|
+
lines.push(`}`);
|
|
131
|
+
lines.push(``);
|
|
132
|
+
// Generic primitive hooks. Specific entity / capability hooks below wrap these.
|
|
133
|
+
lines.push(`function useQueryGeneric<T>(method: string, path: string, deps: unknown[]): QueryState<T> {`);
|
|
134
|
+
lines.push(` const client = useApi();`);
|
|
135
|
+
lines.push(` const [data, setData] = useState<T | null>(null);`);
|
|
136
|
+
lines.push(` const [loading, setLoading] = useState(true);`);
|
|
137
|
+
lines.push(` const [error, setError] = useState<Error | null>(null);`);
|
|
138
|
+
lines.push(` const fetchOnce = useCallback(async () => {`);
|
|
139
|
+
lines.push(` setLoading(true); setError(null);`);
|
|
140
|
+
lines.push(` try { const result = await apiFetch<T>(client, method, path); setData(result); }`);
|
|
141
|
+
lines.push(` catch (e: unknown) { setError(e instanceof Error ? e : new Error(String(e))); }`);
|
|
142
|
+
lines.push(` finally { setLoading(false); }`);
|
|
143
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
144
|
+
lines.push(` }, [client, method, path]);`);
|
|
145
|
+
lines.push(` useEffect(() => { void fetchOnce(); /* eslint-disable-next-line react-hooks/exhaustive-deps */ }, deps);`);
|
|
146
|
+
lines.push(` return { data, loading, error, refetch: fetchOnce };`);
|
|
147
|
+
lines.push(`}`);
|
|
148
|
+
lines.push(``);
|
|
149
|
+
lines.push(`function useMutationGeneric<TInput, TOutput>(builder: (input: TInput) => { method: string; path: string; body?: unknown }): MutationState<TInput, TOutput> {`);
|
|
150
|
+
lines.push(` const client = useApi();`);
|
|
151
|
+
lines.push(` const [loading, setLoading] = useState(false);`);
|
|
152
|
+
lines.push(` const [error, setError] = useState<Error | null>(null);`);
|
|
153
|
+
lines.push(` const mutate = useCallback(async (input: TInput): Promise<TOutput> => {`);
|
|
154
|
+
lines.push(` setLoading(true); setError(null);`);
|
|
155
|
+
lines.push(` try { const req = builder(input); return await apiFetch<TOutput>(client, req.method, req.path, req.body); }`);
|
|
156
|
+
lines.push(` catch (e: unknown) { const err = e instanceof Error ? e : new Error(String(e)); setError(err); throw err; }`);
|
|
157
|
+
lines.push(` finally { setLoading(false); }`);
|
|
158
|
+
lines.push(` }, [client, builder]);`);
|
|
159
|
+
lines.push(` const reset = useCallback(() => setError(null), []);`);
|
|
160
|
+
lines.push(` return { mutate, loading, error, reset };`);
|
|
161
|
+
lines.push(`}`);
|
|
162
|
+
lines.push(``);
|
|
163
|
+
// Per-entity hooks
|
|
164
|
+
for (const mod of apiModules) {
|
|
165
|
+
const model = mod.models[0];
|
|
166
|
+
const entity = toPascalCase(model.name);
|
|
167
|
+
const tableName = toSnakeCase(model.name) + "s";
|
|
168
|
+
const route = `/${tableName}`;
|
|
169
|
+
lines.push(`// ─── ${entity} ───────────────────────────────────────────────────────────`);
|
|
170
|
+
lines.push(``);
|
|
171
|
+
// List
|
|
172
|
+
lines.push(`export function useList${entity}(): QueryState<PaginatedResponse<${entity}>> {`);
|
|
173
|
+
lines.push(` return useQueryGeneric<PaginatedResponse<${entity}>>("GET", "${route}", []);`);
|
|
174
|
+
lines.push(`}`);
|
|
175
|
+
lines.push(``);
|
|
176
|
+
// Read
|
|
177
|
+
lines.push(`export function use${entity}(id: string | null): QueryState<${entity}> {`);
|
|
178
|
+
lines.push(` return useQueryGeneric<${entity}>("GET", id ? \`${route}/\${id}\` : "${route}", [id]);`);
|
|
179
|
+
lines.push(`}`);
|
|
180
|
+
lines.push(``);
|
|
181
|
+
// Create
|
|
182
|
+
const createInputType = `Partial<${entity}>`;
|
|
183
|
+
lines.push(`export function useCreate${entity}(): MutationState<${createInputType}, ${entity}> {`);
|
|
184
|
+
lines.push(` return useMutationGeneric<${createInputType}, ${entity}>((input) => ({ method: "POST", path: "${route}", body: input }));`);
|
|
185
|
+
lines.push(`}`);
|
|
186
|
+
lines.push(``);
|
|
187
|
+
// Update
|
|
188
|
+
lines.push(`export function useUpdate${entity}(): MutationState<{ id: string; patch: Partial<${entity}> }, ${entity}> {`);
|
|
189
|
+
lines.push(` return useMutationGeneric<{ id: string; patch: Partial<${entity}> }, ${entity}>(({ id, patch }) => ({ method: "PUT", path: \`${route}/\${id}\`, body: patch }));`);
|
|
190
|
+
lines.push(`}`);
|
|
191
|
+
lines.push(``);
|
|
192
|
+
// Delete
|
|
193
|
+
lines.push(`export function useDelete${entity}(): MutationState<string, void> {`);
|
|
194
|
+
lines.push(` return useMutationGeneric<string, void>((id) => ({ method: "DELETE", path: \`${route}/\${id}\` }));`);
|
|
195
|
+
lines.push(`}`);
|
|
196
|
+
lines.push(``);
|
|
197
|
+
// Capability hooks
|
|
198
|
+
for (const iface of mod.interfaces) {
|
|
199
|
+
for (const method of iface.methods) {
|
|
200
|
+
if (["create", "read", "update", "delete", "list"].includes(method.name))
|
|
201
|
+
continue;
|
|
202
|
+
const capName = toPascalCase(method.name);
|
|
203
|
+
const inputType = method.input.length > 0
|
|
204
|
+
? `{ ${method.input.map(p => `${p.name}${p.nullable ? "?" : ""}: ${toTsType(p.type)}`).join("; ")} }`
|
|
205
|
+
: "Record<string, never>";
|
|
206
|
+
const endpoint = `${route}/${method.name.replace(/_/g, "-")}`;
|
|
207
|
+
lines.push(`export function useCapability${capName}(): MutationState<${inputType}, unknown> {`);
|
|
208
|
+
lines.push(` return useMutationGeneric<${inputType}, unknown>((input) => ({ method: "POST", path: "${endpoint}", body: input }));`);
|
|
209
|
+
lines.push(`}`);
|
|
210
|
+
lines.push(``);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
path: "sdk/react.ts",
|
|
216
|
+
content: lines.join("\n"),
|
|
217
|
+
language: "typescript",
|
|
218
|
+
source_module: "sdk",
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
exports.emitReactHooks = emitReactHooks;
|
|
222
|
+
//# sourceMappingURL=emit_react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit_react.js","sourceRoot":"","sources":["../src/emit_react.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAKH,SAAS,WAAW,CAAC,CAAS;IAC5B,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7D,CAAC;AAED,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ;IAChE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS;CACvF,CAAC;AAEF,SAAS,QAAQ,CAAC,MAAc;IAC9B,IAAI,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC7C,IAAI,CAAC;QAAE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC5C,IAAI,EAAE;QAAE,OA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BAC9D,KAAK,CAAC,IAAI,CAAC,gCAAgC,OAAO,qBAAqB,SAAS,cAAc,CAAC,CAAC;gBAChG,KAAK,CAAC,IAAI,CAAC,+BAA+B,SAAS,mDAAmD,QAAQ,qBAAqB,CAAC,CAAC;gBACrI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAChB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QACzB,QAAQ,EAAE,YAAY;QACtB,aAAa,EAAE,KAAK;KACrB,CAAC;AACJ,CAAC;AA5LD,wCA4LC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BoneScript SQLite Target Emitter
|
|
3
|
+
*
|
|
4
|
+
* Generates a SQLite-flavored project: same shape as the Express target but
|
|
5
|
+
* with a SQLite type map, no triggers, and the better-sqlite3 driver in place
|
|
6
|
+
* of pg.
|
|
7
|
+
*
|
|
8
|
+
* SQLite differences from PostgreSQL that this emitter handles:
|
|
9
|
+
* - No JSONB / no native UUID — TEXT for both
|
|
10
|
+
* - No CREATE OR REPLACE FUNCTION / no triggers needed (we do updated_at in app code)
|
|
11
|
+
* - Parameter style is ? not $1, $2 — but better-sqlite3 also supports named (:name)
|
|
12
|
+
* - No SKIP LOCKED, no transactional outbox locking semantics — outbox uses simpler ordering
|
|
13
|
+
* - No CHECK constraints with subqueries — basic CHECK only
|
|
14
|
+
*
|
|
15
|
+
* Strategy: keep the SQL flat and portable. Use better-sqlite3's prepared
|
|
16
|
+
* statements. Keep the public interface identical to the Postgres target so
|
|
17
|
+
* route handlers and capability bodies don't need to change.
|
|
18
|
+
*/
|
|
19
|
+
import * as IR from "./ir";
|
|
20
|
+
import { EmittedFile } from "./emitter";
|
|
21
|
+
export declare function toSqliteType(irType: string): string;
|
|
22
|
+
export declare function emitSqliteSchema(model: IR.IRModel, mod: IR.IRModule, system: IR.IRSystem): EmittedFile;
|
|
23
|
+
export declare function emitSqliteOutboxSchema(): string;
|
|
24
|
+
export declare function emitSqliteAuditSchema(): string;
|
|
25
|
+
export declare function emitSqliteDbClient(system: IR.IRSystem): string;
|
|
26
|
+
export declare function emitSqliteMigration(_system: IR.IRSystem, schemas: string[]): string;
|
|
27
|
+
export declare function emitSqlitePackageJson(system: IR.IRSystem): string;
|
|
28
|
+
export declare class SqliteEmitter {
|
|
29
|
+
emit(system: IR.IRSystem): EmittedFile[];
|
|
30
|
+
private emitTsConfig;
|
|
31
|
+
private emitEnvExample;
|
|
32
|
+
private emitReadme;
|
|
33
|
+
}
|