@lowdefy/node-utils 0.0.0-experimental-20260829192306 → 0.0.0-experimental-20260830202815
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/index.js +2 -1
- package/dist/readFixture.js +85 -0
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import installIfPackageJsonChanged from './installIfPackageJsonChanged.js';
|
|
|
21
21
|
import isPortAvailable from './isPortAvailable.js';
|
|
22
22
|
import spawnProcess from './spawnProcess.js';
|
|
23
23
|
import readFile from './readFile.js';
|
|
24
|
+
import readFixture from './readFixture.js';
|
|
24
25
|
import writeFile from './writeFile.js';
|
|
25
26
|
import writeFileIfChanged from './writeFileIfChanged.js';
|
|
26
|
-
export { cleanDirectory, copyFileOrDirectory, findAvailablePort, getFileExtension, getFileSubExtension, getSecretsFromEnv, installIfPackageJsonChanged, isPortAvailable, spawnProcess, readFile, writeFile, writeFileIfChanged };
|
|
27
|
+
export { cleanDirectory, copyFileOrDirectory, findAvailablePort, getFileExtension, getFileSubExtension, getSecretsFromEnv, installIfPackageJsonChanged, isPortAvailable, spawnProcess, readFile, readFixture, writeFile, writeFileIfChanged };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import path from 'path';
|
|
16
|
+
import YAML from 'yaml';
|
|
17
|
+
import { ConfigError } from '@lowdefy/errors';
|
|
18
|
+
import { serializer, type } from '@lowdefy/helpers';
|
|
19
|
+
import readFile from './readFile.js';
|
|
20
|
+
const FIXTURES_DIRECTORY = 'fixtures';
|
|
21
|
+
function validateName({ name }) {
|
|
22
|
+
if (!type.isString(name) || name === '') {
|
|
23
|
+
throw new ConfigError(`Fixture name must be a non-empty string. Received ${JSON.stringify(name)}.`);
|
|
24
|
+
}
|
|
25
|
+
// The name is a file name inside fixtures/, never a path - an agent supplies
|
|
26
|
+
// it over the MCP, so it must not be able to name a file outside that directory.
|
|
27
|
+
if (name.includes('/') || name.includes('\\') || name.includes('..')) {
|
|
28
|
+
throw new ConfigError(`Fixture name must not contain path segments. Received ${JSON.stringify(name)}.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function readFixtureFile({ configDirectory, name }) {
|
|
32
|
+
const directory = path.join(configDirectory, FIXTURES_DIRECTORY);
|
|
33
|
+
let raw = await readFile(path.join(directory, `${name}.yaml`));
|
|
34
|
+
if (type.isNone(raw)) {
|
|
35
|
+
raw = await readFile(path.join(directory, `${name}.yml`));
|
|
36
|
+
}
|
|
37
|
+
if (type.isNone(raw)) {
|
|
38
|
+
throw new ConfigError(`Fixture "${name}" not found. Expected fixtures/${name}.yaml.`);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return YAML.parse(raw);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new ConfigError(`Fixture "${name}" is not valid YAML: ${error.message}`, {
|
|
44
|
+
cause: error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Reads fixtures/<name>.yaml under the config directory: a map keyed by
|
|
49
|
+
// connectionId - the same key a request test's `seed:` uses - to the documents
|
|
50
|
+
// that connection's collection should hold. Returns the connections in file
|
|
51
|
+
// order with `~d` markers revived to Dates. A pure reader: resolving the
|
|
52
|
+
// collection, dropping and inserting belong to whichever seeder calls it (the
|
|
53
|
+
// CLI test runner with the driver, the dev server through the connection layer).
|
|
54
|
+
async function readFixture({ configDirectory, name }) {
|
|
55
|
+
validateName({
|
|
56
|
+
name
|
|
57
|
+
});
|
|
58
|
+
const parsed = await readFixtureFile({
|
|
59
|
+
configDirectory,
|
|
60
|
+
name
|
|
61
|
+
});
|
|
62
|
+
if (!type.isObject(parsed)) {
|
|
63
|
+
throw new ConfigError(`Fixture "${name}" must be an object keyed by connectionId. Received ${JSON.stringify(parsed)}.`);
|
|
64
|
+
}
|
|
65
|
+
const connections = Object.keys(parsed).map((connectionId)=>{
|
|
66
|
+
const docs = parsed[connectionId];
|
|
67
|
+
if (!type.isArray(docs)) {
|
|
68
|
+
throw new ConfigError(`Fixture "${name}" key "${connectionId}" must be an array of documents. Received ${JSON.stringify(docs)}.`);
|
|
69
|
+
}
|
|
70
|
+
docs.forEach((doc, index)=>{
|
|
71
|
+
if (!type.isObject(doc)) {
|
|
72
|
+
throw new ConfigError(`Fixture "${name}" key "${connectionId}" document ${index} must be an object. Received ${JSON.stringify(doc)}.`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
connectionId,
|
|
77
|
+
docs: serializer.deserialize(docs)
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
name,
|
|
82
|
+
connections
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export default readFixture;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/node-utils",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260830202815",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lowdefy/errors": "0.0.0-experimental-
|
|
38
|
-
"@lowdefy/helpers": "0.0.0-experimental-
|
|
39
|
-
"fs-extra": "11.3.4"
|
|
37
|
+
"@lowdefy/errors": "0.0.0-experimental-20260830202815",
|
|
38
|
+
"@lowdefy/helpers": "0.0.0-experimental-20260830202815",
|
|
39
|
+
"fs-extra": "11.3.4",
|
|
40
|
+
"yaml": "2.9.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@swc/cli": "0.8.1",
|