@webstir-io/webstir-backend 0.1.15 → 0.1.16
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/README.md +106 -79
- package/dist/add.d.ts +59 -0
- package/dist/add.js +626 -0
- package/dist/build/artifacts.d.ts +115 -1
- package/dist/build/artifacts.js +4 -4
- package/dist/build/entries.js +1 -1
- package/dist/build/pipeline.d.ts +33 -1
- package/dist/build/pipeline.js +307 -65
- package/dist/cache/diff.js +9 -8
- package/dist/cache/reporters.js +1 -1
- package/dist/deploy-cli.d.ts +2 -0
- package/dist/deploy-cli.js +86 -0
- package/dist/diagnostics/summary.js +2 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/manifest/pipeline.js +103 -32
- package/dist/provider.js +35 -17
- package/dist/runtime/bun.d.ts +51 -0
- package/dist/runtime/bun.js +499 -0
- package/dist/runtime/core.d.ts +141 -0
- package/dist/runtime/core.js +316 -0
- package/dist/runtime/deploy-backend.d.ts +20 -0
- package/dist/runtime/deploy-backend.js +175 -0
- package/dist/runtime/deploy-shared.d.ts +43 -0
- package/dist/runtime/deploy-shared.js +75 -0
- package/dist/runtime/deploy-static.d.ts +2 -0
- package/dist/runtime/deploy-static.js +161 -0
- package/dist/runtime/deploy.d.ts +3 -0
- package/dist/runtime/deploy.js +91 -0
- package/dist/runtime/forms.d.ts +73 -0
- package/dist/runtime/forms.js +236 -0
- package/dist/runtime/request-hooks.d.ts +47 -0
- package/dist/runtime/request-hooks.js +102 -0
- package/dist/runtime/session-metadata.d.ts +13 -0
- package/dist/runtime/session-metadata.js +98 -0
- package/dist/runtime/session-runtime.d.ts +28 -0
- package/dist/runtime/session-runtime.js +180 -0
- package/dist/runtime/session.d.ts +83 -0
- package/dist/runtime/session.js +396 -0
- package/dist/runtime/views.d.ts +74 -0
- package/dist/runtime/views.js +221 -0
- package/dist/scaffold/assets.js +25 -21
- package/dist/testing/context.js +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +100 -56
- package/dist/utils/bun.d.ts +2 -0
- package/dist/utils/bun.js +13 -0
- package/dist/watch.d.ts +13 -1
- package/dist/watch.js +345 -97
- package/dist/workspace.d.ts +8 -0
- package/dist/workspace.js +44 -3
- package/package.json +49 -14
- package/scripts/publish.sh +2 -92
- package/scripts/smoke.mjs +282 -107
- package/scripts/update-contract.sh +12 -10
- package/src/add.ts +964 -0
- package/src/build/artifacts.ts +49 -46
- package/src/build/entries.ts +12 -12
- package/src/build/pipeline.ts +779 -403
- package/src/cache/diff.ts +111 -105
- package/src/cache/reporters.ts +26 -26
- package/src/deploy-cli.ts +111 -0
- package/src/diagnostics/summary.ts +28 -22
- package/src/index.ts +11 -0
- package/src/manifest/pipeline.ts +328 -215
- package/src/provider.ts +115 -98
- package/src/runtime/bun.ts +793 -0
- package/src/runtime/core.ts +598 -0
- package/src/runtime/deploy-backend.ts +239 -0
- package/src/runtime/deploy-shared.ts +136 -0
- package/src/runtime/deploy-static.ts +191 -0
- package/src/runtime/deploy.ts +143 -0
- package/src/runtime/forms.ts +364 -0
- package/src/runtime/request-hooks.ts +165 -0
- package/src/runtime/session-metadata.ts +135 -0
- package/src/runtime/session-runtime.ts +267 -0
- package/src/runtime/session.ts +642 -0
- package/src/runtime/views.ts +385 -0
- package/src/scaffold/assets.ts +77 -73
- package/src/testing/context.js +8 -9
- package/src/testing/context.ts +9 -9
- package/src/testing/index.d.ts +14 -3
- package/src/testing/index.js +254 -175
- package/src/testing/index.ts +298 -195
- package/src/testing/types.d.ts +18 -19
- package/src/testing/types.ts +18 -18
- package/src/utils/bun.ts +26 -0
- package/src/watch.ts +503 -99
- package/src/workspace.ts +59 -3
- package/templates/backend/.env.example +15 -0
- package/templates/backend/auth/adapter.ts +335 -36
- package/templates/backend/db/connection.ts +190 -65
- package/templates/backend/db/migrate.ts +149 -43
- package/templates/backend/db/types.d.ts +1 -1
- package/templates/backend/env.ts +132 -20
- package/templates/backend/functions/hello/index.ts +1 -2
- package/templates/backend/index.ts +15 -508
- package/templates/backend/jobs/nightly/index.ts +1 -1
- package/templates/backend/jobs/runtime.ts +24 -11
- package/templates/backend/jobs/scheduler.ts +208 -46
- package/templates/backend/module.ts +227 -13
- package/templates/backend/observability/logger.ts +2 -12
- package/templates/backend/observability/metrics.ts +8 -5
- package/templates/backend/session/sqlite.ts +152 -0
- package/templates/backend/session/store.ts +45 -0
- package/templates/backend/tsconfig.json +1 -1
- package/tests/add.test.js +327 -0
- package/tests/authAdapter.test.js +315 -0
- package/tests/bundlerParity.test.js +217 -0
- package/tests/cacheReporter.test.js +10 -10
- package/tests/dbConnection.test.js +209 -0
- package/tests/deploy.test.js +357 -0
- package/tests/envLoader.test.js +271 -17
- package/tests/integration.test.js +2432 -3
- package/tests/jobsScheduler.test.js +253 -0
- package/tests/manifest.test.js +287 -12
- package/tests/migrationRunner.test.js +249 -0
- package/tests/sessionScaffoldStore.test.js +752 -0
- package/tests/sessionStore.test.js +490 -0
- package/tests/testing.test.js +252 -0
- package/tests/watch.test.js +192 -32
- package/tsconfig.json +3 -10
- package/templates/backend/server/fastify.ts +0 -288
package/src/provider.ts
CHANGED
|
@@ -1,124 +1,141 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
ModuleBuildOptions,
|
|
6
|
-
ModuleBuildResult,
|
|
7
|
-
ModuleDiagnostic,
|
|
8
|
-
ModuleManifest,
|
|
9
|
-
ModuleProvider
|
|
10
|
-
} from '@webstir-io/module-contract';
|
|
4
|
+
import type { ModuleDiagnostic, ModuleProvider } from '@webstir-io/module-contract';
|
|
11
5
|
|
|
12
6
|
import { collectArtifacts, createBuildManifest } from './build/artifacts.js';
|
|
13
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
buildSupportFile,
|
|
9
|
+
resolveBackendBundler,
|
|
10
|
+
runBackendBuildPipeline,
|
|
11
|
+
} from './build/pipeline.js';
|
|
14
12
|
import { loadBackendModuleManifest } from './manifest/pipeline.js';
|
|
15
13
|
import { createCacheReporter } from './cache/reporters.js';
|
|
16
|
-
import {
|
|
14
|
+
import { normalizeLogLevel, filterDiagnostics } from './diagnostics/summary.js';
|
|
17
15
|
import { getBackendScaffoldAssets } from './scaffold/assets.js';
|
|
18
|
-
import { normalizeMode, resolveWorkspacePaths } from './workspace.js';
|
|
16
|
+
import { normalizeMode, resolveWorkspacePaths, resolveWorkspaceRoot } from './workspace.js';
|
|
19
17
|
|
|
20
18
|
import packageJson from '../package.json' with { type: 'json' };
|
|
21
19
|
|
|
22
20
|
interface PackageJson {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly version: string;
|
|
23
|
+
readonly engines?: {
|
|
24
|
+
readonly node?: string;
|
|
25
|
+
readonly bun?: string;
|
|
26
|
+
};
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
const pkg = packageJson as PackageJson;
|
|
31
30
|
|
|
32
31
|
export const backendProvider: ModuleProvider = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
resolveWorkspace(options) {
|
|
43
|
-
return resolveWorkspacePaths(options.workspaceRoot);
|
|
32
|
+
metadata: {
|
|
33
|
+
id: pkg.name ?? '@webstir-io/webstir-backend',
|
|
34
|
+
kind: 'backend',
|
|
35
|
+
version: pkg.version ?? '0.0.0',
|
|
36
|
+
compatibility: {
|
|
37
|
+
minCliVersion: '0.1.0',
|
|
38
|
+
nodeRange: pkg.engines?.node ?? '>=20.18.1',
|
|
39
|
+
...(pkg.engines?.bun ? { notes: `Requires Bun ${pkg.engines.bun} at runtime.` } : {}),
|
|
44
40
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
},
|
|
42
|
+
resolveWorkspace(options) {
|
|
43
|
+
const workspaceRoot = resolveWorkspaceRoot({
|
|
44
|
+
workspaceRoot: options.workspaceRoot,
|
|
45
|
+
});
|
|
46
|
+
return resolveWorkspacePaths(workspaceRoot);
|
|
47
|
+
},
|
|
48
|
+
async build(options) {
|
|
49
|
+
const env = options.env ?? {};
|
|
50
|
+
const workspaceRoot = resolveWorkspaceRoot({
|
|
51
|
+
workspaceRoot: options.workspaceRoot,
|
|
52
|
+
env,
|
|
53
|
+
});
|
|
54
|
+
const paths = resolveWorkspacePaths(workspaceRoot);
|
|
55
|
+
const tsconfigPath = path.join(paths.sourceRoot, 'tsconfig.json');
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
const diagnostics: ModuleDiagnostic[] = [];
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const incremental = options.incremental === true;
|
|
60
|
+
const mode = normalizeMode(env.WEBSTIR_MODULE_MODE);
|
|
61
|
+
const bundler = resolveBackendBundler({
|
|
62
|
+
env,
|
|
63
|
+
incremental,
|
|
64
|
+
diagnostics,
|
|
65
|
+
});
|
|
66
|
+
console.info(`[webstir-backend] ${mode}:start`);
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const artifacts = await collectArtifacts(paths.buildRoot, includePublishSourcemaps);
|
|
67
|
-
const envSource = path.join(paths.sourceRoot, 'env.ts');
|
|
68
|
-
if (existsSync(envSource)) {
|
|
69
|
-
try {
|
|
70
|
-
await buildSupportFile({
|
|
71
|
-
sourceFile: envSource,
|
|
72
|
-
sourceRoot: paths.sourceRoot,
|
|
73
|
-
buildRoot: paths.buildRoot,
|
|
74
|
-
tsconfigPath,
|
|
75
|
-
mode,
|
|
76
|
-
env,
|
|
77
|
-
diagnostics
|
|
78
|
-
});
|
|
79
|
-
} catch {
|
|
80
|
-
// env compilation errors are already captured in diagnostics
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const moduleManifest = await loadBackendModuleManifest({
|
|
84
|
-
workspaceRoot: options.workspaceRoot,
|
|
85
|
-
buildRoot: paths.buildRoot,
|
|
86
|
-
entryPoints,
|
|
87
|
-
diagnostics
|
|
88
|
-
});
|
|
89
|
-
const manifest = createBuildManifest(paths.buildRoot, artifacts, diagnostics, moduleManifest);
|
|
68
|
+
const { entryPoints, outputs, includePublishSourcemaps } = await runBackendBuildPipeline({
|
|
69
|
+
sourceRoot: paths.sourceRoot,
|
|
70
|
+
buildRoot: paths.buildRoot,
|
|
71
|
+
tsconfigPath,
|
|
72
|
+
mode,
|
|
73
|
+
env,
|
|
74
|
+
incremental,
|
|
75
|
+
diagnostics,
|
|
76
|
+
bundler,
|
|
77
|
+
});
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
79
|
+
const artifacts = await collectArtifacts(paths.buildRoot, includePublishSourcemaps);
|
|
80
|
+
const envSource = path.join(paths.sourceRoot, 'env.ts');
|
|
81
|
+
if (existsSync(envSource)) {
|
|
82
|
+
try {
|
|
83
|
+
await buildSupportFile({
|
|
84
|
+
sourceFile: envSource,
|
|
85
|
+
sourceRoot: paths.sourceRoot,
|
|
86
|
+
buildRoot: paths.buildRoot,
|
|
87
|
+
tsconfigPath,
|
|
88
|
+
mode,
|
|
89
|
+
env,
|
|
90
|
+
diagnostics,
|
|
91
|
+
bundler,
|
|
98
92
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const minLevel = normalizeLogLevel(env.WEBSTIR_BACKEND_LOG_LEVEL);
|
|
111
|
-
const filteredDiagnostics = filterDiagnostics(manifest.diagnostics, minLevel);
|
|
93
|
+
} catch {
|
|
94
|
+
// env compilation errors are already captured in diagnostics
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const moduleManifest = await loadBackendModuleManifest({
|
|
98
|
+
workspaceRoot,
|
|
99
|
+
buildRoot: paths.buildRoot,
|
|
100
|
+
entryPoints,
|
|
101
|
+
diagnostics,
|
|
102
|
+
});
|
|
103
|
+
const manifest = createBuildManifest(paths.buildRoot, artifacts, diagnostics, moduleManifest);
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
console.info(`[webstir-backend] ${mode}:complete (entries=${manifest.entryPoints.length})`);
|
|
106
|
+
diagnostics.push({
|
|
107
|
+
severity: 'info',
|
|
108
|
+
message: `[webstir-backend] ${mode}:built entries=${manifest.entryPoints.length}`,
|
|
109
|
+
});
|
|
110
|
+
const cacheReporter = createCacheReporter({
|
|
111
|
+
workspaceRoot,
|
|
112
|
+
buildRoot: paths.buildRoot,
|
|
113
|
+
env,
|
|
114
|
+
diagnostics,
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
await cacheReporter.diffOutputs(outputs, mode);
|
|
118
|
+
} catch {
|
|
119
|
+
// ignore cache errors
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await cacheReporter.diffManifest(moduleManifest);
|
|
123
|
+
} catch {
|
|
124
|
+
// ignore cache errors
|
|
123
125
|
}
|
|
126
|
+
// Optionally filter diagnostics by severity for orchestrator consumption
|
|
127
|
+
const minLevel = normalizeLogLevel(env.WEBSTIR_BACKEND_LOG_LEVEL);
|
|
128
|
+
const filteredDiagnostics = filterDiagnostics(manifest.diagnostics, minLevel);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
artifacts,
|
|
132
|
+
manifest: {
|
|
133
|
+
...manifest,
|
|
134
|
+
diagnostics: filteredDiagnostics,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
async getScaffoldAssets() {
|
|
139
|
+
return await getBackendScaffoldAssets();
|
|
140
|
+
},
|
|
124
141
|
};
|