@marinoscar/platform-infra 0.0.0-stage → 0.1.0-next.3
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/bin/platform-infra.mjs +7 -0
- package/compose/.gitkeep +0 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +96 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/sync.d.ts +134 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +341 -0
- package/dist/sync.js.map +1 -0
- package/dist/telemetry/index.d.ts +12 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/manifest.d.ts +96 -0
- package/dist/telemetry/manifest.d.ts.map +1 -0
- package/dist/telemetry/manifest.js +51 -0
- package/dist/telemetry/manifest.js.map +1 -0
- package/nginx/.gitkeep +0 -0
- package/otel/.gitkeep +0 -0
- package/package.json +60 -4
- package/telemetry/compose/telemetry.compose.yml +159 -0
- package/telemetry/compose/vps.telemetry.compose.yml +99 -0
- package/telemetry/otel/app-collector.example.yaml +61 -0
- package/telemetry/otel/otel-collector-config.yaml +414 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @marinoscar/platform-infra
|
|
2
|
+
|
|
3
|
+
## 0.1.0-next.3
|
|
4
|
+
|
|
5
|
+
## 0.1.0-next.2
|
|
6
|
+
|
|
7
|
+
## 0.1.0-next.1
|
|
8
|
+
|
|
9
|
+
## 0.1.0-next.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- a66fef1: First pre-release of the platform packages: the six-package scaffold (build formats, boundary lint, pack check, TSDoc and generated API reference, single-instance peer dependencies) plus the first slices.
|
|
14
|
+
|
|
15
|
+
- `@marinoscar/platform-api/core`: the typed registry primitive (`defineRegistry`, `Registry`, `RegistryError`, `RegistryFreezeService`, `withTemporaryEntries`).
|
|
16
|
+
- `@marinoscar/platform-api/testing`: the conformance harness (`runPlatformConformance`, `conformanceSuites`) with the `cron-enqueue-only` suite.
|
|
17
|
+
- `@marinoscar/platform-cli/core`: the CLI command and env-spec fragment registries.
|
|
18
|
+
- `@marinoscar/platform-cli/telemetry`: the node span relay and the telemetry env-spec fragment.
|
|
19
|
+
- `@marinoscar/platform-infra`: `infraFile()`, the `platform-infra` command (`sync` materialises fragments into an app) and the `telemetry` slice (collector and GreptimeDB compose fragments, collector config and overlay, typed manifest).
|
|
20
|
+
- `@marinoscar/platform-contract`, `@marinoscar/platform-web` and `@marinoscar/platform-db` ship their package scaffold only; their slices follow in later releases.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 marinoscar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @marinoscar/platform-infra
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deployment configuration shipped as files: Compose fragments (`compose/`), nginx configuration (`nginx/`) and OpenTelemetry collector configuration (`otel/`), layered by an app with its own overlays. `infraFile('compose/<file>')` returns the absolute path of a shipped file, for `docker compose -f`.
|
|
4
|
+
|
|
5
|
+
## Purpose and scope
|
|
6
|
+
|
|
7
|
+
Compose fragments, nginx and collector configuration of the platform, plus `infraFile()` to locate them. It does not own the app's own overlays, `.env` or images.
|
|
8
|
+
|
|
9
|
+
Slices, each a subpath export with its own README:
|
|
10
|
+
|
|
11
|
+
- [`@marinoscar/platform-infra/telemetry`](src/telemetry/README.md): the collector and GreptimeDB compose fragments, the platform collector config, the app-owned collector overlay and their typed manifest.
|
|
12
|
+
|
|
13
|
+
The package also ships the `platform-infra` command (`bin/platform-infra.mjs`), which materialises the fragments into the app. Version `0.0.0`, unpublished; the base, prod, vps and worker fragments and nginx follow (#714).
|
|
14
|
+
|
|
15
|
+
## Install and peer dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @marinoscar/platform-infra
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
No peer dependencies: the package needs nothing installed beside it.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { infraFile } from '@marinoscar/platform-infra';
|
|
27
|
+
|
|
28
|
+
const base = infraFile('compose/base.compose.yml'); // absolute path for docker compose -f
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Fragments are copied into the app and committed, never resolved from `node_modules` at deploy time (an app's VPS deploy runs `docker compose` from its cloned repository, where there is no `node_modules`):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx platform-infra sync # materialise every fragment into infra/, write infra/platform-infra.lock.json
|
|
35
|
+
npx platform-infra sync --check # CI: fail when a generated file differs from the package or the lock
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In this repository the root script is `npm run platform:infra:sync`.
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
No `forRoot()`. The `platform-infra sync` command takes `--check` (write nothing; exit 1 on drift) and `--root <dir>` (the app's repository root, default the current directory); see the [telemetry slice README](src/telemetry/README.md#configuration).
|
|
43
|
+
|
|
44
|
+
## Extension-point catalog
|
|
45
|
+
|
|
46
|
+
None. The root entry point exports no extension point; each slice lists its own (`telemetryInfraFragment` and the collector overlay: [telemetry slice README](src/telemetry/README.md#extension-point-catalog)).
|
|
47
|
+
|
|
48
|
+
## Data
|
|
49
|
+
|
|
50
|
+
None. The package holds configuration files, not data.
|
|
51
|
+
|
|
52
|
+
## Permissions and settings
|
|
53
|
+
|
|
54
|
+
None. Configuration files declare no permission or setting.
|
|
55
|
+
|
|
56
|
+
## UI
|
|
57
|
+
|
|
58
|
+
None. The package renders nothing.
|
|
59
|
+
|
|
60
|
+
## Infra
|
|
61
|
+
|
|
62
|
+
Slice files ship under `<slice>/` (`telemetry/compose/`, `telemetry/otel/`); the root `compose/`, `nginx/` and `otel/` folders are still empty. `infraFile(relativePath)` (`@stability experimental`) returns the absolute path of a shipped file and throws on an empty, absolute or escaping path. No environment variable is read.
|
|
63
|
+
|
|
64
|
+
Generated files start with a `# GENERATED from @marinoscar/platform-infra@<version> (<slice>)` header and are never edited in the app; `infra/platform-infra.lock.json` records the version and the sha256 of each body. App-owned files (the collector overlay `infra/otel/app-collector.yaml`) are created once from a package example and never overwritten.
|
|
65
|
+
|
|
66
|
+
## Observability
|
|
67
|
+
|
|
68
|
+
None. The package emits nothing at run time; the telemetry slice ships the collector configuration itself (see its README). `platform-infra sync` prints only the files it wrote.
|
|
69
|
+
|
|
70
|
+
## Security notes
|
|
71
|
+
|
|
72
|
+
`infraFile()` refuses absolute paths and any path that resolves outside the package root, so a caller cannot use it to read arbitrary files. `platform-infra sync` refuses any path that leaves the app root or the package, validates its whole plan before writing, and never overwrites an app-owned file.
|
|
73
|
+
|
|
74
|
+
## Conformance suite
|
|
75
|
+
|
|
76
|
+
None yet. The package ships no conformance suite; `runPlatformConformance()` and the suites arrive with the platform's conformance harness.
|
|
77
|
+
|
|
78
|
+
## Upgrade notes
|
|
79
|
+
|
|
80
|
+
None. No version has been published yet, so there is nothing to migrate from.
|
|
81
|
+
|
|
82
|
+
## Troubleshooting
|
|
83
|
+
|
|
84
|
+
`sync --check` failures (a hand-edited generated file, a stale lock) are in the [telemetry slice README](src/telemetry/README.md#troubleshooting) and [the telemetry runbook § 12](../../docs/runbooks/telemetry.md#12-troubleshooting). Build and import problems common to every platform package are in [DEVELOPMENT.md § Platform packages](../../docs/DEVELOPMENT.md#platform-packages).
|
|
85
|
+
|
|
86
|
+
## Links
|
|
87
|
+
|
|
88
|
+
- [Platform packages spec](../../docs/specs/platform-packages.md): the extension contract and the package documentation standard
|
|
89
|
+
- [Package documentation standard and checks](../../docs/PACKAGES.md): how this README, the TSDoc and the catalog are checked
|
|
90
|
+
- [DEVELOPMENT.md § Platform packages](../../docs/DEVELOPMENT.md#platform-packages): build, test and lint commands
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `platform-infra sync [--check] [--root <dir>]`: materialise the platform's
|
|
3
|
+
// infra fragments into the app (see src/sync.ts). Runs the compiled dist/, so
|
|
4
|
+
// in this repository `npm run build:packages` comes first.
|
|
5
|
+
import { main } from '../dist/cli.js';
|
|
6
|
+
|
|
7
|
+
process.exitCode = main(process.argv.slice(2));
|
package/compose/.gitkeep
ADDED
|
File without changes
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type SyncOptions } from './sync.js';
|
|
2
|
+
/**
|
|
3
|
+
* Usage text of the `platform-infra` command.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const USAGE: string;
|
|
8
|
+
/**
|
|
9
|
+
* Where the command writes: injectable so tests capture output.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export interface CliIo {
|
|
14
|
+
out: (line: string) => void;
|
|
15
|
+
err: (line: string) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs the command and returns its exit code: 0 success, 1 check failure or
|
|
19
|
+
* error, 2 usage error.
|
|
20
|
+
*
|
|
21
|
+
* @param argv - Arguments after the command name.
|
|
22
|
+
* @param io - Output sinks.
|
|
23
|
+
* @param overrides - Package-side overrides for tests (package root, version, fragments).
|
|
24
|
+
* @returns The process exit code.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function main(argv: readonly string[], io?: CliIo, overrides?: Omit<SyncOptions, 'root'>): number;
|
|
28
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoC,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,KAAK,QASjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAOD;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,GAAE,KAAkB,EAAE,SAAS,GAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAM,GAAG,MAAM,CAyDvH"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The `platform-infra` command (bin/platform-infra.mjs): argument parsing and
|
|
2
|
+
// output around ./sync.ts. Kept free of process.exit so tests drive it.
|
|
3
|
+
import { PLATFORM_PACKAGE } from './index.js';
|
|
4
|
+
import { checkInfra, LOCK_PATH, syncInfra } from './sync.js';
|
|
5
|
+
/**
|
|
6
|
+
* Usage text of the `platform-infra` command.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const USAGE = `Usage: platform-infra sync [--check] [--root <dir>]
|
|
11
|
+
|
|
12
|
+
sync Materialise the infra fragments of ${PLATFORM_PACKAGE} into the
|
|
13
|
+
app's infra/ folder, with a generated-file header, and write
|
|
14
|
+
${LOCK_PATH}. App-owned files (infra/otel/app-collector.yaml)
|
|
15
|
+
are created from their example only when absent.
|
|
16
|
+
--check Write nothing; exit 1 when a generated file differs from the
|
|
17
|
+
package or from the lock (for CI).
|
|
18
|
+
--root <dir> The app's repository root (default: the current directory).
|
|
19
|
+
`;
|
|
20
|
+
const DEFAULT_IO = {
|
|
21
|
+
out: (line) => process.stdout.write(`${line}\n`),
|
|
22
|
+
err: (line) => process.stderr.write(`${line}\n`),
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Runs the command and returns its exit code: 0 success, 1 check failure or
|
|
26
|
+
* error, 2 usage error.
|
|
27
|
+
*
|
|
28
|
+
* @param argv - Arguments after the command name.
|
|
29
|
+
* @param io - Output sinks.
|
|
30
|
+
* @param overrides - Package-side overrides for tests (package root, version, fragments).
|
|
31
|
+
* @returns The process exit code.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function main(argv, io = DEFAULT_IO, overrides = {}) {
|
|
35
|
+
const args = [...argv];
|
|
36
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
37
|
+
(args.length === 0 ? io.err : io.out)(USAGE);
|
|
38
|
+
return args.length === 0 ? 2 : 0;
|
|
39
|
+
}
|
|
40
|
+
const command = args.shift();
|
|
41
|
+
if (command !== 'sync') {
|
|
42
|
+
io.err(`platform-infra: unknown command "${command ?? ''}"\n\n${USAGE}`);
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
let check = false;
|
|
46
|
+
let root = process.cwd();
|
|
47
|
+
while (args.length > 0) {
|
|
48
|
+
const arg = args.shift();
|
|
49
|
+
if (arg === '--check') {
|
|
50
|
+
check = true;
|
|
51
|
+
}
|
|
52
|
+
else if (arg === '--root') {
|
|
53
|
+
const value = args.shift();
|
|
54
|
+
if (value === undefined || value.startsWith('--')) {
|
|
55
|
+
io.err(`platform-infra: --root needs a directory\n\n${USAGE}`);
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
root = value;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
io.err(`platform-infra: unknown option "${arg ?? ''}"\n\n${USAGE}`);
|
|
62
|
+
return 2;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
if (check) {
|
|
67
|
+
const result = checkInfra({ ...overrides, root });
|
|
68
|
+
for (const w of result.warnings)
|
|
69
|
+
io.err(`warning: ${w.file}: ${w.message}`);
|
|
70
|
+
for (const p of result.problems)
|
|
71
|
+
io.err(`error: ${p.file}: ${p.message}`);
|
|
72
|
+
if (result.problems.length > 0) {
|
|
73
|
+
io.err(`platform-infra sync --check: ${result.problems.length} problem(s). Generated files are never edited by hand.`);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
io.out(`platform-infra sync --check: ${result.checked.length} generated file(s) match ${PLATFORM_PACKAGE}@${result.version} and ${LOCK_PATH}.`);
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
const result = syncInfra({ ...overrides, root });
|
|
80
|
+
for (const file of result.written)
|
|
81
|
+
io.out(`wrote ${file}`);
|
|
82
|
+
for (const file of result.created)
|
|
83
|
+
io.out(`created ${file} (app-owned: edit it freely)`);
|
|
84
|
+
for (const file of result.kept)
|
|
85
|
+
io.out(`kept ${file} (app-owned)`);
|
|
86
|
+
if (result.lockWritten)
|
|
87
|
+
io.out(`wrote ${LOCK_PATH}`);
|
|
88
|
+
io.out(`platform-infra sync: ${result.written.length} written, ${result.unchanged.length} unchanged, ${result.created.length} created.`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wEAAwE;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,WAAW,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;;sDAEiC,gBAAgB;;mBAEnD,SAAS;;;;;CAK3B,CAAC;AAYF,MAAM,UAAU,GAAU;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;CACjD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,IAAI,CAAC,IAAuB,EAAE,KAAY,UAAU,EAAE,YAAuC,EAAE;IAC7G,M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C,GAAG,CAAC,YAAY,IAAI,8BAA8B,CAAC,CAAC;QAC1F,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI;YAAE,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,cAAc,CAAC,CAAC;QACvE,IAAI,MAAM,CAAC,WAAW;YAAE,EAAE,CAAC,GAAG,CAAC,YAAY,SAAS,EAAE,CAAC,CAAC;QACxD,EAAE,CAAC,GAAG,CACJ,wBAAwB,MAAM,CAAC,OAAO,CAAC,MAAM,aAAa,MAAM,CAAC,SAAS,CAAC,MAAM,eAAe,MAAM,CAAC,OAAO,CAAC,MAAM,WAAW,CACjI,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,EAAE,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The npm name of this package, which holds Compose fragments, nginx and OpenTelemetry collector configuration of the platform.
|
|
3
|
+
*
|
|
4
|
+
* A placeholder export so the build, the pack check and the smoke imports in
|
|
5
|
+
* CI have something to load end to end. Real slices arrive as subpath
|
|
6
|
+
* exports (`@marinoscar/platform-infra/<slice>`).
|
|
7
|
+
*
|
|
8
|
+
* @stability experimental
|
|
9
|
+
*/
|
|
10
|
+
export declare const PLATFORM_PACKAGE: "@marinoscar/platform-infra";
|
|
11
|
+
/**
|
|
12
|
+
* Absolute path of a file shipped inside this package, for example
|
|
13
|
+
* `infraFile('compose/base.compose.yml')`, so a consumer can hand it to
|
|
14
|
+
* `docker compose -f` without knowing where npm installed the package.
|
|
15
|
+
*
|
|
16
|
+
* @param relativePath - Path relative to the package root, using `/`.
|
|
17
|
+
* @returns The absolute filesystem path.
|
|
18
|
+
* @throws Error when `relativePath` is empty, absolute, or resolves outside
|
|
19
|
+
* the package root (for example `../../etc/passwd`).
|
|
20
|
+
* @stability experimental
|
|
21
|
+
*/
|
|
22
|
+
export declare function infraFile(relativePath: string): string;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAG,4BAAqC,CAAC;AAStE;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAWtD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
/**
|
|
4
|
+
* The npm name of this package, which holds Compose fragments, nginx and OpenTelemetry collector configuration of the platform.
|
|
5
|
+
*
|
|
6
|
+
* A placeholder export so the build, the pack check and the smoke imports in
|
|
7
|
+
* CI have something to load end to end. Real slices arrive as subpath
|
|
8
|
+
* exports (`@marinoscar/platform-infra/<slice>`).
|
|
9
|
+
*
|
|
10
|
+
* @stability experimental
|
|
11
|
+
*/
|
|
12
|
+
export const PLATFORM_PACKAGE = '@marinoscar/platform-infra';
|
|
13
|
+
/**
|
|
14
|
+
* The package root as a URL. `../` from this module is the package root both
|
|
15
|
+
* from the built `dist/index.js` and from `src/index.ts` under the tests.
|
|
16
|
+
*/
|
|
17
|
+
const PACKAGE_ROOT_URL = new URL('../', import.meta.url);
|
|
18
|
+
const PACKAGE_ROOT = fileURLToPath(PACKAGE_ROOT_URL);
|
|
19
|
+
/**
|
|
20
|
+
* Absolute path of a file shipped inside this package, for example
|
|
21
|
+
* `infraFile('compose/base.compose.yml')`, so a consumer can hand it to
|
|
22
|
+
* `docker compose -f` without knowing where npm installed the package.
|
|
23
|
+
*
|
|
24
|
+
* @param relativePath - Path relative to the package root, using `/`.
|
|
25
|
+
* @returns The absolute filesystem path.
|
|
26
|
+
* @throws Error when `relativePath` is empty, absolute, or resolves outside
|
|
27
|
+
* the package root (for example `../../etc/passwd`).
|
|
28
|
+
* @stability experimental
|
|
29
|
+
*/
|
|
30
|
+
export function infraFile(relativePath) {
|
|
31
|
+
if (relativePath.trim() === '' || isAbsolute(relativePath) || /^[a-zA-Z]:/.test(relativePath)) {
|
|
32
|
+
throw new Error(`infraFile: expected a path relative to the package root, got "${relativePath}"`);
|
|
33
|
+
}
|
|
34
|
+
const encoded = relativePath.split(/[\\/]/).map(encodeURIComponent).join('/');
|
|
35
|
+
const resolved = fileURLToPath(new URL(encoded, PACKAGE_ROOT_URL));
|
|
36
|
+
const fromRoot = relative(PACKAGE_ROOT, resolved);
|
|
37
|
+
if (fromRoot === '' || fromRoot === '..' || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot)) {
|
|
38
|
+
throw new Error(`infraFile: "${relativePath}" resolves outside @marinoscar/platform-infra`);
|
|
39
|
+
}
|
|
40
|
+
return resolved;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,4BAAqC,CAAC;AAEtE;;;GAGG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzD,MAAM,YAAY,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,YAAoB;IAC5C,IAAI,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9F,MAAM,IAAI,KAAK,CAAC,iEAAiE,YAAY,GAAG,CAAC,CAAC;IACpG,CAAC;IACD,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAClD,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpG,MAAM,IAAI,KAAK,CAAC,eAAe,YAAY,+CAA+C,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type InfraFile, type InfraFragment } from './telemetry/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every fragment the package ships, in sync order.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const INFRA_FRAGMENTS: readonly InfraFragment[];
|
|
8
|
+
/**
|
|
9
|
+
* Where the lock file lives, relative to the app's repository root.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOCK_PATH = "infra/platform-infra.lock.json";
|
|
14
|
+
/**
|
|
15
|
+
* The command that re-materialises the files, as printed in headers and errors.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const SYNC_COMMAND = "npx platform-infra sync";
|
|
20
|
+
/**
|
|
21
|
+
* Shape of `infra/platform-infra.lock.json`.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export interface InfraLock {
|
|
26
|
+
/** The `@marinoscar/platform-infra` version the files were materialised from. */
|
|
27
|
+
version: string;
|
|
28
|
+
/** Per fragment id: app path of each generated file to the sha256 (hex) of its body. */
|
|
29
|
+
fragments: Record<string, {
|
|
30
|
+
files: Record<string, string>;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Inputs shared by {@link syncInfra} and {@link checkInfra}.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export interface SyncOptions {
|
|
39
|
+
/** The app's repository root; every `to` path is relative to it. */
|
|
40
|
+
root: string;
|
|
41
|
+
/** The package root to read fragment files from. Defaults to this package. */
|
|
42
|
+
packageRoot?: string;
|
|
43
|
+
/** The package version written into headers and the lock. Defaults to this package's `version`. */
|
|
44
|
+
version?: string;
|
|
45
|
+
/** The fragments to materialise. Defaults to {@link INFRA_FRAGMENTS}. */
|
|
46
|
+
fragments?: readonly InfraFragment[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What a sync did, as app-relative paths.
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export interface SyncResult {
|
|
54
|
+
/** Generated files written because they were missing or differed. */
|
|
55
|
+
written: string[];
|
|
56
|
+
/** Generated files already identical to what sync would write. */
|
|
57
|
+
unchanged: string[];
|
|
58
|
+
/** App-owned files created from their template because they were absent. */
|
|
59
|
+
created: string[];
|
|
60
|
+
/** App-owned files left alone because they already exist. */
|
|
61
|
+
kept: string[];
|
|
62
|
+
/** Whether the lock file was (re)written. */
|
|
63
|
+
lockWritten: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* One finding of {@link checkInfra}.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export interface CheckFinding {
|
|
71
|
+
/** App-relative path the finding is about. */
|
|
72
|
+
file: string;
|
|
73
|
+
/** What is wrong and how to fix it, in one line. */
|
|
74
|
+
message: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The outcome of {@link checkInfra}: `problems` fail the check, `warnings` do not.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export interface CheckResult {
|
|
82
|
+
/** The installed package version the files were compared against. */
|
|
83
|
+
version: string;
|
|
84
|
+
problems: CheckFinding[];
|
|
85
|
+
warnings: CheckFinding[];
|
|
86
|
+
/** Generated files that matched the package and the lock. */
|
|
87
|
+
checked: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* sha256 (hex) of a body, after normalising line endings.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
export declare function bodyChecksum(body: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* The generated-file header for one file, as complete lines ending in `\n`.
|
|
97
|
+
*
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
export declare function generatedHeader(fragment: InfraFragment, file: InfraFile, version: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Splits a materialised file into its generated header (two lines) and body.
|
|
103
|
+
* `header` is `undefined` when the file does not start with one.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export declare function splitGenerated(text: string): {
|
|
108
|
+
header: string | undefined;
|
|
109
|
+
version: string | undefined;
|
|
110
|
+
body: string;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Materialises every fragment into the app: rewrites each generated file
|
|
114
|
+
* (header plus the package's content), creates each app-owned file from its
|
|
115
|
+
* template only when absent, and writes the lock. Idempotent: a second run
|
|
116
|
+
* writes nothing.
|
|
117
|
+
*
|
|
118
|
+
* @param options - The app root, and overrides for tests.
|
|
119
|
+
* @returns What was written, created or left alone.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
export declare function syncInfra(options: SyncOptions): SyncResult;
|
|
123
|
+
/**
|
|
124
|
+
* Verifies the app's materialised files without writing anything. A problem
|
|
125
|
+
* is a generated file that is missing, lacks its header, differs from the
|
|
126
|
+
* package or from the lock, or a missing app-owned file. A version-only
|
|
127
|
+
* difference (same content, older header or lock version) is a warning.
|
|
128
|
+
*
|
|
129
|
+
* @param options - The app root, and overrides for tests.
|
|
130
|
+
* @returns The problems (which fail `--check`) and warnings.
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
export declare function checkInfra(options: SyncOptions): CheckResult;
|
|
134
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AA+BA,OAAO,EAA0B,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAElG;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAA6B,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,SAAS,mCAAmC,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,YAAY,4BAA4B,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,IAA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