@quickback-dev/cli 0.10.2 → 0.10.5
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/commands/compile.d.ts +9 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +56 -16
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/create.js +108 -55
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +22 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/cursor/quickback.mdc +61 -46
- package/dist/docs/content.js +18 -18
- package/dist/docs/content.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/api-client.d.ts +34 -2
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +31 -2
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/api-client.test.js +58 -0
- package/dist/lib/api-client.test.js.map +1 -1
- package/dist/lib/config-sync.d.ts +55 -0
- package/dist/lib/config-sync.d.ts.map +1 -0
- package/dist/lib/config-sync.js +207 -0
- package/dist/lib/config-sync.js.map +1 -0
- package/dist/lib/config-sync.test.d.ts +2 -0
- package/dist/lib/config-sync.test.d.ts.map +1 -0
- package/dist/lib/config-sync.test.js +151 -0
- package/dist/lib/config-sync.test.js.map +1 -0
- package/dist/lib/file-loader.d.ts +39 -5
- package/dist/lib/file-loader.d.ts.map +1 -1
- package/dist/lib/file-loader.js +226 -63
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/lib/file-loader.test.js +212 -1
- package/dist/lib/file-loader.test.js.map +1 -1
- package/dist/lib/prepare-output.d.ts +31 -0
- package/dist/lib/prepare-output.d.ts.map +1 -0
- package/dist/lib/prepare-output.js +95 -0
- package/dist/lib/prepare-output.js.map +1 -0
- package/dist/lib/prepare-output.test.d.ts +2 -0
- package/dist/lib/prepare-output.test.d.ts.map +1 -0
- package/dist/lib/prepare-output.test.js +105 -0
- package/dist/lib/prepare-output.test.js.map +1 -0
- package/dist/lib/sweep-stale.d.ts +25 -0
- package/dist/lib/sweep-stale.d.ts.map +1 -0
- package/dist/lib/sweep-stale.js +179 -0
- package/dist/lib/sweep-stale.js.map +1 -0
- package/dist/lib/sweep-stale.test.d.ts +2 -0
- package/dist/lib/sweep-stale.test.d.ts.map +1 -0
- package/dist/lib/sweep-stale.test.js +130 -0
- package/dist/lib/sweep-stale.test.js.map +1 -0
- package/dist/skill/SKILL.md +327 -103
- package/dist/skill/agents/quickback-specialist/AGENT.md +93 -81
- package/package.json +14 -14
- package/src/cursor/quickback.mdc +61 -46
- package/src/skill/SKILL.md +327 -103
- package/src/skill/agents/quickback-specialist/AGENT.md +93 -81
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-sync.test.d.ts","sourceRoot":"","sources":["../../src/lib/config-sync.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { applySync } from './config-sync.js';
|
|
3
|
+
const NEW_BLOCK = [
|
|
4
|
+
' // [quickback:options-start]',
|
|
5
|
+
' // ── new content ──',
|
|
6
|
+
' // openapi: { generate: true, publish: true },',
|
|
7
|
+
' // [quickback:options-end]',
|
|
8
|
+
].join('\n');
|
|
9
|
+
describe('config-sync applySync', () => {
|
|
10
|
+
// User story: As a Quickback user with an existing config containing the marker block, I need
|
|
11
|
+
// the kitchen-sink to be refreshed wholesale every compile so newly added options surface
|
|
12
|
+
// immediately without me having to upgrade my CLI.
|
|
13
|
+
it('replaces the body between markers without touching surrounding code', () => {
|
|
14
|
+
const original = [
|
|
15
|
+
'export default defineConfig({',
|
|
16
|
+
' name: "demo",',
|
|
17
|
+
' template: "hono",',
|
|
18
|
+
' providers: cloudflare({}),',
|
|
19
|
+
'',
|
|
20
|
+
' // [quickback:options-start]',
|
|
21
|
+
' // outdated content',
|
|
22
|
+
' // foo: { bar: true },',
|
|
23
|
+
' // [quickback:options-end]',
|
|
24
|
+
'});',
|
|
25
|
+
'',
|
|
26
|
+
].join('\n');
|
|
27
|
+
const { text, inserted, skippedReason } = applySync(original, NEW_BLOCK);
|
|
28
|
+
expect(skippedReason).toBeUndefined();
|
|
29
|
+
expect(inserted).toBe(false);
|
|
30
|
+
expect(text).toContain('name: "demo",');
|
|
31
|
+
expect(text).toContain('// ── new content ──');
|
|
32
|
+
expect(text).not.toContain('outdated content');
|
|
33
|
+
// Surrounding lines are preserved verbatim
|
|
34
|
+
expect(text.startsWith('export default defineConfig({')).toBe(true);
|
|
35
|
+
expect(text.endsWith('});\n')).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
// User story: As a Quickback user with a legacy config that pre-dates the marker convention,
|
|
38
|
+
// I need the first compile to insert the marker block automatically just inside the closing
|
|
39
|
+
// }) of defineConfig so I do not have to hand-edit the file.
|
|
40
|
+
it('inserts marker block before the closing `})` when sentinels are absent', () => {
|
|
41
|
+
const original = [
|
|
42
|
+
'export default defineConfig({',
|
|
43
|
+
' name: "demo",',
|
|
44
|
+
' template: "hono",',
|
|
45
|
+
' providers: cloudflare({}),',
|
|
46
|
+
'});',
|
|
47
|
+
'',
|
|
48
|
+
].join('\n');
|
|
49
|
+
const { text, inserted, skippedReason } = applySync(original, NEW_BLOCK);
|
|
50
|
+
expect(skippedReason).toBeUndefined();
|
|
51
|
+
expect(inserted).toBe(true);
|
|
52
|
+
expect(text).toContain('// [quickback:options-start]');
|
|
53
|
+
expect(text).toContain('// [quickback:options-end]');
|
|
54
|
+
// The block sits before the closing brace, not after the file ends
|
|
55
|
+
const blockIdx = text.indexOf('// [quickback:options-start]');
|
|
56
|
+
const closeIdx = text.indexOf('});');
|
|
57
|
+
expect(blockIdx).toBeLessThan(closeIdx);
|
|
58
|
+
});
|
|
59
|
+
// User story: As a Quickback user, I need a no-op compile to not rewrite my config so file
|
|
60
|
+
// mtimes stay stable and editors do not flag a phantom change after every compile.
|
|
61
|
+
it('returns identical text when the block is already up to date', () => {
|
|
62
|
+
const original = [
|
|
63
|
+
'export default defineConfig({',
|
|
64
|
+
' name: "demo",',
|
|
65
|
+
' template: "hono",',
|
|
66
|
+
' providers: cloudflare({}),',
|
|
67
|
+
'',
|
|
68
|
+
' // [quickback:options-start]',
|
|
69
|
+
' // ── new content ──',
|
|
70
|
+
' // openapi: { generate: true, publish: true },',
|
|
71
|
+
' // [quickback:options-end]',
|
|
72
|
+
'});',
|
|
73
|
+
'',
|
|
74
|
+
].join('\n');
|
|
75
|
+
const { text } = applySync(original, NEW_BLOCK);
|
|
76
|
+
expect(text).toBe(original);
|
|
77
|
+
});
|
|
78
|
+
// User story: As a Quickback user who half-deleted the markers by accident, I need the sync
|
|
79
|
+
// step to refuse to rewrite the file rather than guess where the block ends, so I can fix
|
|
80
|
+
// the file by hand without losing surrounding content.
|
|
81
|
+
it('refuses to overwrite when only one sentinel is present', () => {
|
|
82
|
+
const original = [
|
|
83
|
+
'export default defineConfig({',
|
|
84
|
+
' name: "demo",',
|
|
85
|
+
' providers: cloudflare({}),',
|
|
86
|
+
' // [quickback:options-start]',
|
|
87
|
+
' // some leftover content with no end sentinel',
|
|
88
|
+
'});',
|
|
89
|
+
].join('\n');
|
|
90
|
+
const { text, skippedReason } = applySync(original, NEW_BLOCK);
|
|
91
|
+
expect(text).toBe(original);
|
|
92
|
+
expect(skippedReason).toBeDefined();
|
|
93
|
+
expect(skippedReason).toContain('one sentinel');
|
|
94
|
+
});
|
|
95
|
+
// User story: As a Quickback user whose config does not call defineConfig (e.g. a hand-rolled
|
|
96
|
+
// object literal export), I need the sync step to skip rather than corrupt the file.
|
|
97
|
+
it('skips when defineConfig is not present', () => {
|
|
98
|
+
const original = 'export default { name: "demo" };\n';
|
|
99
|
+
const { text, inserted, skippedReason } = applySync(original, NEW_BLOCK);
|
|
100
|
+
expect(text).toBe(original);
|
|
101
|
+
expect(inserted).toBe(false);
|
|
102
|
+
expect(skippedReason).toContain('defineConfig');
|
|
103
|
+
});
|
|
104
|
+
// User story: As a Quickback user whose config has nested parentheses inside provider calls
|
|
105
|
+
// (preset functions, helper expressions, etc.), I need the closing-brace detection to find
|
|
106
|
+
// the *outer* `})` of defineConfig and not stop at the first nested `)`.
|
|
107
|
+
it('matches the outer closing `)` even when defineConfig contains nested calls', () => {
|
|
108
|
+
const original = [
|
|
109
|
+
'export default defineConfig({',
|
|
110
|
+
' name: "demo",',
|
|
111
|
+
' providers: cloudflare({ extras: foo({ bar: 1 }) }),',
|
|
112
|
+
' auth: { roleHierarchy: ["a", "b"] },',
|
|
113
|
+
'});',
|
|
114
|
+
].join('\n');
|
|
115
|
+
const { text, inserted } = applySync(original, NEW_BLOCK);
|
|
116
|
+
expect(inserted).toBe(true);
|
|
117
|
+
// Block should land before the final }) — there is exactly one
|
|
118
|
+
expect(text.indexOf('// [quickback:options-start]')).toBeGreaterThan(text.indexOf('cloudflare('));
|
|
119
|
+
expect(text.indexOf('// [quickback:options-end]')).toBeLessThan(text.indexOf('});'));
|
|
120
|
+
});
|
|
121
|
+
// User story: As a Quickback user, I need parens that appear inside string literals (e.g.
|
|
122
|
+
// a regex-like default value or a Better Auth callback URL with `?redirect=(...)`) to be
|
|
123
|
+
// ignored by the brace counter so the block lands at the real outer closing.
|
|
124
|
+
it('ignores parens inside string literals when finding the outer closing', () => {
|
|
125
|
+
const original = [
|
|
126
|
+
'export default defineConfig({',
|
|
127
|
+
' name: "demo",',
|
|
128
|
+
' auth: { redirect: "/cb?next=(home)" },',
|
|
129
|
+
'});',
|
|
130
|
+
].join('\n');
|
|
131
|
+
const { text, inserted } = applySync(original, NEW_BLOCK);
|
|
132
|
+
expect(inserted).toBe(true);
|
|
133
|
+
// The string literal should not have been treated as a paren scope
|
|
134
|
+
expect(text).toContain('"/cb?next=(home)"');
|
|
135
|
+
});
|
|
136
|
+
// User story: As a Quickback user, I need parens in line comments (e.g. JSDoc-style notes
|
|
137
|
+
// describing example payloads) to be ignored so the block placement is not thrown off by
|
|
138
|
+
// human-friendly commentary.
|
|
139
|
+
it('ignores parens inside line comments when finding the outer closing', () => {
|
|
140
|
+
const original = [
|
|
141
|
+
'export default defineConfig({',
|
|
142
|
+
' name: "demo", // example: defineConfig(legacy)',
|
|
143
|
+
' providers: cloudflare({}),',
|
|
144
|
+
'});',
|
|
145
|
+
].join('\n');
|
|
146
|
+
const { text, inserted } = applySync(original, NEW_BLOCK);
|
|
147
|
+
expect(inserted).toBe(true);
|
|
148
|
+
expect(text).toContain('example: defineConfig(legacy)');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=config-sync.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-sync.test.js","sourceRoot":"","sources":["../../src/lib/config-sync.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,SAAS,GAAG;IAChB,kCAAkC;IAClC,0BAA0B;IAC1B,oDAAoD;IACpD,gCAAgC;CACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,8FAA8F;IAC9F,0FAA0F;IAC1F,mDAAmD;IACnD,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;QAC7E,MAAM,QAAQ,GAAG;YACf,+BAA+B;YAC/B,mBAAmB;YACnB,uBAAuB;YACvB,gCAAgC;YAChC,EAAE;YACF,kCAAkC;YAClC,yBAAyB;YACzB,4BAA4B;YAC5B,gCAAgC;YAChC,KAAK;YACL,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAEzE,MAAM,CAAC,aAAa,CAAC,CAA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A4C;YAC5C,KAAK;SACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAE1D,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,mEAAmE;QACnE,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,0FAA0F;IAC1F,yFAAyF;IACzF,6BAA6B;IAC7B,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;QAC5E,MAAM,QAAQ,GAAG;YACf,+BAA+B;YAC/B,oDAAoD;YACpD,gCAAgC;YAChC,KAAK;SACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAE1D,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,+BAA+B,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -55,7 +55,15 @@ export interface LoadedPageDefinition {
|
|
|
55
55
|
source: string;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* A loaded feature containing one or more tables
|
|
58
|
+
* A loaded feature containing one or more tables.
|
|
59
|
+
*
|
|
60
|
+
* Action authoring uses the one-file-per-action shape exclusively: every
|
|
61
|
+
* action lives in `<feature>/actions/<name>.ts` (or
|
|
62
|
+
* `<feature>/actions/<table>/<name>.ts` for multi-table features) and is
|
|
63
|
+
* AST-parsed compiler-side via the feature-walker discovery + per-action
|
|
64
|
+
* parser. The legacy `defineActions(...)` / `actions.ts` / `_feature.ts` /
|
|
65
|
+
* `handlers/` shapes are retired; the loader rejects them at discovery
|
|
66
|
+
* time with a migration error.
|
|
59
67
|
*/
|
|
60
68
|
export interface LoadedFeature {
|
|
61
69
|
name: string;
|
|
@@ -69,9 +77,18 @@ export interface LoadedFeature {
|
|
|
69
77
|
tables?: LoadedTableDefinition[];
|
|
70
78
|
resource?: any;
|
|
71
79
|
resourceSource?: string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
/**
|
|
81
|
+
* One file per action, AST-parsed by the compiler. Keyed by relative path
|
|
82
|
+
* from the feature root, e.g. `actions/advance.ts` or
|
|
83
|
+
* `actions/profiles/publish.ts`. Each file is `export default defineAction(...)`.
|
|
84
|
+
*/
|
|
85
|
+
actionFiles?: Record<string, string>;
|
|
86
|
+
/**
|
|
87
|
+
* Feature-local `<feature>/lib/` files keyed by relative path
|
|
88
|
+
* (e.g. `lib/inputs.ts`). Copied verbatim into the generated output;
|
|
89
|
+
* action files import them via `../lib/...`.
|
|
90
|
+
*/
|
|
91
|
+
featureLibFiles?: Record<string, string>;
|
|
75
92
|
/** Page definitions from pages/ subdirectory */
|
|
76
93
|
pageFiles?: LoadedPageDefinition[];
|
|
77
94
|
}
|
|
@@ -127,7 +144,12 @@ export interface LoadedServices {
|
|
|
127
144
|
*/
|
|
128
145
|
export declare function loadConfig(configPath: string): Promise<LoadedConfig>;
|
|
129
146
|
/**
|
|
130
|
-
* Load all features from definitions/features
|
|
147
|
+
* Load all features from definitions/features/.
|
|
148
|
+
*
|
|
149
|
+
* After each feature loads, conflicts are batched and thrown as one error
|
|
150
|
+
* block — keeps migration of an existing project to a single round-trip
|
|
151
|
+
* instead of N. The loader emits no warnings; everything that needs the
|
|
152
|
+
* user's attention is an actionable conflict pointing at the migration.
|
|
131
153
|
*/
|
|
132
154
|
export declare function loadFeatures(featuresDir: string): Promise<LoadedFeature[]>;
|
|
133
155
|
/**
|
|
@@ -138,6 +160,18 @@ export declare function findConfigPath(startDir?: string): Promise<string | null
|
|
|
138
160
|
* Find the features directory
|
|
139
161
|
*/
|
|
140
162
|
export declare function findFeaturesDir(startDir?: string): Promise<string | null>;
|
|
163
|
+
/**
|
|
164
|
+
* Load project-level shared lib at `quickback/lib/`.
|
|
165
|
+
*
|
|
166
|
+
* Cross-feature TypeScript that any feature can import via the `~/lib/*`
|
|
167
|
+
* alias. Returns relative paths keyed from `lib/` (e.g. `lib/inputs.ts`)
|
|
168
|
+
* with their source contents. Empty object when the directory is missing.
|
|
169
|
+
*
|
|
170
|
+
* Discipline (enforced compiler-side, not here): files in `quickback/lib/`
|
|
171
|
+
* must not import from `quickback/features/`. Keeps lib genuinely shared
|
|
172
|
+
* and cycle-free.
|
|
173
|
+
*/
|
|
174
|
+
export declare function loadProjectLib(projectRoot: string): Promise<Record<string, string>>;
|
|
141
175
|
/**
|
|
142
176
|
* Find the services directory
|
|
143
177
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-loader.d.ts","sourceRoot":"","sources":["../../src/lib/file-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"file-loader.d.ts","sourceRoot":"","sources":["../../src/lib/file-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+JH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACvC,cAAc,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACxC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC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ACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAWzF;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,QAAQ,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAc9F;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAsB/E;AA8HD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAiDtG"}
|
package/dist/lib/file-loader.js
CHANGED
|
@@ -89,6 +89,27 @@ async function parseTableDefinitions(source) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
// Colocated pattern: `const x = feature("name", …)` followed by `export
|
|
93
|
+
// default x` and a sibling `defineActions(x, …)`. The const is not
|
|
94
|
+
// exported directly, so the export-default-feature path above misses it.
|
|
95
|
+
// Recognize the bare const-feature() form so colocated files where the
|
|
96
|
+
// table needs to be named (so it can be referenced by defineActions in
|
|
97
|
+
// the same file) are still picked up as tables.
|
|
98
|
+
if (ts.isVariableStatement(node)) {
|
|
99
|
+
for (const decl of node.declarationList.declarations) {
|
|
100
|
+
if (ts.isIdentifier(decl.name) &&
|
|
101
|
+
decl.initializer &&
|
|
102
|
+
ts.isCallExpression(decl.initializer) &&
|
|
103
|
+
isFeatureCallee(decl.initializer.expression) &&
|
|
104
|
+
decl.initializer.arguments.length >= 2) {
|
|
105
|
+
const firstArg = decl.initializer.arguments[0];
|
|
106
|
+
if (ts.isStringLiteral(firstArg)) {
|
|
107
|
+
tableNames.push(firstArg.text);
|
|
108
|
+
hasResourceConfig = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
92
113
|
ts.forEachChild(node, visit);
|
|
93
114
|
};
|
|
94
115
|
visit(sourceFile);
|
|
@@ -106,6 +127,14 @@ async function parseTableDefinitions(source) {
|
|
|
106
127
|
tableNames.push(featureMatch[1]);
|
|
107
128
|
hasResourceConfig = true;
|
|
108
129
|
}
|
|
130
|
+
// Colocated pattern: `const x = feature("name", …)` (no `export default`
|
|
131
|
+
// wrapper because the table is bound to a name so a sibling
|
|
132
|
+
// `defineActions(x, …)` in the same file can reference it).
|
|
133
|
+
const constFeatureMatch = source.match(/(?:const|let)\s+\w+\s*=\s*(?:(?:q|qb)\s*\.\s*)?feature\s*\(\s*["']([^"']+)["']/);
|
|
134
|
+
if (constFeatureMatch && !tableNames.includes(constFeatureMatch[1])) {
|
|
135
|
+
tableNames.push(constFeatureMatch[1]);
|
|
136
|
+
hasResourceConfig = true;
|
|
137
|
+
}
|
|
109
138
|
return { tableNames, hasResourceConfig };
|
|
110
139
|
}
|
|
111
140
|
}
|
|
@@ -138,7 +167,12 @@ export async function loadConfig(configPath) {
|
|
|
138
167
|
};
|
|
139
168
|
}
|
|
140
169
|
/**
|
|
141
|
-
* Load all features from definitions/features
|
|
170
|
+
* Load all features from definitions/features/.
|
|
171
|
+
*
|
|
172
|
+
* After each feature loads, conflicts are batched and thrown as one error
|
|
173
|
+
* block — keeps migration of an existing project to a single round-trip
|
|
174
|
+
* instead of N. The loader emits no warnings; everything that needs the
|
|
175
|
+
* user's attention is an actionable conflict pointing at the migration.
|
|
142
176
|
*/
|
|
143
177
|
export async function loadFeatures(featuresDir) {
|
|
144
178
|
if (!(await pathExists(featuresDir))) {
|
|
@@ -153,50 +187,148 @@ export async function loadFeatures(featuresDir) {
|
|
|
153
187
|
const featureDir = join(featuresDir, name);
|
|
154
188
|
results[index] = await loadFeature(name, featureDir);
|
|
155
189
|
});
|
|
156
|
-
|
|
190
|
+
const loaded = results.filter((f) => Boolean(f));
|
|
191
|
+
// Surface every retired-shape conflict in one batched error block — saves
|
|
192
|
+
// users a "fix one, recompile, fix the next" papercut loop.
|
|
193
|
+
const allConflicts = loaded.flatMap((f) => f.conflicts);
|
|
194
|
+
if (allConflicts.length > 0) {
|
|
195
|
+
const lines = allConflicts.map((c) => ` • [${c.feature}] ${c.message}\n ${c.paths.map((p) => `- ${p}`).join('\n ')}`);
|
|
196
|
+
throw new Error(`Action discovery found ${allConflicts.length} conflict(s):\n${lines.join('\n')}\n\n` +
|
|
197
|
+
`Resolve all of the above and recompile.`);
|
|
198
|
+
}
|
|
199
|
+
return loaded.map((f) => f.feature);
|
|
157
200
|
}
|
|
158
201
|
/**
|
|
159
|
-
*
|
|
202
|
+
* Recursively walk a directory and collect every `.ts` file as
|
|
203
|
+
* `{ relativePath: source }`. The relative path includes the prefix dir name
|
|
204
|
+
* (e.g. `handlers/profiles/publish.ts`), preserved so the compiler can mirror
|
|
205
|
+
* the directory layout in the generated output.
|
|
206
|
+
*/
|
|
207
|
+
async function walkRecursiveTs(rootDir, prefix) {
|
|
208
|
+
if (!(await pathExists(rootDir)))
|
|
209
|
+
return {};
|
|
210
|
+
const collected = {};
|
|
211
|
+
async function walk(currentDir, relPrefix) {
|
|
212
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
213
|
+
const tsFiles = entries.filter((e) => e.isFile() && e.name.endsWith('.ts'));
|
|
214
|
+
const subdirs = entries.filter((e) => e.isDirectory());
|
|
215
|
+
if (tsFiles.length > 0) {
|
|
216
|
+
await runWithLimit(tsFiles, READ_CONCURRENCY, async (entry) => {
|
|
217
|
+
const key = `${relPrefix}/${entry.name}`;
|
|
218
|
+
collected[key] = await fs.readFile(join(currentDir, entry.name), 'utf-8');
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
for (const sub of subdirs) {
|
|
222
|
+
await walk(join(currentDir, sub.name), `${relPrefix}/${sub.name}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
await walk(rootDir, prefix);
|
|
226
|
+
return collected;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Filename patterns that belonged to the retired `defineActions(...)` shape.
|
|
230
|
+
* Each match is rejected at load time with a migration error pointing the
|
|
231
|
+
* user at the new per-file `actions/<name>.ts` layout.
|
|
232
|
+
*/
|
|
233
|
+
const RETIRED_FILENAME_PATTERNS = [
|
|
234
|
+
/-actions\.ts$/, // e.g. `profiles-actions.ts`
|
|
235
|
+
/\.actions\.ts$/, // e.g. `episodes.actions.ts`
|
|
236
|
+
];
|
|
237
|
+
/**
|
|
238
|
+
* Load a single feature from its directory.
|
|
160
239
|
*
|
|
161
|
-
*
|
|
240
|
+
* Action authoring is one file per action under `<feature>/actions/`. The
|
|
241
|
+
* loader rejects every retired primitive at discovery time so the user
|
|
242
|
+
* gets a single batched migration error instead of a downstream compiler
|
|
243
|
+
* surprise:
|
|
244
|
+
*
|
|
245
|
+
* - `actions.ts` — bundled actions, retired
|
|
246
|
+
* - `_feature.ts` — preamble + tableless actions, retired
|
|
247
|
+
* - `handlers/` — string-ref handler files, retired
|
|
248
|
+
* - colocated `defineActions(` inside any feature-root `*.ts`, retired
|
|
249
|
+
* - `actions/<flat>.ts` containing `defineActions(`, retired
|
|
250
|
+
* - `*-actions.ts` / `*.actions.ts` filename patterns, retired
|
|
162
251
|
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
252
|
+
* Returns the loaded feature alongside any discovered conflicts; the
|
|
253
|
+
* caller (`loadFeatures`) batches these across all features before
|
|
254
|
+
* failing.
|
|
165
255
|
*/
|
|
166
256
|
async function loadFeature(name, dir) {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
257
|
+
const conflicts = [];
|
|
258
|
+
const migrate = (msg) => `${msg} See https://docs.quickback.dev/compiler/definitions/actions for the new shape.`;
|
|
259
|
+
// ── Reject retired root-level files / colocated `defineActions(` ────────────
|
|
260
|
+
const rootEntries = await fs.readdir(dir, { withFileTypes: true });
|
|
261
|
+
const rootTsFiles = rootEntries.filter((e) => e.isFile() && e.name.endsWith('.ts'));
|
|
262
|
+
for (const entry of rootTsFiles) {
|
|
263
|
+
if (entry.name === 'actions.ts') {
|
|
264
|
+
conflicts.push({
|
|
265
|
+
feature: name,
|
|
266
|
+
message: migrate('Bundled `actions.ts` is retired. Move each entry to its own file under `actions/<name>.ts` ' +
|
|
267
|
+
'using `export default defineAction({...})`.'),
|
|
268
|
+
paths: [join(dir, 'actions.ts')],
|
|
269
|
+
});
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (entry.name === '_feature.ts') {
|
|
273
|
+
conflicts.push({
|
|
274
|
+
feature: name,
|
|
275
|
+
message: migrate('`_feature.ts` is retired. Move shared schemas/helpers to `<feature>/lib/` and tableless ' +
|
|
276
|
+
'actions to `actions/<name>.ts`.'),
|
|
277
|
+
paths: [join(dir, '_feature.ts')],
|
|
184
278
|
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (RETIRED_FILENAME_PATTERNS.some((re) => re.test(entry.name))) {
|
|
282
|
+
conflicts.push({
|
|
283
|
+
feature: name,
|
|
284
|
+
message: migrate(`Filename pattern \`${entry.name}\` is retired. Move action definitions to per-file form ` +
|
|
285
|
+
`under \`actions/<name>.ts\`.`),
|
|
286
|
+
paths: [join(dir, entry.name)],
|
|
287
|
+
});
|
|
288
|
+
continue;
|
|
185
289
|
}
|
|
290
|
+
const filePath = join(dir, entry.name);
|
|
291
|
+
const src = await fs.readFile(filePath, 'utf-8');
|
|
292
|
+
if (src.includes('defineActions(')) {
|
|
293
|
+
conflicts.push({
|
|
294
|
+
feature: name,
|
|
295
|
+
message: migrate(`Colocated \`defineActions(...)\` inside \`${entry.name}\` is retired. Move each action ` +
|
|
296
|
+
`to its own \`actions/<name>.ts\` file with \`export default defineAction({...})\`. The ` +
|
|
297
|
+
`table file should hold only \`defineTable(...)\`.`),
|
|
298
|
+
paths: [filePath],
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// ── Reject retired handlers/ directory ──────────────────────────────────────
|
|
303
|
+
if (await pathExists(join(dir, 'handlers'))) {
|
|
304
|
+
conflicts.push({
|
|
305
|
+
feature: name,
|
|
306
|
+
message: migrate('`handlers/` directory is retired. Inline the `execute` body in each `actions/<name>.ts` ' +
|
|
307
|
+
'file or import shared helpers from `<feature>/lib/`.'),
|
|
308
|
+
paths: [join(dir, 'handlers')],
|
|
309
|
+
});
|
|
186
310
|
}
|
|
187
|
-
//
|
|
311
|
+
// ── Walk actions/ — every `.ts` file is a per-action source ─────────────────
|
|
312
|
+
const actionFiles = {};
|
|
188
313
|
const actionsDir = join(dir, 'actions');
|
|
189
314
|
if (await pathExists(actionsDir)) {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
315
|
+
const allActionFiles = await walkRecursiveTs(actionsDir, 'actions');
|
|
316
|
+
for (const [relativePath, src] of Object.entries(allActionFiles)) {
|
|
317
|
+
if (src.includes('defineActions(')) {
|
|
318
|
+
conflicts.push({
|
|
319
|
+
feature: name,
|
|
320
|
+
message: migrate(`\`${relativePath}\` uses the retired \`defineActions(...)\` (plural). Convert each entry ` +
|
|
321
|
+
`to \`actions/<name>.ts\` with \`export default defineAction({...})\` (singular).`),
|
|
322
|
+
paths: [join(dir, relativePath)],
|
|
323
|
+
});
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
actionFiles[relativePath] = src;
|
|
197
327
|
}
|
|
198
328
|
}
|
|
199
|
-
//
|
|
329
|
+
// ── Walk lib/ — feature-local helpers ───────────────────────────────────────
|
|
330
|
+
const libFiles = await walkRecursiveTs(join(dir, 'lib'), 'lib');
|
|
331
|
+
// ── Pages discovery ─────────────────────────────────────────────────────────
|
|
200
332
|
let pageFiles;
|
|
201
333
|
const pagesDir = join(dir, 'pages');
|
|
202
334
|
if (await pathExists(pagesDir)) {
|
|
@@ -208,7 +340,6 @@ async function loadFeature(name, dir) {
|
|
|
208
340
|
const source = await fs.readFile(join(pagesDir, entry.name), 'utf-8');
|
|
209
341
|
if (!source.includes('definePage'))
|
|
210
342
|
return;
|
|
211
|
-
// Extract slug, title, feature from source
|
|
212
343
|
const slugMatch = source.match(/slug\s*:\s*['"]([^'"]+)['"]/);
|
|
213
344
|
const titleMatch = source.match(/title\s*:\s*['"]([^'"]+)['"]/);
|
|
214
345
|
const featureMatch = source.match(/feature\s*:\s*['"]([^'"]+)['"]/);
|
|
@@ -226,19 +357,42 @@ async function loadFeature(name, dir) {
|
|
|
226
357
|
pageFiles = undefined;
|
|
227
358
|
}
|
|
228
359
|
}
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
360
|
+
// ── Bail early if any retired primitive was hit ─────────────────────────────
|
|
361
|
+
// The conflicts get batched into one error block by `loadFeatures`, so don't
|
|
362
|
+
// try to also discover tables (a legacy table file with colocated
|
|
363
|
+
// `defineActions` still has a real `defineTable`; surfacing it as "loaded"
|
|
364
|
+
// alongside the retired-shape conflict would mislead).
|
|
365
|
+
if (conflicts.length > 0) {
|
|
366
|
+
return {
|
|
367
|
+
feature: { name, schema: { tableName: name, columns: {}, source: '' } },
|
|
368
|
+
conflicts,
|
|
369
|
+
};
|
|
233
370
|
}
|
|
234
|
-
|
|
371
|
+
// ── Tables discovery ────────────────────────────────────────────────────────
|
|
372
|
+
const feature = await loadFeatureTables(name, dir);
|
|
373
|
+
if (!feature)
|
|
374
|
+
return null;
|
|
375
|
+
feature.pageFiles = pageFiles;
|
|
376
|
+
if (Object.keys(actionFiles).length > 0)
|
|
377
|
+
feature.actionFiles = actionFiles;
|
|
378
|
+
if (Object.keys(libFiles).length > 0)
|
|
379
|
+
feature.featureLibFiles = libFiles;
|
|
380
|
+
return { feature, conflicts };
|
|
235
381
|
}
|
|
236
382
|
/**
|
|
237
|
-
* Load feature tables from defineTable() definitions
|
|
383
|
+
* Load feature tables from defineTable() definitions.
|
|
384
|
+
*
|
|
385
|
+
* Tableless features (feature dir with only `actions/` and `lib/`) are
|
|
386
|
+
* still valid — the caller wires their `actionFiles` / `featureLibFiles`
|
|
387
|
+
* onto the returned shell. Calling this with a feature that has neither
|
|
388
|
+
* tables nor any actions returns `null`, which the upstream walker
|
|
389
|
+
* surfaces as a warning.
|
|
238
390
|
*/
|
|
239
|
-
async function loadFeatureTables(name, dir
|
|
391
|
+
async function loadFeatureTables(name, dir) {
|
|
240
392
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
241
|
-
const files = entries.filter((e) => e.isFile() &&
|
|
393
|
+
const files = entries.filter((e) => e.isFile() &&
|
|
394
|
+
e.name.endsWith('.ts') &&
|
|
395
|
+
!RETIRED_FILENAME_PATTERNS.some((re) => re.test(e.name)));
|
|
242
396
|
// Use index-based results to preserve deterministic file ordering
|
|
243
397
|
const results = new Array(files.length);
|
|
244
398
|
await runWithLimit(files.map((entry, index) => ({ entry, index })), READ_CONCURRENCY, async ({ entry, index }) => {
|
|
@@ -266,26 +420,14 @@ async function loadFeatureTables(name, dir, actionsSource, handlerFiles) {
|
|
|
266
420
|
}
|
|
267
421
|
const tables = results.filter(Boolean).flat();
|
|
268
422
|
if (tables.length === 0) {
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
handlerFiles,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
// The walker didn't find a `q.table()` / `sqliteTable()` / `pgTable()` /
|
|
281
|
-
// `defineTable()` / `feature()` call in any `.ts` file in this folder.
|
|
282
|
-
// The CLI reads every file in the dir by default; the filename is
|
|
283
|
-
// free-form. Most likely cause: the folder is empty / scaffolded but not
|
|
284
|
-
// filled in, or the tables use an unrecognized callee.
|
|
285
|
-
console.warn(`Feature ${name}: no table exports detected in any .ts file. ` +
|
|
286
|
-
`Add a \`feature("${name}", { … })\` or \`defineTable(…)\` default export to expose CRUD routes, ` +
|
|
287
|
-
`or add an \`actions.ts\` if this feature is actions-only. Skipping.`);
|
|
288
|
-
return null;
|
|
423
|
+
// Tableless feature — caller decides whether `actionFiles` will be
|
|
424
|
+
// populated. Returning a shell preserves the actions-only path.
|
|
425
|
+
return {
|
|
426
|
+
name,
|
|
427
|
+
schema: undefined,
|
|
428
|
+
tables: [],
|
|
429
|
+
resourceSource: undefined,
|
|
430
|
+
};
|
|
289
431
|
}
|
|
290
432
|
// Use first table as "primary" for backward compatibility
|
|
291
433
|
const primaryTable = tables[0];
|
|
@@ -299,8 +441,6 @@ async function loadFeatureTables(name, dir, actionsSource, handlerFiles) {
|
|
|
299
441
|
tables,
|
|
300
442
|
// Resource config comes from defineTable()
|
|
301
443
|
resourceSource: primaryTable.hasResourceConfig ? primaryTable.source : undefined,
|
|
302
|
-
actionsSource,
|
|
303
|
-
handlerFiles,
|
|
304
444
|
};
|
|
305
445
|
}
|
|
306
446
|
/**
|
|
@@ -377,6 +517,29 @@ export async function findFeaturesDir(startDir = process.cwd()) {
|
|
|
377
517
|
}
|
|
378
518
|
return null;
|
|
379
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Load project-level shared lib at `quickback/lib/`.
|
|
522
|
+
*
|
|
523
|
+
* Cross-feature TypeScript that any feature can import via the `~/lib/*`
|
|
524
|
+
* alias. Returns relative paths keyed from `lib/` (e.g. `lib/inputs.ts`)
|
|
525
|
+
* with their source contents. Empty object when the directory is missing.
|
|
526
|
+
*
|
|
527
|
+
* Discipline (enforced compiler-side, not here): files in `quickback/lib/`
|
|
528
|
+
* must not import from `quickback/features/`. Keeps lib genuinely shared
|
|
529
|
+
* and cycle-free.
|
|
530
|
+
*/
|
|
531
|
+
export async function loadProjectLib(projectRoot) {
|
|
532
|
+
const candidates = [
|
|
533
|
+
join(projectRoot, 'quickback', 'lib'),
|
|
534
|
+
join(projectRoot, 'lib'), // when invoked from inside the quickback/ dir
|
|
535
|
+
];
|
|
536
|
+
for (const candidate of candidates) {
|
|
537
|
+
if (await pathExists(candidate)) {
|
|
538
|
+
return walkRecursiveTs(candidate, 'lib');
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return {};
|
|
542
|
+
}
|
|
380
543
|
/**
|
|
381
544
|
* Find the services directory
|
|
382
545
|
*/
|