-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Models and base babel build architecture
- Loading branch information
1 parent
14da567
commit 5bb5d10
Showing
18 changed files
with
1,867 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": false, | ||
"useBuiltIns": "usage", | ||
"corejs": 3 | ||
} | ||
], | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-optional-chaining" | ||
], | ||
"env": { | ||
"cjs": { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": 10, | ||
"browsers": [ | ||
">0.23%", | ||
"iOS >= 9", | ||
"Chrome >= 63", | ||
"safari >= 9", | ||
"IE >= 11" | ||
] | ||
}, | ||
"useBuiltIns": "usage", | ||
"corejs": 3 | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2020: true, | ||
}, | ||
extends: ["standard", "plugin:prettier/recommended"], | ||
parserOptions: { | ||
ecmaVersion: 11, | ||
sourceType: "module", | ||
}, | ||
rules: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/esm | ||
/lib | ||
*.log | ||
yarn.lock | ||
package-lock.json | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.babelrc | ||
.gitignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@module-federation/aegis", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"repository": "[email protected]:module-federation/aegis.git", | ||
"author": "Zack Jackson <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"format": "yarn pretty -- --write", | ||
"build": "npm run build:esm && npm run build:cjs", | ||
"build:esm": "babel --delete-dir-on-start -d esm/ src/ && cp -r ./src ./esm", | ||
"build:cjs": "babel --delete-dir-on-start --env-name cjs -d lib/ src/ && cp -r ./webpack ./lib/webpack", | ||
"prepublish": "yarn build" | ||
}, | ||
"peerDependencies": { | ||
"core-js": "^3" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.1", | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-proposal-optional-chaining": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/preset-react": "^7.12.5", | ||
"eslint": "^7.12.1", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.2", | ||
"prettier": "^2.1.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// "use strict"; | ||
|
||
// const BreakerStatus = { | ||
// tripped: [], | ||
// closed: [], | ||
// } | ||
|
||
// const CurcuitBreaker = function ({ observer, models }) { | ||
// function | ||
// return { | ||
// getStatus(port) { | ||
// const keys = Object.keys(BreakerStatus); | ||
// keys.filter(key => ) | ||
// } | ||
// }; | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import async from "../lib/async-error"; | ||
import domainEvents from "./domain-events"; | ||
|
||
/** | ||
* Steps through the sequence of port calls | ||
* in LIFO order executing their undo functions. | ||
* @param {import('.').Model} model | ||
* @returns {function():Promise<void>} | ||
*/ | ||
export default async function compensate(model) { | ||
try { | ||
const updated = await model.update({ compensate: true }); | ||
const portFlow = model.getPortFlow(); | ||
const ports = model.getPorts(); | ||
|
||
await updated.emit(domainEvents.undoStarted(updated), "undo starting"); | ||
|
||
const undoResult = await portFlow.reduceRight( | ||
async (_prev, port, index, arr) => { | ||
if (ports[port].undo) { | ||
console.log("calling undo on port: ", port); | ||
const result = await async(ports[port].undo(updated)); | ||
|
||
if (result.ok) { | ||
return arr.splice(0, index); | ||
} | ||
throw new Error("undo failed on port: ", port, result.error); | ||
} | ||
return arr.splice(0, index); | ||
} | ||
); | ||
|
||
if (undoResult.length > 0) { | ||
const lastPort = portFlow[undoResult.length - 1]; | ||
const msg = "undo incomplete, last port compensated " + lastPort; | ||
|
||
const recordPort = await updated.update({ | ||
lastPort, | ||
compensateResult: "INCOMPLETE", | ||
}); | ||
|
||
await recordPort.emit(domainEvents.undoFailed(model), msg); | ||
console.error(msg, updated); | ||
return; | ||
} | ||
|
||
const compensateResult = "COMPLETE"; | ||
await updated.emit(domainEvents.undoWorked(model), compensateResult); | ||
await updated.update({ compensateResult }); | ||
} catch (error) { | ||
console.error(error); | ||
await model.emit(domainEvents.undoFailed(model), error.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
|
||
const domainEvents = { | ||
portTimeout: model => `portTimeout:${model.getName()}`, | ||
portRetryWorked: model => `portRetryWorked:${model.getName()}`, | ||
undoStarted: model => `undoStart:${model.getName()}`, | ||
undoFailed: model => `undoFailed:${model.getName()}`, | ||
undoWorked: model => `undoWorked:${model.getName()}`, | ||
unauthorizedCommand: model => `unauthorizedCommand:${model.getName()}`, | ||
addModel: eventName => `addModel:${eventName}`, | ||
editModel: eventName => `editModel:${eventName}`, | ||
}; | ||
|
||
export default domainEvents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict' | ||
|
||
import { withId, withTimestamp } from './mixins'; | ||
import asyncPipe from '../lib/async-pipe'; | ||
import uuid from '../lib/uuid'; | ||
|
||
/** | ||
* @typedef {import('../models/model-factory').EventType} EventType | ||
*/ | ||
|
||
/** | ||
* @typedef {{ | ||
* factory: function(*):any, | ||
* args: any, | ||
* eventType: EventType, | ||
* modelName: String | ||
* }} options | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} Event | ||
* @property {EventType} eventType | ||
* @property {String} eventName | ||
* @property {String} eventTime | ||
* @property {String} modelName | ||
* @property {Object} modelData | ||
* @property {String} id | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
const Event = (() => { | ||
|
||
/** | ||
* @lends Event | ||
* @namespace | ||
* @class | ||
* @param {options} options | ||
* @returns {Promise<Readonly<Event>>} | ||
*/ | ||
const Event = async ({ | ||
factory, | ||
args, | ||
eventType, | ||
modelName | ||
}) => Promise.resolve( | ||
factory(args) | ||
).then(event => ({ | ||
...event, | ||
eventName: (eventType + modelName).toUpperCase(), | ||
eventType, | ||
modelName | ||
})) | ||
|
||
const makeEvent = asyncPipe( | ||
Event, | ||
withTimestamp('eventTime'), | ||
withId('id', uuid), | ||
Object.freeze | ||
); | ||
|
||
return { | ||
/** | ||
* Create event | ||
* @param {options} options | ||
* @returns {Promise<Readonly<Event>>} | ||
*/ | ||
create: async (options) => makeEvent(options) | ||
} | ||
})(); | ||
|
||
export default Event; | ||
|
||
|
Oops, something went wrong.