generated from astrohelm/node-workspace
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
138 additions
and
209 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function () {}; | ||
const prototypes = require('./proto'); | ||
const Schema = require('./schema'); | ||
|
||
module.exports = { Schema, prototypes }; |
File renamed without changes.
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,14 +1,8 @@ | ||
'use strict'; | ||
const PROTO = { | ||
...require('../types/proto/scalars'), | ||
enum: require('./enum'), | ||
}; | ||
|
||
const getPrototype = plan => { | ||
const isShorthand = typeof plan === 'string'; | ||
let type = isShorthand ? plan : plan.type; | ||
if (isShorthand) type = type.substring(1); | ||
return PROTO[type](plan); | ||
module.exports = { | ||
...require('./scalars'), | ||
...require('./objects'), | ||
...require('./arrays'), | ||
...require('./exotic'), | ||
}; | ||
|
||
module.exports = { PROTO, getPrototype }; |
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
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
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,22 @@ | ||
'use strict'; | ||
|
||
const preprocess = require('./preprocess'); | ||
module.exports = (types, tools, schema) => { | ||
const tests = preprocess(types, tools, schema); | ||
const { typeCondition = 'anyof' } = schema; | ||
return (sample, path = 'root') => { | ||
const handler = tools.conditions(typeCondition, tests.length - 1); | ||
const errors = []; | ||
for (let i = 0; i < tests.length; ++i) { | ||
const result = tests[i](sample, path); | ||
const [toDo, err] = handler(result, i); | ||
if (err) { | ||
if (result.length) errors.push(...result); | ||
else errors.push(`[${path}] => ${err}: ${JSON.stringify(sample)}`); | ||
} | ||
if (toDo === 'skip' || toDo === 'break') break; | ||
if (toDo === 'continue') continue; | ||
} | ||
return errors; | ||
}; | ||
}; |
File renamed without changes.
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 |
---|---|---|
@@ -1,26 +1,24 @@ | ||
'use strict'; | ||
|
||
const schemaFrom = require('./from'); | ||
const prototypes = require('../proto'); | ||
const arrayBuilder = (schema, { build }) => schema.items.map(v => build(v)); | ||
const [objectBuilder, createError] = [require('./object'), require('./error')]; | ||
const builders = { object: objectBuilder, array: arrayBuilder }; | ||
const tooling = { Error: createError(), ...require('./utils'), builders }; | ||
const build = require('./build'); | ||
|
||
//TODO Type fabric, to fix existed and passed types | ||
//TODO Parser that creates test for Schema, append Models, and tests it for errors | ||
const Schema = function (plan, options = {}) { | ||
const { namespace, types, rules } = options; | ||
module.exports = function Schema(schema, { errorPattern, ...options }) { | ||
const tools = { ...tooling, build: null, warn: null }; | ||
if (errorPattern) tools.Error = createError({ pattern: errorPattern }); | ||
const warn = options => { | ||
const err = new tooling.Error(options); | ||
return this.warnings.push(err), err; | ||
}; | ||
|
||
this.plan = plan; | ||
this.test = sample => { | ||
const isShorthand = typeof plan === 'string'; | ||
let planType = isShorthand ? plan : plan.type; | ||
if (isShorthand) { | ||
if (planType[0] === '?') planType = planType.substring(1); | ||
const errors = prototypes[planType](sample); | ||
} | ||
[tools.build, tools.warn] = [build.bind(null, options, tools), warn]; | ||
|
||
const result = { valid: true, errors: [] }; | ||
return result; | ||
}; | ||
this.warnings = []; | ||
this.test = tools.build(schema); | ||
return Object.freeze(this); | ||
}; | ||
|
||
module.exports = Schema; | ||
module.exports.from = sample => new Schema(schemaFrom(sample)); | ||
// schema check, dts generation, |
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,27 @@ | ||
{ | ||
"license": "MIT", | ||
"version": "1.2.0", | ||
"version": "0.1.0", | ||
"type": "commonjs", | ||
"name": "astrohelm-workspace", | ||
"name": "astroplan", | ||
"homepage": "https://astrohelm.ru", | ||
"description": "Astrohelm workspace example", | ||
"author": "Alexander Ivanov <[email protected]>", | ||
"keywords": [ | ||
"nodejs", | ||
"zero-dependencies", | ||
"prettier", | ||
"eslint", | ||
"ts", | ||
"workspace", | ||
"example", | ||
"preset", | ||
"starter-kit", | ||
"astrohelm", | ||
"javascript", | ||
"typescript" | ||
"testing", | ||
"metadata", | ||
"json", | ||
"schema", | ||
"validation", | ||
"types", | ||
"checker", | ||
"dsl", | ||
"metalanguage", | ||
"runtime-verification", | ||
"zero-dependencies", | ||
"type-generator", | ||
"astrohelm" | ||
], | ||
"main": "index.js", | ||
"types": "types/index.d.ts", | ||
|
@@ -28,7 +31,7 @@ | |
"node": "18 || 19 || 20" | ||
}, | ||
"browser": {}, | ||
"files": ["/dist", "/lib", "/types"], | ||
"files": ["/lib", "/types"], | ||
"scripts": { | ||
"test": "node --test", | ||
"dev": "node index.js", | ||
|
Oops, something went wrong.