Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / exotic / @examples / CatalogStateFromApi.js
Size: Mime:
// @coerce @supports decorators !!!
// shouldDefault, shouldMerge, shouldRehydrate, shouldCoerce... ugh
class StringType {
  typeName = 'String'
  '@@native' = String
  '@@empty' = ''
  is = isString
  coerce = any => String | ''
  supports = tag => true
  coercers = [[+Type, toString]]
}

const choices = {
  // that means when they do `Number` vs `Number(1)`...
  canDefault: true,
  shouldDefault: true,

  canMerge: true,
  shouldMerge: true,

  canRehydrate: true,
  shouldRehydrate: true,

  shouldCoerce: true,
  isSupported: true,
  canCoerce: true,

  // would mean like `10.00` ?
  isFromSpecial: true,
  // NumberType.toFixed(2)
  isToSpecial: true,
  best: () => false,
}

// we have to `set` default... so scope will be outside of the type...
// '@@default': ''
function Schema(schema) {
  // traverse (like reshape)
  const built = {}
}

const fake = {
  eh: {
    skus: [{ identifier: 'skusie', value: 'oh' }],
    shouldMatch: [{ label: 'uh oh', value: 'oh no' }],
    children: {
      products: [
        {
          'identifier': 'prod-eh',
          'properties?': 'true',
          'digimon': '10.1',
          'nummy': '100',
        },
      ],
    },
  },
}
const toApi = {
  name: '?String',
  children: {
    products: Array,
  },
  properties: {
    iteminfo: {
      categoryids: Array,
      additionalinfo: Array,
    },
    state: {
      selectedFacets: Array,
      sorting: [
        {
          options: Array,
          selectedname: String,
        },
      ],
      productcount: Number(1),
    },
  },
  facets: Array,
}

const Indexed = {
  byId() {
    'byid'
  },
}

// entriesCount
// const EntriesType = Types()
//   .condition(data => data.get('entriesCount') > 0)
//   .coerce(data => {}).default('...')

const ShapeOfCatalogAPI = {
  name: String,
  children: {
    products: Array,
  },
  properties: {
    iteminfo: {
      categoryids: Array,
      additionalinfo: Array,
    },
    state: {
      selectedFacets: Array,
      sorting: [
        {
          options: Array,
          selectedname: String,
        },
      ],
      productcount: Number(1),
    },
  },
  facets: Array,
}
const CatalogShapeWeWant = {
  selectedFacets: Indexed.byId(),
  sorting: Indexed.byId(),
  selectedname: String('default name optionally'),
  productcount: Number(1),
}

const fromApi = {
  name: '?String',
  products: Indexed.byId(),
  state: CatalogState,
  categoryids: Array,
  info: Array,
  facets: Array,
  entries: EntriesType,
}
// const CatalogFromApi = {
//   name: String,
//   info: Array,
//   categoryids: [CategoryIds],
//   facets: [Facet],
//   products: Indexed.byId(),
//   state: CatalogState,
//   entries: EntriesType,
// }

const State = {
  starttime: Date,
}
const User = {
  id: Number,
}
const FilterSchema = {
  name: String('defaultable'),
  products: Array(ProductSchema),
  pricing: Money,
  cartinfo: Cart,
  flags: Type.to(Object).indexFrom(Array).propertyAsKey('property-here'),
  state: State,
  userinfo: User,
}

// class ObjectType extends Type {
//   // validPropertyIndex
//   // instanceOf
//   // ownPropertyIs
//   // hasIn
//   // propertyIs / hasInIs
//   // isFrozen
//   // isSealed
//   // isExtendable
//   // isObjWithKeys
//   // toObj
//   // toObjPlain
//   // toPlainObj
//   // isObj
//   // of
// }