metaforge

Library 📝 that allow you to describe data structures by subset of JavaScript syntax and validate them at runtime

MIT License

Downloads
10
Stars
3
Committers
1
metaforge - MetaForge V1.0.0 Latest Release

Published by sashapop10 12 months ago

Updates 2023-11-10

  • ES modules support & typescript support
  • Release version
metaforge - MetaForge V0.8.0

Published by sashapop10 12 months ago

Update 2023-11-08

JSDOC

To have JSDOC comments in your type annotations you need to add $meta field to your
schema; Also, your $meta properties should start with @;

Example

({
  reciever: 'number',
  money: 'number',
  $meta: {
    '@version': 'v1',
    '@name': 'Pay check',
    '@description': 'Cash settlement',
    '@example': '<caption>Check example</caption>\n{ money: 100, reciever: 2 }',
  },
});
metaforge - MetaForge V0.7.0

Published by sashapop10 12 months ago

Update 2023-11-08

Calculated fields

Calculated fields supposed to do preprocessing of your schema;

Warning: experimental. We do not support some types yet: Map, Set

Example

const schema = {
  $id: 'user',
  name: 'string',
  phrase: (sample, schema, root) => 'Hello ' + schema.name + ' !',
};
const sample = { name: 'Alexander' };
new Schema(schema).calc(sample); // { ..., name: 'Alexander', phrase: 'Hello Alexander !'};
schema; // { $id: 'user', name: 'Alexander', phrase: 'Hello Alexander !'};

Writing calculated fields

Calculated fields is a function that receives two arguments:

  • root: root object { input: Sample }
  • parent: assigned target object

Warning: your return value will be assigned to samples

Additional

Method schema.calc receives mode as second parameter; This method allow to specify
return value as:

  • Schema.calc(sample, true); // Returns copy of sample with assigned values
  • Schema.calc(sample); // Returns sample object with assigned values
metaforge - MetaForge V0.6.0

Published by sashapop10 12 months ago

Update 2023-11-06

  • Typescript generation module
  • Documentation fixes
metaforge - MetaForge V0.5.0

Published by sashapop10 12 months ago

Update 2023-11-05

  • Readme enhancement
  • JSDOC documentation
metaforge - MetaForge V0.4.0

Published by sashapop10 12 months ago

Update 2023-11-05

  • Support latest:21 node version

  • Removed parser (maybe temporary)

  • TypeScript .d.ts support

  • Schema field with multiple type variants now works only with special type union

  • Modular mechanism (internal rework): How it works

    const schema = new Schema();
    schema.register((schema, options, plan) => {}); //? Register new module
    

    By default registrated modules are:

    • Metatest module (Adds tests for prototypes)
    • Metatype module (Typescript parser)
    • Handyman (Quality of life module)

    But you also remove default modules:

    Schema.modules.delete('metatest');
    
  • New shorthands for:

    • enum example: ['winter', 'spring', 'summer, 'autumn']
    • tuple example: ['string', 'number']
    • object example: { a: string, b: number }
    • string example: 'string'
    • schema example: 'MyGlobalSchema'
    • schema#2 example: new Schema('string')
  • Removed preprocessor mechanism

  • Schemas now can be part of plan

  • Performance improvements (by removing unnecessary modules)

  • Lightweight inheritance

  • Removed type JSON (temporary)

  • Prototype chaining

  • Partial testing

  • New prototypes:

    • Tuple
    • Record
    • Schema
    • Union
metaforge - MetaForge V0.3.0

Published by sashapop10 about 1 year ago

Release 2023-10-16

  • Schema child method, now you can update only schema or only options for new schemas
  • Metadata fetcher, now you can gather all metadata by schema.meta
  • Fixed case when schema returns only methods without metadata, now it returns prototypes key with
    all metadata
  • Preprocess & postprocess for objects properties mutations
  • New prototype enum
  • Code cleanup & tests
metaforge - MetaForge V0.2.0

Published by sashapop10 about 1 year ago

Release 2023-10-16

  • Renamed astroplan -> metaforge
  • Meta information & Builded tree export issue
  • Custom checks (rules) issue
  • Allow custom types, schemas and rules to return value of string, array, boolean and SchemaError
    types;
metaforge - MetaForge V0.1.0

Published by sashapop10 about 1 year ago

Release 2023-10-16

  • Stable release version
  • Warnings before testing
  • Repository created
  • Namespaces, runtime schema checking, custom types
  • Default struct types: Array, Set, Map, Object
  • Default scalar types: String, Boolean, Number, BigInt
  • Default exotic types: Any, Undefined, JSON
  • Custom Errors