jaypie 1.0.20 → 1.0.22
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 +8 -14
- package/dist/jaypie.cjs.js +27 -84
- package/dist/jaypie.esm.js +3 -93
- package/package.json +2 -2
- package/rollup.config.mjs +1 -1
- package/src/index.js +3 -19
- package/src/index.cjs +0 -88
package/README.md
CHANGED
|
@@ -235,7 +235,7 @@ See `HTTP` for status codes.
|
|
|
235
235
|
|
|
236
236
|
``` javascript
|
|
237
237
|
// See `Error Reference` for full list
|
|
238
|
-
const { InternalError } = require("
|
|
238
|
+
const { InternalError } = require("jaypie");
|
|
239
239
|
|
|
240
240
|
try {
|
|
241
241
|
// Code happens...
|
|
@@ -336,7 +336,7 @@ Returns `false` for `false` (case-insensitive) and `0` for string, boolean, and
|
|
|
336
336
|
Returns `undefined` otherwise.
|
|
337
337
|
|
|
338
338
|
``` javascript
|
|
339
|
-
const { envBoolean } = require("
|
|
339
|
+
const { envBoolean } = require("jaypie");
|
|
340
340
|
|
|
341
341
|
process.env.AWESOME = true;
|
|
342
342
|
|
|
@@ -348,7 +348,7 @@ if (envBoolean("AWESOME")) {
|
|
|
348
348
|
##### `envBoolean`: `defaultValue`
|
|
349
349
|
|
|
350
350
|
``` javascript
|
|
351
|
-
const { envBoolean } = require("
|
|
351
|
+
const { envBoolean } = require("jaypie");
|
|
352
352
|
|
|
353
353
|
if (envBoolean("AWESOME", { defaultValue: true })) {
|
|
354
354
|
console.log("Awesome!");
|
|
@@ -368,15 +368,19 @@ argument = force([thing], Array);
|
|
|
368
368
|
// argument = [thing]
|
|
369
369
|
```
|
|
370
370
|
|
|
371
|
-
`force` supports Array, Object, and String.
|
|
371
|
+
`force` supports Array, Boolean, Number, Object, and String.
|
|
372
372
|
|
|
373
373
|
```javascript
|
|
374
374
|
argument = force(argument, Array);
|
|
375
|
+
argument = force(argument, Boolean, "true");
|
|
376
|
+
argument = force(argument, Number, "12");
|
|
375
377
|
argument = force(argument, Object, "key");
|
|
376
378
|
argument = force(argument, String, "default");
|
|
377
379
|
|
|
378
380
|
// Convenience functions
|
|
379
381
|
argument = force.array(argument);
|
|
382
|
+
argument = force.boolean(argument);
|
|
383
|
+
argument = force.number(argument);
|
|
380
384
|
argument = force.object(argument, "key");
|
|
381
385
|
argument = force.string(argument);
|
|
382
386
|
```
|
|
@@ -412,16 +416,6 @@ await sleep(2000);
|
|
|
412
416
|
|
|
413
417
|
_This is "bad code" because it checks `NODE_ENV` during runtime. The "right way" is to let sleep run and mock it in tests, in practice this is needless boilerplate. A fair compromise would be to mock `sleep` with `@jaypie/testkit` but not all projects include that dependency. Jaypie will trade academically incorrect for human convenience and simplicity._
|
|
414
418
|
|
|
415
|
-
#### `sleepAlways`
|
|
416
|
-
|
|
417
|
-
`sleepAlways` is a promise-based `setTimeout` that resolves after a specified number of milliseconds. It will run even when `NODE_ENV` is `test`. See `sleep` for a version that will NOT run in tests.
|
|
418
|
-
|
|
419
|
-
```javascript
|
|
420
|
-
import { sleepAlways } from "jaypie";
|
|
421
|
-
|
|
422
|
-
await sleepAlways(2000);
|
|
423
|
-
```
|
|
424
|
-
|
|
425
419
|
#### `validate`
|
|
426
420
|
|
|
427
421
|
```javascript
|
package/dist/jaypie.cjs.js
CHANGED
|
@@ -1,90 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@jaypie/core');
|
|
4
|
+
var aws = require('@jaypie/aws');
|
|
5
|
+
var lambda = require('@jaypie/lambda');
|
|
6
|
+
var mongoose = require('@jaypie/mongoose');
|
|
4
7
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// Helper Functions
|
|
8
|
-
//
|
|
9
8
|
|
|
10
|
-
const _importedModule = {};
|
|
11
|
-
function dynamicImport(module) {
|
|
12
|
-
if (!_importedModule[module]) {
|
|
13
|
-
try {
|
|
14
|
-
_importedModule[module] = require(module);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (process.env.NODE_ENV === "test") {
|
|
17
|
-
if (!_importedModule[module]) {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.warn(
|
|
20
|
-
`[jaypie] Caught error requiring ${module} -- Is it installed?`,
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
throw new core.ConfigurationError();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return _importedModule[module];
|
|
28
|
-
}
|
|
29
9
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} catch (error) {
|
|
55
|
-
core.log
|
|
56
|
-
.lib({ lib: core.JAYPIE.LIB.JAYPIE })
|
|
57
|
-
.trace(`[jaypie] ${moduleImport} could not be imported; continuing`);
|
|
58
|
-
}
|
|
59
|
-
// Return
|
|
60
|
-
const result = {};
|
|
61
|
-
functions.forEach((func) => {
|
|
62
|
-
result[func] = () => {
|
|
63
|
-
throw new core.ConfigurationError(`${moduleImport}.${func} is not available`);
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
vars.forEach((variable) => {
|
|
67
|
-
result[variable] = null;
|
|
68
|
-
});
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// Export
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
...dynamicExport({
|
|
79
|
-
functions: ["getMessages", "getSecret", "sendBatchMessages", "sendMessage"],
|
|
80
|
-
moduleImport: core.JAYPIE.LIB.AWS,
|
|
81
|
-
}),
|
|
82
|
-
...dynamicExport({
|
|
83
|
-
functions: ["lambdaHandler"],
|
|
84
|
-
moduleImport: core.JAYPIE.LIB.LAMBDA,
|
|
85
|
-
}),
|
|
86
|
-
...dynamicExport({
|
|
87
|
-
functions: ["connectFromSecretEnv", "disconnect"],
|
|
88
|
-
moduleImport: core.JAYPIE.LIB.MONGOOSE,
|
|
89
|
-
}),
|
|
90
|
-
};
|
|
10
|
+
Object.keys(core).forEach(function (k) {
|
|
11
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return core[k]; }
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
Object.keys(aws).forEach(function (k) {
|
|
17
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return aws[k]; }
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
Object.keys(lambda).forEach(function (k) {
|
|
23
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return lambda[k]; }
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
Object.keys(mongoose).forEach(function (k) {
|
|
29
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return mongoose[k]; }
|
|
32
|
+
});
|
|
33
|
+
});
|
package/dist/jaypie.esm.js
CHANGED
|
@@ -1,94 +1,4 @@
|
|
|
1
|
-
import { ConfigurationError, log, JAYPIE } from '@jaypie/core';
|
|
2
1
|
export * from '@jaypie/core';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Helper Functions
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
const _importedModule = {};
|
|
10
|
-
async function dynamicImport(module) {
|
|
11
|
-
if (!_importedModule[module]) {
|
|
12
|
-
try {
|
|
13
|
-
// eslint-disable-next-line import/no-unresolved
|
|
14
|
-
_importedModule[module] = await import(module);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (process.env.NODE_ENV === "test") {
|
|
17
|
-
if (!_importedModule[module]) {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.warn(
|
|
20
|
-
`[jaypie] Caught error importing ${module} -- Is it installed?`,
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
throw new ConfigurationError();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return _importedModule[module];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// Main
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
var dynamicExport = async ({
|
|
36
|
-
functions = ["default"],
|
|
37
|
-
moduleImport,
|
|
38
|
-
vars = [],
|
|
39
|
-
} = {}) => {
|
|
40
|
-
// Validate
|
|
41
|
-
if (!moduleImport || typeof moduleImport !== "string") {
|
|
42
|
-
throw new ConfigurationError("`moduleImport` must be a string");
|
|
43
|
-
}
|
|
44
|
-
if (!Array.isArray(functions)) {
|
|
45
|
-
throw new ConfigurationError("`functions` must be an array");
|
|
46
|
-
}
|
|
47
|
-
if (!Array.isArray(vars)) {
|
|
48
|
-
throw new ConfigurationError("`vars` must be an array");
|
|
49
|
-
}
|
|
50
|
-
if (!functions.length && !vars.length) {
|
|
51
|
-
throw new ConfigurationError(
|
|
52
|
-
"Either `functions` or `vars` must be provided",
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
// Process
|
|
56
|
-
try {
|
|
57
|
-
// Attempt to import the module
|
|
58
|
-
return await dynamicImport(moduleImport);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
log
|
|
61
|
-
.lib({ lib: JAYPIE.LIB.JAYPIE })
|
|
62
|
-
.trace(`[jaypie] ${moduleImport} could not be imported; continuing`);
|
|
63
|
-
}
|
|
64
|
-
// Return
|
|
65
|
-
const result = {};
|
|
66
|
-
functions.forEach((func) => {
|
|
67
|
-
result[func] = () => {
|
|
68
|
-
throw new ConfigurationError(`${moduleImport}.${func} is not available`);
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
vars.forEach((variable) => {
|
|
72
|
-
result[variable] = null;
|
|
73
|
-
});
|
|
74
|
-
return result;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Optional dependencies are wrapped in a dynamic import
|
|
78
|
-
const { getMessages, getSecret, sendBatchMessages, sendMessage } =
|
|
79
|
-
await dynamicExport({
|
|
80
|
-
functions: ["getMessages", "getSecret", "sendBatchMessages", "sendMessage"],
|
|
81
|
-
moduleImport: JAYPIE.LIB.AWS,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const { lambdaHandler } = await dynamicExport({
|
|
85
|
-
functions: ["lambdaHandler"],
|
|
86
|
-
moduleImport: JAYPIE.LIB.LAMBDA,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const { connectFromSecretEnv, disconnect } = await dynamicExport({
|
|
90
|
-
functions: ["connectFromSecretEnv", "disconnect"],
|
|
91
|
-
moduleImport: JAYPIE.LIB.MONGOOSE,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
export { connectFromSecretEnv, disconnect, getMessages, getSecret, lambdaHandler, sendBatchMessages, sendMessage };
|
|
2
|
+
export * from '@jaypie/aws';
|
|
3
|
+
export * from '@jaypie/lambda';
|
|
4
|
+
export * from '@jaypie/mongoose';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jaypie",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"author": "Finlayson Studio",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@jaypie/aws": "^1.0.5",
|
|
31
|
-
"@jaypie/core": "^1.0.
|
|
31
|
+
"@jaypie/core": "^1.0.26",
|
|
32
32
|
"@jaypie/lambda": "^1.0.4",
|
|
33
33
|
"@jaypie/mongoose": "^1.0.6"
|
|
34
34
|
},
|
package/rollup.config.mjs
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { JAYPIE } from "@jaypie/core";
|
|
2
|
-
import dynamicExport from "./dynamicExport.function.js";
|
|
3
|
-
|
|
4
1
|
//
|
|
5
2
|
//
|
|
6
3
|
// Export
|
|
@@ -9,19 +6,6 @@ import dynamicExport from "./dynamicExport.function.js";
|
|
|
9
6
|
// Required dependencies
|
|
10
7
|
export * from "@jaypie/core";
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
functions: ["getMessages", "getSecret", "sendBatchMessages", "sendMessage"],
|
|
16
|
-
moduleImport: JAYPIE.LIB.AWS,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const { lambdaHandler } = await dynamicExport({
|
|
20
|
-
functions: ["lambdaHandler"],
|
|
21
|
-
moduleImport: JAYPIE.LIB.LAMBDA,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const { connectFromSecretEnv, disconnect } = await dynamicExport({
|
|
25
|
-
functions: ["connectFromSecretEnv", "disconnect"],
|
|
26
|
-
moduleImport: JAYPIE.LIB.MONGOOSE,
|
|
27
|
-
});
|
|
9
|
+
export * from "@jaypie/aws";
|
|
10
|
+
export * from "@jaypie/lambda";
|
|
11
|
+
export * from "@jaypie/mongoose";
|
package/src/index.cjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ConfigurationError, JAYPIE, log } from "@jaypie/core";
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Helper Functions
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
const _importedModule = {};
|
|
9
|
-
function dynamicImport(module) {
|
|
10
|
-
if (!_importedModule[module]) {
|
|
11
|
-
try {
|
|
12
|
-
_importedModule[module] = require(module);
|
|
13
|
-
} catch (error) {
|
|
14
|
-
if (process.env.NODE_ENV === "test") {
|
|
15
|
-
if (!_importedModule[module]) {
|
|
16
|
-
// eslint-disable-next-line no-console
|
|
17
|
-
console.warn(
|
|
18
|
-
`[jaypie] Caught error requiring ${module} -- Is it installed?`,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
throw new ConfigurationError();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return _importedModule[module];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function dynamicExport({
|
|
29
|
-
functions = ["default"],
|
|
30
|
-
moduleImport,
|
|
31
|
-
vars = [],
|
|
32
|
-
} = {}) {
|
|
33
|
-
// Validate
|
|
34
|
-
if (!moduleImport || typeof moduleImport !== "string") {
|
|
35
|
-
throw new ConfigurationError("`moduleImport` must be a string");
|
|
36
|
-
}
|
|
37
|
-
if (!Array.isArray(functions)) {
|
|
38
|
-
throw new ConfigurationError("`functions` must be an array");
|
|
39
|
-
}
|
|
40
|
-
if (!Array.isArray(vars)) {
|
|
41
|
-
throw new ConfigurationError("`vars` must be an array");
|
|
42
|
-
}
|
|
43
|
-
if (!functions.length && !vars.length) {
|
|
44
|
-
throw new ConfigurationError(
|
|
45
|
-
"Either `functions` or `vars` must be provided",
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
// Process
|
|
49
|
-
try {
|
|
50
|
-
// Attempt to import the module
|
|
51
|
-
return dynamicImport(moduleImport);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
log
|
|
54
|
-
.lib({ lib: JAYPIE.LIB.JAYPIE })
|
|
55
|
-
.trace(`[jaypie] ${moduleImport} could not be imported; continuing`);
|
|
56
|
-
}
|
|
57
|
-
// Return
|
|
58
|
-
const result = {};
|
|
59
|
-
functions.forEach((func) => {
|
|
60
|
-
result[func] = () => {
|
|
61
|
-
throw new ConfigurationError(`${moduleImport}.${func} is not available`);
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
vars.forEach((variable) => {
|
|
65
|
-
result[variable] = null;
|
|
66
|
-
});
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
// Export
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
module.exports = {
|
|
76
|
-
...dynamicExport({
|
|
77
|
-
functions: ["getMessages", "getSecret", "sendBatchMessages", "sendMessage"],
|
|
78
|
-
moduleImport: JAYPIE.LIB.AWS,
|
|
79
|
-
}),
|
|
80
|
-
...dynamicExport({
|
|
81
|
-
functions: ["lambdaHandler"],
|
|
82
|
-
moduleImport: JAYPIE.LIB.LAMBDA,
|
|
83
|
-
}),
|
|
84
|
-
...dynamicExport({
|
|
85
|
-
functions: ["connectFromSecretEnv", "disconnect"],
|
|
86
|
-
moduleImport: JAYPIE.LIB.MONGOOSE,
|
|
87
|
-
}),
|
|
88
|
-
};
|