jaypie 0.1.4 → 0.1.6
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jaypie",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"author": "Finlayson Studio",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test:spec:mongoose.package": "vitest run ./src/__tests__/mongoose.package.spec.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@jaypie/core": "^0.4.
|
|
20
|
+
"@jaypie/core": "^0.4.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@jaypie/testkit": "^1.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@jaypie/aws": "^0.1.1",
|
|
37
|
-
"@jaypie/lambda": "^0.1.
|
|
37
|
+
"@jaypie/lambda": "^0.1.3",
|
|
38
38
|
"@jaypie/mongoose": "^0.1.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
@@ -73,21 +73,31 @@ describe("Dynamic Export Function", () => {
|
|
|
73
73
|
it("Returns an object", () => {
|
|
74
74
|
expect(dynamicExport({ moduleImport: MOCK.MODULE })).toBeObject();
|
|
75
75
|
});
|
|
76
|
-
it("
|
|
76
|
+
it("Exported functions throw if the real module is not installed", async () => {
|
|
77
|
+
const functions = ["default"];
|
|
78
|
+
const result = await dynamicExport({
|
|
79
|
+
functions,
|
|
80
|
+
moduleImport: MOCK.MODULE,
|
|
81
|
+
});
|
|
82
|
+
await expect(() => {
|
|
83
|
+
result.default();
|
|
84
|
+
}).toThrow();
|
|
85
|
+
});
|
|
86
|
+
it("Vars return null if the real module is not installed", async () => {
|
|
77
87
|
const vars = ["scalar"];
|
|
78
88
|
const result = await dynamicExport({
|
|
79
89
|
vars,
|
|
80
90
|
moduleImport: MOCK.MODULE,
|
|
81
91
|
});
|
|
82
|
-
expect(result.scalar).
|
|
92
|
+
expect(result.scalar).toBeNull();
|
|
83
93
|
});
|
|
84
|
-
it("
|
|
85
|
-
const
|
|
94
|
+
it("Vars that never existed are undefined", async () => {
|
|
95
|
+
const vars = ["scalar"];
|
|
86
96
|
const result = await dynamicExport({
|
|
87
|
-
|
|
97
|
+
vars,
|
|
88
98
|
moduleImport: MOCK.MODULE,
|
|
89
99
|
});
|
|
90
|
-
|
|
100
|
+
expect(result.bogus).toBeUndefined();
|
|
91
101
|
});
|
|
92
102
|
});
|
|
93
103
|
describe("Features", () => {
|
|
@@ -56,37 +56,24 @@ export default async ({
|
|
|
56
56
|
"Either `functions` or `vars` must be provided",
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
-
//
|
|
60
|
-
let imported;
|
|
61
|
-
const returning = {};
|
|
62
|
-
// Preprocess
|
|
59
|
+
// Process
|
|
63
60
|
try {
|
|
64
|
-
|
|
61
|
+
// Attempt to import the module
|
|
62
|
+
return await dynamicImport(moduleImport);
|
|
65
63
|
} catch (error) {
|
|
66
64
|
moduleLogger.trace(
|
|
67
65
|
`[jaypie] ${moduleImport} could not be imported; continuing`,
|
|
68
66
|
);
|
|
69
67
|
}
|
|
70
|
-
// Process
|
|
71
|
-
for (const key of functions) {
|
|
72
|
-
if (imported) {
|
|
73
|
-
returning[key] = imported[key];
|
|
74
|
-
} else {
|
|
75
|
-
returning[key] = () => {
|
|
76
|
-
throw new ConfigurationError(
|
|
77
|
-
`Function ${key} cannot be called because ${moduleImport} is not installed`,
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (const key of vars) {
|
|
83
|
-
if (imported) {
|
|
84
|
-
returning[key] = imported[key];
|
|
85
|
-
} else {
|
|
86
|
-
// TODO: make the not found vars throw only _when accessed_
|
|
87
|
-
returning[key] = undefined;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
68
|
// Return
|
|
91
|
-
|
|
69
|
+
const result = {};
|
|
70
|
+
functions.forEach((func) => {
|
|
71
|
+
result[func] = () => {
|
|
72
|
+
throw new ConfigurationError(`${moduleImport}.${func} is not available`);
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
vars.forEach((variable) => {
|
|
76
|
+
result[variable] = null;
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
92
79
|
};
|