Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gasket/core

Package Overview
Dependencies
Maintainers
0
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasket/core - npm Package Compare versions

Comparing version 7.0.9 to 7.1.0-canary.1

27

cjs/engine.js

@@ -60,2 +60,16 @@ "use strict";

class GasketEngine {
registerPlugins(plugins) {
if (!plugins || !Array.isArray(plugins) || !plugins.length) {
throw new Error('An array of plugins is required');
}
this._hooks = {};
this._plans = {};
this._registerPlugins(plugins);
this._registerHooks();
this._registerActions();
// Allow methods to be called without context (to support destructuring)
lifecycleMethods.forEach((method)=>{
this[method] = this[method].bind(this);
});
}
_registerPlugins(plugins) {

@@ -535,15 +549,4 @@ // map the plugin name to module contents for easy lookup

constructor(plugins){
if (!plugins || !Array.isArray(plugins) || !plugins.length) {
throw new Error('An array of plugins is required');
}
this._hooks = {};
this._plans = {};
this._registerPlugins(plugins);
this._registerHooks();
this._registerActions();
// Allow methods to be called without context (to support destructuring)
lifecycleMethods.forEach((method)=>{
this[method] = this[method].bind(this);
});
this.registerPlugins(plugins);
}
}

@@ -22,2 +22,31 @@ /* eslint-disable no-console, no-process-env */ "use strict";

const _trace = require("./trace.js");
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
/**

@@ -51,3 +80,3 @@ * Get the environment to use for the gasket instance.

const env = getEnvironment();
/** @type {import('@gasket/core').GasketConfig} */ const config = (0, _config.applyConfigOverrides)(configDef, {
const config = (0, _config.applyConfigOverrides)(configDef, {
env

@@ -59,4 +88,4 @@ });

// prune nullish and/or empty plugins
config.plugins = config.plugins.filter(Boolean)// @ts-ignore - default not expected - quality of life for cjs apps
.map((plugin)=>plugin.default || plugin).filter((plugin)=>Boolean(plugin.name) || Boolean(plugin.hooks));
config.plugins = config.plugins.filter(Boolean).map((plugin)=>plugin.default || plugin) // quality of life for cjs apps
.filter((plugin)=>Boolean(plugin.name) || Boolean(plugin.hooks));
// start the engine

@@ -75,8 +104,16 @@ this.engine = new _engine.GasketEngine(config.plugins);

this.symbol = Symbol('gasket');
// @ts-ignore - attached lifecycle trace methods
// @ts-ignore
this.execSync('init');
// @ts-ignore - attached lifecycle trace methods
// @ts-ignore
this.config = this.execWaterfallSync('configure', config);
// @ts-ignore - attached lifecycle trace methods
this.exec('ready');
this.isReady = new Promise((resolve)=>{
var _this = this;
_async_to_generator(function*() {
// @ts-ignore - attached lifecycle trace methods
yield _this.exec('prepare');
// @ts-ignore - attached lifecycle trace methods
yield _this.exec('ready');
resolve();
})();
});
}

@@ -83,0 +120,0 @@ }

@@ -12,2 +12,6 @@ let dynamicNamingId = 0;

constructor(plugins) {
this.registerPlugins(plugins);
}
registerPlugins(plugins) {
if (!plugins || !Array.isArray(plugins) || !plugins.length) {

@@ -14,0 +18,0 @@ throw new Error('An array of plugins is required');

@@ -26,3 +26,2 @@ /* eslint-disable no-console, no-process-env */

* The Gasket class is the main entry point for the Gasket API.
* @type {import('@gasket/core').Gasket}
*/

@@ -36,3 +35,2 @@ export class Gasket {

const env = getEnvironment();
/** @type {import('@gasket/core').GasketConfig} */
const config = applyConfigOverrides(configDef, { env });

@@ -45,4 +43,3 @@ config.env = env;

.filter(Boolean)
// @ts-ignore - default not expected - quality of life for cjs apps
.map(plugin => plugin.default || plugin)
.map(plugin => plugin.default || plugin) // quality of life for cjs apps
.filter(plugin => Boolean(plugin.name) || Boolean(plugin.hooks));

@@ -67,8 +64,16 @@

// @ts-ignore - attached lifecycle trace methods
// @ts-ignore
this.execSync('init');
// @ts-ignore - attached lifecycle trace methods
// @ts-ignore
this.config = this.execWaterfallSync('configure', config);
// @ts-ignore - attached lifecycle trace methods
this.exec('ready');
this.isReady = new Promise((resolve) => {
(async () => {
// @ts-ignore - attached lifecycle trace methods
await this.exec('prepare');
// @ts-ignore - attached lifecycle trace methods
await this.exec('ready');
resolve();
})();
});
}

@@ -75,0 +80,0 @@

@@ -22,2 +22,3 @@ declare module '@gasket/core' {

ready(): MaybeAsync<void>
prepare(): MaybeAsync<void>
}

@@ -78,2 +79,3 @@

registerPlugins(plugins: Array<Plugin>): void;
exec<Id extends HookId>(

@@ -123,2 +125,3 @@ hook: Id,

config: GasketConfig;
engine: GasketEngine;
symbol: Symbol;

@@ -144,2 +147,3 @@ traceBranch(): GasketTrace

* Expected request shape for GasketActions
* @deprecated - use class from @gasket/request
*/

@@ -146,0 +150,0 @@ export interface GasketRequest {

{
"name": "@gasket/core",
"version": "7.0.9",
"version": "7.1.0-canary.1",
"description": "Entry point to setting up Gasket instances",

@@ -54,3 +54,3 @@ "type": "module",

"dependencies": {
"@gasket/utils": "^7.0.9",
"@gasket/utils": "7.1.0-canary.1",
"debug": "^4.3.4"

@@ -102,3 +102,3 @@ },

},
"gitHead": "ff3acd042a9a22cd43ac29c6b064bd2f49304b9e"
"gitHead": "79706568a4b2a7aa2621bf1f0bdaded08c396ed4"
}

@@ -43,8 +43,25 @@ # @gasket/core

When a new Gasket is created, there are three lifecycles executed in the
following order:
When a new Gasket is created, there are two lifecycles synchronous executed followed by two asynchronous lifecycles.
You can determine when the asynchronous lifecycles have completed by verifying that the `isReady` property on the Gasket instance has been resolved.
```js
import gasket from './gasket.js';
gasket.isReady.then(() => {
gasket.actions.startServer();
});
```
The lifecycles are executed in the following order:
Synchronous lifecycles
1. [init]
2. [configure]
2. [ready]
Asynchronous lifecycles
3. [prepare]
4. [ready]
### init

@@ -106,7 +123,31 @@

### prepare
The `prepare` lifecycle is the first asynchronous lifecycle executed after the `configure` lifecycle. It is used to add any additional setup that requires asynchronous operations.
```js
// gasket-plugin-example.js
const name = 'gasket-plugin-example';
const hooks = {
async prepare(gasket) {
const asyncConfig = await getAsyncConfig();
gasket.config = {
...gasket.config,
...asyncConfig
};
}
};
export default { name, hooks };
```
### ready
The `ready` lifecycle is the last lifecycle executed and is used to signal that
The `ready` is the last lifecycle executed and is used to signal that
the Gasket instance is fully initialized and ready to be used.
After the `ready` lifecycle has been executed, the `isReady` property on the Gasket instance will be resolved signaling the last step of the Gasket instance initialization.
```js

@@ -257,3 +298,4 @@ // gasket-plugin-example.js

[init]: #init
[configure]: #configure
[configure]: #configure
[prepare]: #prepare
[ready]: #ready

@@ -260,0 +302,0 @@ [actions]: #actions

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc