@luckystack/devkit 0.10.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/AGENTS.md +9 -0
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +2 -37
  4. package/dist/{chunk-IWGWJU4M.js → chunk-BJN4XIUX.js} +1 -1
  5. package/dist/{chunk-IWGWJU4M.js.map → chunk-BJN4XIUX.js.map} +1 -1
  6. package/dist/cli/validateDeploy.d.ts +2 -0
  7. package/dist/cli/validateDeploy.js +2 -2
  8. package/dist/cli/validateDeploy.js.map +1 -1
  9. package/dist/functionRegistry.d.ts +72 -0
  10. package/dist/hotReload.d.ts +1 -0
  11. package/dist/importDependencyGraph.d.ts +2 -0
  12. package/dist/index.d.ts +15 -280
  13. package/dist/index.js +558 -431
  14. package/dist/index.js.map +1 -1
  15. package/dist/internal/mapUtils.d.ts +2 -0
  16. package/dist/loader.d.ts +11 -0
  17. package/dist/prismaClientCheck.d.ts +19 -0
  18. package/dist/routeConventions.d.ts +20 -0
  19. package/dist/routeNamingValidation.d.ts +46 -0
  20. package/dist/routingRules.d.ts +62 -0
  21. package/dist/runtimeTypeResolver.d.ts +15 -0
  22. package/dist/supervisor.d.ts +25 -0
  23. package/dist/templateInjector.d.ts +60 -0
  24. package/dist/templateRegistry.d.ts +78 -0
  25. package/dist/typeMap/apiMeta.d.ts +42 -0
  26. package/dist/typeMap/discovery.d.ts +3 -0
  27. package/dist/typeMap/emitterArtifacts.d.ts +94 -0
  28. package/dist/typeMap/extractionDiagnostics.d.ts +16 -0
  29. package/dist/typeMap/extractors.d.ts +18 -0
  30. package/dist/typeMap/functionsMeta.d.ts +5 -0
  31. package/dist/typeMap/routeMeta.d.ts +6 -0
  32. package/dist/typeMap/tsApi.d.ts +12 -0
  33. package/dist/typeMap/tsProgram.d.ts +41 -0
  34. package/dist/typeMap/typeContext.d.ts +21 -0
  35. package/dist/typeMap/zodEmitter.d.ts +8 -0
  36. package/dist/typeMapGenerator.d.ts +5 -0
  37. package/dist/validateDeploy.d.ts +25 -0
  38. package/docs/cli.md +3 -243
  39. package/docs/hot-reload.md +4 -362
  40. package/docs/loader-pipeline.md +3 -322
  41. package/docs/runtime-type-resolver.md +3 -256
  42. package/docs/supervisor.md +3 -290
  43. package/docs/template-customization.md +2 -133
  44. package/docs/ts-program-cache.md +4 -197
  45. package/docs/type-map-generation.md +5 -418
  46. package/package.json +6 -6
  47. package/CLAUDE.md +0 -135
package/dist/index.d.ts CHANGED
@@ -1,280 +1,15 @@
1
- import { ServicesConfigShape, DeployConfigShape } from '@luckystack/core';
2
-
3
- interface GenerateTypeMapOptions {
4
- quiet?: boolean;
5
- }
6
- declare const generateTypeMapFile: (options?: GenerateTypeMapOptions) => void;
7
-
8
- declare const getInputTypeFromFile: (filePath: string) => string;
9
- declare const getSyncClientDataType: (filePath: string) => string;
10
-
11
- declare const API_VERSION_TOKEN_REGEX: RegExp;
12
- declare const SYNC_VERSION_TOKEN_REGEX: RegExp;
13
-
14
- declare const assertValidRouteNaming: ({ srcDir, context, }: {
15
- srcDir: string;
16
- context: string;
17
- }) => void;
18
- declare const assertNoDuplicateNormalizedRouteKeys: ({ srcDir, context, }: {
19
- srcDir: string;
20
- context: string;
21
- }) => void;
22
-
23
- interface FunctionModule {
24
- /**
25
- * Key path under the injected `functions` object. `shared/rbac/engine.ts`
26
- * with root `shared` yields `['rbac', 'engine']`, reachable as
27
- * `functions.rbac.engine`.
28
- */
29
- keyPath: string[];
30
- /** Workspace-relative, forward-slash path to the source file (with `.ts`). */
31
- sourcePath: string;
32
- /** Workspace-relative, forward-slash root directory that claimed this key path. */
33
- rootPath: string;
34
- }
35
- /** Dotted rendering of a key path, e.g. `rbac.engine`. */
36
- declare const formatFunctionKeyPath: (keyPath: string[]) => string;
37
- /**
38
- * Last segment of a key path — the module's file name, which is also the alias
39
- * a default-only export is published under (`functions.sleep.sleep`).
40
- *
41
- * Discovery never produces an empty key path; the guard exists so the callers
42
- * get a real string instead of threading `string | undefined` through every
43
- * emitter.
44
- */
45
- declare const functionModuleFileName: (keyPath: string[]) => string;
46
- declare const formatFunctionKeyConflict: (keyPath: string[], firstSourcePath: string, secondSourcePath: string) => string;
47
- declare const formatFunctionNamespaceConflict: (moduleKeyPath: string[], moduleSourcePath: string, nestedKeyPath: string[], nestedSourcePath: string) => string;
48
- interface CollectFunctionModulesOptions {
49
- /**
50
- * Override the configured roots (absolute paths). Tests pass this;
51
- * production callers omit it and get `getServerFunctionDirs()`.
52
- */
53
- roots?: string[];
54
- /**
55
- * When provided, a collision REPORTS through this callback and the offending
56
- * module is skipped instead of throwing. The dev loader passes it so a
57
- * duplicate does not hard-crash a running dev server; the build-time
58
- * generators omit it so the same duplicate fails the build loudly.
59
- */
60
- onConflict?: (message: string) => void;
61
- }
62
- /**
63
- * Discover every server function module across the configured
64
- * `paths.serverFunctionDirs` roots (default `['functions', 'shared']`), in
65
- * config order, and derive its `functions.*` key path from its location
66
- * relative to the root that owns it.
67
- *
68
- * Throws on a cross-root key collision or a module/namespace collision (unless
69
- * `onConflict` is supplied), so a broken registry fails the BUILD instead of
70
- * producing a map that is silently missing entries at runtime.
71
- */
72
- declare const collectFunctionModules: (options?: CollectFunctionModulesOptions) => FunctionModule[];
73
- interface RenderedFunctionsMap {
74
- /** `import * as fn0 from '...'` lines, in emission order. */
75
- imports: string[];
76
- /** The full `export const functions = { ... };` declaration. */
77
- source: string;
78
- }
79
- /**
80
- * Render discovered modules into the `functions` export of a generated
81
- * production runtime-map file. The emitted object is NESTED, matching what the
82
- * dev loader builds and what `apiTypes.generated.ts` declares.
83
- *
84
- * @param modules Output of {@link collectFunctionModules}.
85
- * @param importPrefix Prefix that turns a workspace-relative source path into a
86
- * specifier relative to the generated file (`'../../'` for
87
- * the standard `server/prod/` output location).
88
- * @param varPrefix Import alias prefix; aliases are `<varPrefix><n>`.
89
- */
90
- declare const renderFunctionsMap: ({ modules, importPrefix, varPrefix, }: {
91
- modules: FunctionModule[];
92
- importPrefix: string;
93
- varPrefix?: string;
94
- }) => RenderedFunctionsMap;
95
-
96
- interface RoutingRules {
97
- /** Folder name that marks an API directory. Default: `_api`. */
98
- apiMarker: string;
99
- /** Folder name that marks a sync directory. Default: `_sync`. */
100
- syncMarker: string;
101
- /** Suffix matcher for API files: must end with `_v<number>.ts`. */
102
- apiVersionRegex: RegExp;
103
- /** Suffix matcher for sync server files: must end with `_server_v<number>.ts`. */
104
- syncServerVersionRegex: RegExp;
105
- /** Suffix matcher for sync client files: must end with `_client_v<number>.ts`. */
106
- syncClientVersionRegex: RegExp;
107
- /** Combined sync regex (server or client). */
108
- syncVersionRegex: RegExp;
109
- /**
110
- * Predicate called for each candidate file/folder during discovery.
111
- * Return `true` to skip. Path is provided as a forward-slash relative
112
- * string from the workspace root (e.g. `src/dashboard/__tests__/foo_v1.ts`).
113
- */
114
- ignore: (relativePath: string) => boolean;
115
- /**
116
- * Single-character prefix that marks a folder as **invisible-parent** for
117
- * page routing: `src/_housing/renting/page.tsx` resolves to `/renting`
118
- * (the `_housing` segment is stripped from the URL). A `page.tsx` placed
119
- * directly inside an `_<name>` folder is invalid (no URL segment left).
120
- *
121
- * Default: `'_'`. Override only if you need a different prefix scheme.
122
- */
123
- privateFolderPrefix: string;
124
- /**
125
- * Folder names that are reserved for framework-internal use and may NEVER
126
- * host a `page.tsx`. Scaffold + page-discovery emit a hard error when a
127
- * page is placed inside one. Extend (do not replace) the defaults if you
128
- * add your own internal folder convention.
129
- *
130
- * Defaults: `_api`, `_sync`, `_function(s)`, `_component(s)`, `_provider(s)`,
131
- * `_locale(s)`, `_socket(s)`, `_shared`, `_server`. The semantic markers
132
- * (`_api`, `_sync`) are also reserved by the API/sync routers.
133
- */
134
- scaffoldIgnoredFolders: string[];
135
- /**
136
- * Optional predicate. Return `true` for a given absolute file path to
137
- * disable template injection entirely for that file. Useful when a
138
- * consumer wants to opt some part of the tree out of the scaffold
139
- * (e.g. `/src/migrations/**` lives by hand). The argument is the
140
- * absolute path the chokidar watcher provides; the predicate is
141
- * called BEFORE the `isInApiFolder` / `isPageFile` checks fire.
142
- */
143
- disableTemplateInjection?: (filePath: string) => boolean;
144
- }
145
- declare const registerRoutingRules: (overrides: Partial<RoutingRules>) => RoutingRules;
146
- declare const getRoutingRules: () => RoutingRules;
147
- declare const apiMarkerSegment: () => string;
148
- declare const syncMarkerSegment: () => string;
149
- declare const isApiFileName: (fileName: string) => boolean;
150
- declare const isSyncServerFileName: (fileName: string) => boolean;
151
- declare const isSyncClientFileName: (fileName: string) => boolean;
152
- declare const isSyncFileName: (fileName: string) => boolean;
153
-
154
- /**
155
- * The six template kinds the framework ships out of the box. Consumers may
156
- * register additional kinds (e.g. `page_marketing`) via `registerTemplateKind`.
157
- */
158
- type BuiltInTemplateKind = 'api' | 'sync_server' | 'sync_client_paired' | 'sync_client_standalone' | 'page_plain' | 'page_dashboard';
159
- type TemplateKind = BuiltInTemplateKind | (string & {});
160
- declare const BUILT_IN_TEMPLATE_KINDS: readonly BuiltInTemplateKind[];
161
- declare const BUILT_IN_TEMPLATE_FILENAMES: Record<BuiltInTemplateKind, string>;
162
- /**
163
- * Structural classification of the file an injection is being computed for.
164
- * `templateInjector.ts` derives this from the folder + filename conventions
165
- * (controlled separately via `registerRoutingRules`). Selection rules match
166
- * against it to choose a template kind.
167
- */
168
- interface TemplateMatchContext {
169
- /** Absolute path of the file being created. */
170
- filePath: string;
171
- /** Structural kind derived from the route conventions. */
172
- fileKind: 'api' | 'sync_server' | 'sync_client' | 'page';
173
- /** For `sync_client`: whether a paired `_server_v<N>.ts` exists on disk. */
174
- hasPairedServer: boolean;
175
- /** Path relative to `src/` (forward slashes), or `null` if outside src. */
176
- srcRelativePath: string | null;
177
- }
178
- /** A single template-selection rule. First matching rule (by priority) wins. */
179
- interface TemplateRule {
180
- kind: TemplateKind;
181
- match: (ctx: TemplateMatchContext) => boolean;
182
- /** Higher runs first. Built-in defaults use 10 (specific) / 0 (catch-all). */
183
- priority: number;
184
- }
185
- interface RegisterTemplateKindOptions {
186
- /** Predicate deciding when this kind is chosen. */
187
- match: (ctx: TemplateMatchContext) => boolean;
188
- /** Optional inline template body (same as calling `registerTemplate`). */
189
- content?: string;
190
- /** Higher runs first. Defaults to 100 so consumer kinds beat the built-ins. */
191
- priority?: number;
192
- }
193
- declare const DEFAULT_DASHBOARD_PATH_PATTERN: RegExp;
194
- /**
195
- * Override the template body for a given kind. Subsequent injections emit the
196
- * supplied content with the standard `{{REL_PATH}}` / `{{PAGE_PATH}}` /
197
- * `{{SYNC_NAME}}` placeholder substitution. Resolution order in the injector
198
- * is: consumer file (`.luckystack/templates/<kind>.template.*`) → this
199
- * override → bundled disk template.
200
- */
201
- declare const registerTemplate: (kind: TemplateKind, content: string) => void;
202
- /** Read the registered content override for a kind, or `null` when none. */
203
- declare const getRegisteredTemplate: (kind: TemplateKind) => string | null;
204
- /** Drop every content override. Test-only. */
205
- declare const clearTemplateOverrides: () => void;
206
- /** Diagnostic: kinds that currently have a content override. */
207
- declare const listRegisteredTemplateKinds: () => readonly TemplateKind[];
208
- /**
209
- * Register a selection rule. Rules are evaluated by descending `priority`,
210
- * ties broken by descending registration order (so a later registration —
211
- * e.g. a consumer overlay — beats an earlier same-priority default).
212
- */
213
- declare const registerTemplateRule: (rule: TemplateRule) => void;
214
- /**
215
- * Register a brand-new template kind: its selection predicate plus (optionally)
216
- * its inline content. Equivalent to `registerTemplateRule` + `registerTemplate`
217
- * in one call. Default priority 100 so custom kinds win over the built-ins.
218
- */
219
- declare const registerTemplateKind: (kind: TemplateKind, options: RegisterTemplateKindOptions) => void;
220
- /** Drop every selection rule (including the built-in defaults). */
221
- declare const clearTemplateRules: () => void;
222
- /** Read the active rules in evaluation order (priority desc, then newest first). */
223
- declare const getTemplateRules: () => readonly TemplateRule[];
224
- /** Evaluate the active rules against a context; returns the first matching kind. */
225
- declare const resolveTemplateKind: (ctx: TemplateMatchContext) => TemplateKind | null;
226
- declare const registerDefaultTemplateRules: () => void;
227
-
228
- declare const devApis: Record<string, unknown>;
229
- declare const devSyncs: Record<string, unknown>;
230
- declare const devFunctions: Record<string, unknown>;
231
- declare const initializeAll: () => Promise<void>;
232
- declare const initializeApis: () => Promise<void>;
233
- declare const upsertApiFromFile: (filePath: string) => Promise<void>;
234
- declare const removeApiFromFile: (filePath: string) => void;
235
- declare const initializeSyncs: () => Promise<void>;
236
- declare const upsertSyncFromFile: (filePath: string) => Promise<void>;
237
- declare const removeSyncFromFile: (filePath: string) => void;
238
- declare const initializeFunctions: () => Promise<void>;
239
-
240
- declare const setupWatchers: () => void;
241
-
242
- type ResolveResult = {
243
- status: 'success';
244
- typeText: string;
245
- } | {
246
- status: 'error';
247
- message: string;
248
- };
249
- declare const clearRuntimeTypeResolverCache: () => void;
250
- declare const resolveRuntimeTypeText: ({ typeText, filePath, }: {
251
- typeText: string;
252
- filePath?: string;
253
- }) => ResolveResult;
254
-
255
- type ValidationSeverity = 'error' | 'warning';
256
- interface ValidationFinding {
257
- severity: ValidationSeverity;
258
- code: string;
259
- message: string;
260
- /** Human-readable location pointer (e.g. `services.config.ts > presets.api`). */
261
- location?: string;
262
- }
263
- interface ValidateDeployInput {
264
- services: ServicesConfigShape;
265
- deploy: DeployConfigShape;
266
- /**
267
- * Environment values to consult for `synchronizedEnvKeys` / `urlEnvKey`
268
- * presence checks. Defaults to `process.env`. Pass a fixture for tests.
269
- */
270
- env?: Record<string, string | undefined>;
271
- }
272
- interface ValidateDeployResult {
273
- ok: boolean;
274
- findings: ValidationFinding[];
275
- errorCount: number;
276
- warningCount: number;
277
- }
278
- declare const validateDeploy: ({ services, deploy, env, }: ValidateDeployInput) => ValidateDeployResult;
279
-
280
- export { API_VERSION_TOKEN_REGEX, BUILT_IN_TEMPLATE_FILENAMES, BUILT_IN_TEMPLATE_KINDS, type BuiltInTemplateKind, type CollectFunctionModulesOptions, DEFAULT_DASHBOARD_PATH_PATTERN, type FunctionModule, type RegisterTemplateKindOptions, type RenderedFunctionsMap, type RoutingRules, SYNC_VERSION_TOKEN_REGEX, type TemplateKind, type TemplateMatchContext, type TemplateRule, type ValidateDeployInput, type ValidateDeployResult, type ValidationFinding, type ValidationSeverity, apiMarkerSegment, assertNoDuplicateNormalizedRouteKeys, assertValidRouteNaming, clearRuntimeTypeResolverCache, clearTemplateOverrides, clearTemplateRules, collectFunctionModules, devApis, devFunctions, devSyncs, formatFunctionKeyConflict, formatFunctionKeyPath, formatFunctionNamespaceConflict, functionModuleFileName, generateTypeMapFile, getInputTypeFromFile, getRegisteredTemplate, getRoutingRules, getSyncClientDataType, getTemplateRules, initializeAll, initializeApis, initializeFunctions, initializeSyncs, isApiFileName, isSyncClientFileName, isSyncFileName, isSyncServerFileName, listRegisteredTemplateKinds, registerDefaultTemplateRules, registerRoutingRules, registerTemplate, registerTemplateKind, registerTemplateRule, removeApiFromFile, removeSyncFromFile, renderFunctionsMap, resolveRuntimeTypeText, resolveTemplateKind, setupWatchers, syncMarkerSegment, upsertApiFromFile, upsertSyncFromFile, validateDeploy };
1
+ export { generateTypeMapFile } from './typeMapGenerator.js';
2
+ export { getInputTypeFromFile, getSyncClientDataType, } from './typeMap/extractors.js';
3
+ export { API_VERSION_TOKEN_REGEX, SYNC_VERSION_TOKEN_REGEX, } from './routeConventions.js';
4
+ export { assertNoDuplicateNormalizedRouteKeys, assertValidRouteNaming, } from './routeNamingValidation.js';
5
+ export { collectFunctionModules, renderFunctionsMap, formatFunctionKeyPath, functionModuleFileName, formatFunctionKeyConflict, formatFunctionNamespaceConflict, } from './functionRegistry.js';
6
+ export type { FunctionModule, RenderedFunctionsMap, CollectFunctionModulesOptions, } from './functionRegistry.js';
7
+ export { registerRoutingRules, getRoutingRules, apiMarkerSegment, syncMarkerSegment, isApiFileName, isSyncFileName, isSyncServerFileName, isSyncClientFileName, } from './routingRules.js';
8
+ export type { RoutingRules } from './routingRules.js';
9
+ export { registerTemplate, getRegisteredTemplate, clearTemplateOverrides, listRegisteredTemplateKinds, registerTemplateRule, registerTemplateKind, clearTemplateRules, getTemplateRules, resolveTemplateKind, registerDefaultTemplateRules, BUILT_IN_TEMPLATE_KINDS, BUILT_IN_TEMPLATE_FILENAMES, DEFAULT_DASHBOARD_PATH_PATTERN, } from './templateRegistry.js';
10
+ export type { TemplateKind, BuiltInTemplateKind, TemplateRule, TemplateMatchContext, RegisterTemplateKindOptions, } from './templateRegistry.js';
11
+ export { devApis, devSyncs, devFunctions, initializeAll, initializeApis, initializeSyncs, initializeFunctions, upsertApiFromFile, removeApiFromFile, upsertSyncFromFile, removeSyncFromFile, } from './loader.js';
12
+ export { setupWatchers } from './hotReload.js';
13
+ export { resolveRuntimeTypeText, clearRuntimeTypeResolverCache } from './runtimeTypeResolver.js';
14
+ export { validateDeploy } from './validateDeploy.js';
15
+ export type { ValidateDeployInput, ValidateDeployResult, ValidationFinding, ValidationSeverity, } from './validateDeploy.js';