jaypie 0.1.4 → 0.1.5

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.4",
3
+ "version": "0.1.5",
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.0"
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.1",
37
+ "@jaypie/lambda": "^0.1.3",
38
38
  "@jaypie/mongoose": "^0.1.1"
39
39
  },
40
40
  "peerDependenciesMeta": {
@@ -73,13 +73,24 @@ describe("Dynamic Export Function", () => {
73
73
  it("Returns an object", () => {
74
74
  expect(dynamicExport({ moduleImport: MOCK.MODULE })).toBeObject();
75
75
  });
76
- it("Scalars are undefined when module is not found", async () => {
76
+ it("If module is not found and you try to get a scalar it will throw", async () => {
77
77
  const vars = ["scalar"];
78
78
  const result = await dynamicExport({
79
79
  vars,
80
80
  moduleImport: MOCK.MODULE,
81
81
  });
82
- expect(result.scalar).toBeUndefined();
82
+ await expect(() => {
83
+ console.log("result.scalar :>> ", result.scalar);
84
+ try {
85
+ console.log("result.scalar.taco :>> ", result.scalar.taco);
86
+ } catch (error) {
87
+ console.log("error :>> ", error);
88
+ }
89
+ if (result.scalar) {
90
+ return true;
91
+ }
92
+ return false;
93
+ }).toThrow();
83
94
  });
84
95
  it("Exported functions throw if the real module is not installed", async () => {
85
96
  const functions = ["default"];
@@ -87,7 +98,17 @@ describe("Dynamic Export Function", () => {
87
98
  functions,
88
99
  moduleImport: MOCK.MODULE,
89
100
  });
90
- await expect(result.default).toThrow();
101
+ await expect(() => {
102
+ result.default();
103
+ }).toThrow();
104
+ });
105
+ it("Scalars that never existed are undefined", async () => {
106
+ const vars = ["scalar"];
107
+ const result = await dynamicExport({
108
+ vars,
109
+ moduleImport: MOCK.MODULE,
110
+ });
111
+ expect(result.bogus).toBeUndefined();
91
112
  });
92
113
  });
93
114
  describe("Features", () => {
@@ -56,37 +56,28 @@ export default async ({
56
56
  "Either `functions` or `vars` must be provided",
57
57
  );
58
58
  }
59
- // Setup
60
- let imported;
61
- const returning = {};
62
- // Preprocess
59
+ // Process
63
60
  try {
64
- imported = await dynamicImport(moduleImport);
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
- return returning;
69
+ // * Returns a proxy that throws if you call a functions or get a vars
70
+ return new Proxy(
71
+ {},
72
+ {
73
+ get: (target, prop) => {
74
+ if (functions.includes(prop) || vars.includes(prop)) {
75
+ throw new ConfigurationError(
76
+ `Attempted to access ${prop} from ${moduleImport}, but it is not installed`,
77
+ );
78
+ }
79
+ return undefined;
80
+ },
81
+ },
82
+ );
92
83
  };