@webstir-io/webstir-backend 0.1.15
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 +427 -0
- package/dist/build/artifacts.d.ts +113 -0
- package/dist/build/artifacts.js +53 -0
- package/dist/build/entries.d.ts +1 -0
- package/dist/build/entries.js +17 -0
- package/dist/build/pipeline.d.ts +31 -0
- package/dist/build/pipeline.js +424 -0
- package/dist/cache/diff.d.ts +4 -0
- package/dist/cache/diff.js +114 -0
- package/dist/cache/reporters.d.ts +12 -0
- package/dist/cache/reporters.js +23 -0
- package/dist/diagnostics/summary.d.ts +6 -0
- package/dist/diagnostics/summary.js +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/manifest/pipeline.d.ts +13 -0
- package/dist/manifest/pipeline.js +224 -0
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +101 -0
- package/dist/scaffold/assets.d.ts +2 -0
- package/dist/scaffold/assets.js +77 -0
- package/dist/testing/context.d.ts +3 -0
- package/dist/testing/context.js +14 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.js +208 -0
- package/dist/testing/types.d.ts +28 -0
- package/dist/testing/types.js +1 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +159 -0
- package/dist/workspace.d.ts +4 -0
- package/dist/workspace.js +15 -0
- package/package.json +74 -0
- package/scripts/publish.sh +99 -0
- package/scripts/smoke.mjs +241 -0
- package/scripts/update-contract.sh +122 -0
- package/src/build/artifacts.ts +67 -0
- package/src/build/entries.ts +19 -0
- package/src/build/pipeline.ts +507 -0
- package/src/cache/diff.ts +128 -0
- package/src/cache/reporters.ts +41 -0
- package/src/diagnostics/summary.ts +32 -0
- package/src/index.ts +2 -0
- package/src/manifest/pipeline.ts +270 -0
- package/src/provider.ts +124 -0
- package/src/scaffold/assets.ts +81 -0
- package/src/testing/context.d.ts +3 -0
- package/src/testing/context.js +14 -0
- package/src/testing/context.ts +17 -0
- package/src/testing/index.d.ts +6 -0
- package/src/testing/index.js +208 -0
- package/src/testing/index.ts +252 -0
- package/src/testing/types.d.ts +28 -0
- package/src/testing/types.js +1 -0
- package/src/testing/types.ts +32 -0
- package/src/watch.ts +177 -0
- package/src/workspace.ts +22 -0
- package/templates/backend/.env.example +13 -0
- package/templates/backend/auth/adapter.ts +160 -0
- package/templates/backend/db/connection.ts +99 -0
- package/templates/backend/db/migrate.ts +231 -0
- package/templates/backend/db/migrations/0001-example.ts +17 -0
- package/templates/backend/db/types.d.ts +2 -0
- package/templates/backend/env.ts +174 -0
- package/templates/backend/functions/hello/index.ts +29 -0
- package/templates/backend/index.ts +532 -0
- package/templates/backend/jobs/nightly/index.ts +28 -0
- package/templates/backend/jobs/runtime.ts +103 -0
- package/templates/backend/jobs/scheduler.ts +193 -0
- package/templates/backend/module.ts +87 -0
- package/templates/backend/observability/logger.ts +24 -0
- package/templates/backend/observability/metrics.ts +78 -0
- package/templates/backend/server/fastify.ts +288 -0
- package/templates/backend/tsconfig.json +19 -0
- package/tests/cacheReporter.test.js +89 -0
- package/tests/envLoader.test.js +64 -0
- package/tests/integration.test.js +108 -0
- package/tests/manifest.test.js +159 -0
- package/tests/watch.test.js +100 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
usage() {
|
|
6
|
+
cat <<'EOF'
|
|
7
|
+
Usage: scripts/update-contract.sh [x.y.z|--latest] [--exact] [--fast]
|
|
8
|
+
|
|
9
|
+
Updates @webstir-io/module-contract (defaults to latest when no version is provided),
|
|
10
|
+
installs deps, then builds and tests the backend package. Does NOT publish. If
|
|
11
|
+
everything passes, run scripts/publish.sh <bump> separately.
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
scripts/update-contract.sh # use latest
|
|
15
|
+
scripts/update-contract.sh --latest # explicit latest
|
|
16
|
+
scripts/update-contract.sh 0.1.8 # specific version (caret range)
|
|
17
|
+
scripts/update-contract.sh 0.1.8 --exact # set exact version instead of ^range
|
|
18
|
+
scripts/update-contract.sh 0.1.8 --fast # lockfile-only update; skip build/test
|
|
19
|
+
EOF
|
|
20
|
+
exit 1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
24
|
+
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
25
|
+
|
|
26
|
+
has_script() {
|
|
27
|
+
local script_name="$1"
|
|
28
|
+
node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); const has=!!(pkg.scripts && Object.prototype.hasOwnProperty.call(pkg.scripts, '${script_name}')); process.exit(has ? 0 : 1);"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main() {
|
|
32
|
+
local ver=""
|
|
33
|
+
local exact="false"
|
|
34
|
+
local fast="false"
|
|
35
|
+
|
|
36
|
+
while [[ $# -gt 0 ]]; do
|
|
37
|
+
case "$1" in
|
|
38
|
+
--latest)
|
|
39
|
+
ver="__resolve_latest__"
|
|
40
|
+
;;
|
|
41
|
+
--exact)
|
|
42
|
+
exact="true"
|
|
43
|
+
;;
|
|
44
|
+
--fast)
|
|
45
|
+
fast="true"
|
|
46
|
+
;;
|
|
47
|
+
-h|--help)
|
|
48
|
+
usage ;;
|
|
49
|
+
*)
|
|
50
|
+
# assume explicit version
|
|
51
|
+
if [[ -n "$ver" && "$ver" != "__resolve_latest__" ]]; then
|
|
52
|
+
echo "error: duplicate version argument '$1'" >&2
|
|
53
|
+
usage
|
|
54
|
+
fi
|
|
55
|
+
ver="$1"
|
|
56
|
+
;;
|
|
57
|
+
esac
|
|
58
|
+
shift || true
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
# Default to latest if no version provided
|
|
62
|
+
if [[ -z "$ver" || "$ver" == "__resolve_latest__" ]]; then
|
|
63
|
+
echo "› Resolving latest @webstir-io/module-contract version"
|
|
64
|
+
ver="$(npm view @webstir-io/module-contract version 2>/dev/null || true)"
|
|
65
|
+
if [[ -z "$ver" ]]; then
|
|
66
|
+
echo "error: unable to resolve latest @webstir-io/module-contract version" >&2
|
|
67
|
+
exit 1
|
|
68
|
+
fi
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
if [[ ! $ver =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
72
|
+
echo "error: invalid version '$ver' (expected x.y.z)" >&2
|
|
73
|
+
usage
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
cd "$ROOT_DIR"
|
|
77
|
+
|
|
78
|
+
local spec
|
|
79
|
+
if [[ "$exact" == "true" ]]; then
|
|
80
|
+
spec="$ver"
|
|
81
|
+
else
|
|
82
|
+
spec="^$ver"
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
echo "› Setting @webstir-io/module-contract to $spec"
|
|
86
|
+
npm pkg set "dependencies.@webstir-io/module-contract=$spec"
|
|
87
|
+
|
|
88
|
+
echo "› npm install (refresh lockfile)"
|
|
89
|
+
if [[ "$fast" == "true" ]]; then
|
|
90
|
+
npm install --package-lock-only --no-audit --no-fund --ignore-scripts
|
|
91
|
+
else
|
|
92
|
+
npm install --no-audit --no-fund
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
# Clarify versions in logs to avoid confusion with backend package version
|
|
96
|
+
local backend_ver
|
|
97
|
+
backend_ver="$(node -p "require('./package.json').version" 2>/dev/null || echo 'unknown')"
|
|
98
|
+
local installed_contract
|
|
99
|
+
installed_contract="$(npm ls @webstir-io/module-contract --json 2>/dev/null | node -e "let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{try{const j=JSON.parse(d);const v=(j.dependencies&&j.dependencies['@webstir-io/module-contract']&&j.dependencies['@webstir-io/module-contract'].version)||'';console.log(v||'unknown')}catch{console.log('unknown')}})")"
|
|
100
|
+
echo "› Backend package: @webstir-io/webstir-backend@${backend_ver}"
|
|
101
|
+
echo "› Contract installed: @webstir-io/module-contract@${installed_contract}"
|
|
102
|
+
|
|
103
|
+
if [[ "$fast" != "true" ]]; then
|
|
104
|
+
echo "› npm run build"
|
|
105
|
+
npm run build
|
|
106
|
+
|
|
107
|
+
if has_script test; then
|
|
108
|
+
echo "› npm test"
|
|
109
|
+
npm test
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
if has_script smoke; then
|
|
113
|
+
echo "› npm run smoke"
|
|
114
|
+
npm run smoke
|
|
115
|
+
fi
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
echo
|
|
119
|
+
echo "Contract update complete: @webstir-io/module-contract@$spec"
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main "$@"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
import { glob } from 'glob';
|
|
5
|
+
import type { ModuleArtifact, ModuleDiagnostic, ModuleManifest } from '@webstir-io/module-contract';
|
|
6
|
+
|
|
7
|
+
import { pushEntryBucketSummary } from '../diagnostics/summary.js';
|
|
8
|
+
|
|
9
|
+
export async function collectArtifacts(buildRoot: string, includeSourceMaps: boolean): Promise<ModuleArtifact[]> {
|
|
10
|
+
const patterns = ['**/*.js'];
|
|
11
|
+
if (includeSourceMaps) {
|
|
12
|
+
patterns.push('**/*.js.map');
|
|
13
|
+
}
|
|
14
|
+
const matches = new Set<string>();
|
|
15
|
+
for (const pattern of patterns) {
|
|
16
|
+
const files = await glob(pattern, {
|
|
17
|
+
cwd: buildRoot,
|
|
18
|
+
nodir: true,
|
|
19
|
+
dot: false
|
|
20
|
+
});
|
|
21
|
+
for (const relativePath of files) {
|
|
22
|
+
matches.add(relativePath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return Array.from(matches).map<ModuleArtifact>((relativePath) => ({
|
|
27
|
+
path: path.join(buildRoot, relativePath),
|
|
28
|
+
type: relativePath.endsWith('.map') ? 'asset' : 'bundle'
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createBuildManifest(
|
|
33
|
+
buildRoot: string,
|
|
34
|
+
artifacts: readonly ModuleArtifact[],
|
|
35
|
+
diagnostics: ModuleDiagnostic[],
|
|
36
|
+
moduleManifest: ModuleManifest
|
|
37
|
+
) {
|
|
38
|
+
const entryPoints: string[] = [];
|
|
39
|
+
|
|
40
|
+
for (const artifact of artifacts) {
|
|
41
|
+
const relative = path.relative(buildRoot, artifact.path);
|
|
42
|
+
if (relative.endsWith('index.js')) {
|
|
43
|
+
entryPoints.push(relative);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (entryPoints.length === 0) {
|
|
48
|
+
const defaultEntry = path.join(buildRoot, 'index.js');
|
|
49
|
+
if (existsSync(defaultEntry)) {
|
|
50
|
+
entryPoints.push(path.relative(buildRoot, defaultEntry));
|
|
51
|
+
} else {
|
|
52
|
+
diagnostics.push({
|
|
53
|
+
severity: 'warn',
|
|
54
|
+
message: 'No backend entry point found (expected index.js).'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
pushEntryBucketSummary(diagnostics, entryPoints);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
entryPoints,
|
|
63
|
+
staticAssets: [],
|
|
64
|
+
diagnostics,
|
|
65
|
+
module: moduleManifest
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
|
|
5
|
+
export async function discoverEntryPoints(sourceRoot: string): Promise<string[]> {
|
|
6
|
+
const patterns = [
|
|
7
|
+
'index.{ts,tsx,js,mjs}',
|
|
8
|
+
'functions/*/index.{ts,tsx,js,mjs}',
|
|
9
|
+
'jobs/*/index.{ts,tsx,js,mjs}'
|
|
10
|
+
];
|
|
11
|
+
const entries = new Set<string>();
|
|
12
|
+
for (const pattern of patterns) {
|
|
13
|
+
const matches = await glob(pattern, { cwd: sourceRoot, nodir: true, dot: false });
|
|
14
|
+
for (const rel of matches) {
|
|
15
|
+
entries.add(path.join(sourceRoot, rel));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Array.from(entries);
|
|
19
|
+
}
|