Best JavaScript code snippet using playwright-internal
Either.spec.js
Source:Either.spec.js
...13const isSameType = require('../core/isSameType')14const unit = require('../core/_unit')15const fl = require('../core/flNames')16const either =17 (f, g) => m => m.either(f, g)18const applyTo =19 x => fn => fn(x)20const constant = x => () => x21const identity = x => x22const testCircularReference = (t, fn) => {23 const objectWithCircularReference = {}24 const ref = { objectWithCircularReference }25 objectWithCircularReference.ref = ref26 t.doesNotThrow(() => fn(objectWithCircularReference), 'does not throw when called with an object containing a circular reference')27}28const Either = require('.')29test('Either', t => {30 const m = Either(0)31 t.ok(isFunction(Either), 'is a function')32 t.ok(isObject(m), 'returns an object')33 t.equals(Either.Right(0).constructor, Either, 'provides TypeRep on constructor for Right')34 t.equals(Either.Left(0).constructor, Either, 'provides TypeRep on constructor for Left')35 t.ok(isFunction(Either.of), 'provides an of function')36 t.ok(isFunction(Either.Left), 'provides a Left function')37 t.ok(isFunction(Either.Right), 'provides a Right function')38 t.ok(isFunction(Either.type), 'provides a type function')39 t.ok(isString(Either['@@type']), 'provides a @@type string')40 const err = /Either: Must wrap something, try using Left or Right constructors/41 t.throws(Either, err, 'throws with no parameters')42 t.end()43})44test('Either fantasy-land api', t => {45 const l = Either.Left('')46 const r = Either.Right('')47 t.ok(isFunction(Either[fl.of]), 'provides of function on constructor')48 t.ok(isFunction(l[fl.of]), 'provides of method on left instance')49 t.ok(isFunction(l[fl.equals]), 'provides equals method on left instance')50 t.ok(isFunction(l[fl.alt]), 'provides alt method on left instance')51 t.ok(isFunction(l[fl.bimap]), 'provides bimap method on left instance')52 t.ok(isFunction(l[fl.chain]), 'provides chain method on left instance')53 t.ok(isFunction(l[fl.concat]), 'provides concat method on left instance')54 t.ok(isFunction(l[fl.map]), 'provides map method on left instance')55 t.ok(isFunction(r[fl.of]), 'provides of method on right instance')56 t.ok(isFunction(r[fl.equals]), 'provides equals method on right instance')57 t.ok(isFunction(r[fl.alt]), 'provides alt method on right instance')58 t.ok(isFunction(r[fl.bimap]), 'provides bimap method on right instance')59 t.ok(isFunction(r[fl.chain]), 'provides chain method on right instance')60 t.ok(isFunction(r[fl.concat]), 'provides concat method on right instance')61 t.ok(isFunction(r[fl.map]), 'provides map method on right instance')62 t.end()63})64test('Either @@implements', t => {65 const f = Either['@@implements']66 t.equal(f('alt'), true, 'implements alt func')67 t.equal(f('ap'), true, 'implements ap func')68 t.equal(f('bimap'), true, 'implements bimap func')69 t.equal(f('chain'), true, 'implements chain func')70 t.equal(f('concat'), true, 'implements concat func')71 t.equal(f('equals'), true, 'implements equals func')72 t.equal(f('map'), true, 'implements map func')73 t.equal(f('of'), true, 'implements of func')74 t.equal(f('traverse'), true, 'implements traverse func')75 t.end()76})77test('Either.Left', t => {78 const l = Either.Left('value')79 t.equal(l.either(identity, constant('right')), 'value', 'creates an Either.Left')80 testCircularReference(t, Either.Left)81 t.end()82})83test('Either.Right', t => {84 const r = Either.Right('value')85 t.equal(r.either(constant('left'), identity), 'value', 'creates an Either.Right')86 testCircularReference(t, Either.Right)87 t.end()88})89test('Either inspect', t => {90 const l = Either.Left(0)91 const r = Either.Right(1)92 t.ok(isFunction(l.inspect), 'Left provides an inspect function')93 t.equal(l.inspect, l.toString, 'Left toString is the same function as inspect')94 t.ok(isFunction(r.inspect), 'Right provides an inpsect function')95 t.equal(r.inspect, r.toString, 'Right toString is the same function as inspect')96 t.equal(l.inspect(), 'Left 0', 'Left returns inspect string')97 t.equal(r.inspect(), 'Right 1', 'Right returns inspect string')98 t.end()99})100test('Either type', t => {101 const { Left, Right } = Either102 t.ok(isFunction(Right(0).type), 'is a function on Right')103 t.ok(isFunction(Left(0).type), 'is a function on Left')104 t.equal(Right(0).type, Either.type, 'static and instance versions are the same for Right')105 t.equal(Left(0).type, Either.type, 'static and instance versions are the same for Left')106 t.equal(Right(0).type(), 'Either', 'type returns Either for Right')107 t.equal(Left(0).type(), 'Either', 'type returns Either for Left')108 t.end()109})110test('Either @@type', t => {111 const { Left, Right } = Either112 t.equal(Right(0)['@@type'], Either['@@type'], 'static and instance versions are the same for Right')113 t.equal(Left(0)['@@type'], Either['@@type'], 'static and instance versions are the same for Left')114 t.equal(Right(0)['@@type'], 'crocks/Either@4', 'returns crocks/Either@4 for Right')115 t.equal(Left(0)['@@type'], 'crocks/Either@4', 'returns crocks/Either@4 for Left')116 t.end()117})118test('Either either', t => {119 const l = Either.Left('left')120 const r = Either.Right('right')121 const fn = bindFunc(Either.Right(23).either)122 const err = /Either.either: Requires both left and right functions/123 t.throws(fn(), err, 'throws when nothing passed')124 t.throws(fn(null, unit), err, 'throws with null in left')125 t.throws(fn(undefined, unit), err, 'throws with undefined in left')126 t.throws(fn(0, unit), err, 'throws with falsey number in left')127 t.throws(fn(1, unit), err, 'throws with truthy number in left')128 t.throws(fn('', unit), err, 'throws with falsey string in left')129 t.throws(fn('string', unit), err, 'throws with truthy string in left')130 t.throws(fn(false, unit), err, 'throws with false in left')131 t.throws(fn(true, unit), err, 'throws with true in left')132 t.throws(fn({}, unit), err, 'throws with object in left')133 t.throws(fn([], unit), err, 'throws with array in left')134 t.throws(fn(unit, null), err, 'throws with null in right')135 t.throws(fn(unit, undefined), err, 'throws with undefined in right')136 t.throws(fn(unit, 0), err, 'throws with falsey number in right')137 t.throws(fn(unit, 1), err, 'throws with truthy number in right')138 t.throws(fn(unit, ''), err, 'throws with falsey string in right')139 t.throws(fn(unit, 'string'), err, 'throws with truthy string in right')140 t.throws(fn(unit, false), err, 'throws with false in right')141 t.throws(fn(unit, true), err, 'throws with true in right')142 t.throws(fn(unit, {}), err, 'throws with object in right')143 t.throws(fn(unit, []), err, 'throws with array in right')144 t.equal(l.either(identity, constant('right')), 'left', 'returns left function result when called on a Left')145 t.equal(r.either(constant('left'), identity), 'right', 'returns right function result when called on a Right')146 t.end()147})148test('Either swap', t => {149 const fn = bindFunc(Either.Right(23).swap)150 const err = /Either.swap: Requires both left and right functions/151 t.throws(fn(null, unit), err, 'throws with null in left')152 t.throws(fn(undefined, unit), err, 'throws with undefined in left')153 t.throws(fn(0, unit), err, 'throws with falsey number in left')154 t.throws(fn(1, unit), err, 'throws with truthy number in left')155 t.throws(fn('', unit), err, 'throws with falsey string in left')156 t.throws(fn('string', unit), err, 'throws with truthy string in left')157 t.throws(fn(false, unit), err, 'throws with false in left')158 t.throws(fn(true, unit), err, 'throws with true in left')159 t.throws(fn({}, unit), err, 'throws with object in left')160 t.throws(fn([], unit), err, 'throws with array in left')161 t.throws(fn(unit, null), err, 'throws with null in right')162 t.throws(fn(unit, undefined), err, 'throws with undefined in right')163 t.throws(fn(unit, 0), err, 'throws with falsey number in right')164 t.throws(fn(unit, 1), err, 'throws with truthy number in right')165 t.throws(fn(unit, ''), err, 'throws with falsey string in right')166 t.throws(fn(unit, 'string'), err, 'throws with truthy string in right')167 t.throws(fn(unit, false), err, 'throws with false in right')168 t.throws(fn(unit, true), err, 'throws with true in right')169 t.throws(fn(unit, {}), err, 'throws with object in right')170 t.throws(fn(unit, []), err, 'throws with array in right')171 const l = Either.Left('here').swap(constant('left'), identity)172 const r = Either.Right('here').swap(identity, constant('right'))173 t.ok(l.equals(Either.Right('left')), 'returns an Either.Right wrapping left')174 t.ok(r.equals(Either.Left('right')), 'returns an Either.Left wrapping right')175 t.end()176})177test('Either coalesce', t => {178 const fn = bindFunc(Either.Right(23).coalesce)179 const err = /Either.coalesce: Requires both left and right functions/180 t.throws(fn(null, unit), err, 'throws with null in left')181 t.throws(fn(undefined, unit), err, 'throws with undefined in left')182 t.throws(fn(0, unit), err, 'throws with falsey number in left')183 t.throws(fn(1, unit), err, 'throws with truthy number in left')184 t.throws(fn('', unit), err, 'throws with falsey string in left')185 t.throws(fn('string', unit), err, 'throws with truthy string in left')186 t.throws(fn(false, unit), err, 'throws with false in left')187 t.throws(fn(true, unit), err, 'throws with true in left')188 t.throws(fn({}, unit), err, 'throws with object in left')189 t.throws(fn([], unit), err, 'throws with array in left')190 t.throws(fn(unit, null), err, 'throws with null in right')191 t.throws(fn(unit, undefined), err, 'throws with undefined in right')192 t.throws(fn(unit, 0), err, 'throws with falsey number in right')193 t.throws(fn(unit, 1), err, 'throws with truthy number in right')194 t.throws(fn(unit, ''), err, 'throws with falsey string in right')195 t.throws(fn(unit, 'string'), err, 'throws with truthy string in right')196 t.throws(fn(unit, false), err, 'throws with false in right')197 t.throws(fn(unit, true), err, 'throws with true in right')198 t.throws(fn(unit, {}), err, 'throws with object in right')199 t.throws(fn(unit, []), err, 'throws with array in right')200 const l = Either.Left('here').coalesce(constant('was left'), identity)201 const r = Either.Right('here').coalesce(identity, constant('was right'))202 t.ok(l.equals(Either.Right('was left')),'returns an Either.Right wrapping was left' )203 t.ok(r.equals(Either.Right('was right')),'returns an Either.Right wrapping was right' )204 t.end()205})206test('Either bichain left errors', t => {207 const { Left } = Either208 const bichain = bindFunc(Left(0).bichain)209 const err = /Either.bichain: Both arguments must be Either returning functions/210 t.throws(bichain(undefined, Left), err, 'throws with undefined on left')211 t.throws(bichain(null, Left), err, 'throws with null on left')212 t.throws(bichain(0, Left), err, 'throws with falsy number on left')213 t.throws(bichain(1, Left), err, 'throws with truthy number on left')214 t.throws(bichain('', Left), err, 'throws with falsy string on left')215 t.throws(bichain('string', Left), err, 'throws with truthy string on left')216 t.throws(bichain(false, Left), err, 'throws with false on left')217 t.throws(bichain(true, Left), err, 'throws with true on left')218 t.throws(bichain([], Left), err, 'throws with an array on left')219 t.throws(bichain({}, Left), err, 'throws with an object on left')220 t.throws(bichain(unit, Left), err, 'throws with a non-Either returning function')221 t.end()222})223test('Either bichain right errors', t => {224 const { Right } = Either225 const bichain = bindFunc(Right(0).bichain)226 const err = /Either.bichain: Both arguments must be Either returning functions/227 t.throws(bichain(Right, undefined), err, 'throws with undefined on left')228 t.throws(bichain(Right, null), err, 'throws with null on left')229 t.throws(bichain(Right, 0), err, 'throws with falsy number on left')230 t.throws(bichain(Right, 1), err, 'throws with truthy number on left')231 t.throws(bichain(Right, ''), err, 'throws with falsy string on left')232 t.throws(bichain(Right, 'string'), err, 'throws with truthy string on left')233 t.throws(bichain(Right, false), err, 'throws with false on left')234 t.throws(bichain(Right, true), err, 'throws with true on left')235 t.throws(bichain(Right, []), err, 'throws with an array on left')236 t.throws(bichain(Right, {}), err, 'throws with an object on left')237 t.throws(bichain(Right, unit), err, 'throws with a non-Either returning function')238 t.end()239})240test('Either bichain functionality', t => {241 const { Left, Right } = Either242 const left = x => Left(x + 1)243 const right = x => Right(x + 1)244 t.ok(equals(Left(0).bichain(right, left), Right(1)), 'moves from Left to Right')245 t.ok(equals(Right(0).bichain(right, left), Left(1)), 'moves from Right to Left')246 t.ok(equals(Right(0).bichain(left, right), Right(1)), 'moves from Right to Right')247 t.ok(equals(Left(0).bichain(left, right), Left(1)), 'moves from Left to Left')248 t.end()249})250test('Either concat errors', t => {251 const m = { type: () => 'Either...Not' }252 const good = Either.Right([])253 const f = bindFunc(Either.Right([]).concat)254 const nonEitherErr = /Either.concat: Either of Semigroup required/255 t.throws(f(undefined), nonEitherErr, 'throws with undefined on Right')256 t.throws(f(null), nonEitherErr, 'throws with null on Right')257 t.throws(f(0), nonEitherErr, 'throws with falsey number on Right')258 t.throws(f(1), nonEitherErr, 'throws with truthy number on Right')259 t.throws(f(''), nonEitherErr, 'throws with falsey string on Right')260 t.throws(f('string'), nonEitherErr, 'throws with truthy string on Right')261 t.throws(f(false), nonEitherErr, 'throws with false on Right')262 t.throws(f(true), nonEitherErr, 'throws with true on Right')263 t.throws(f([]), nonEitherErr, 'throws with array on Right')264 t.throws(f({}), nonEitherErr, 'throws with object on Right')265 t.throws(f(m), nonEitherErr, 'throws with non-Either on Right')266 const g = bindFunc(Either.Left(0).concat)267 t.throws(g(undefined), nonEitherErr, 'throws with undefined on Left')268 t.throws(g(null), nonEitherErr, 'throws with null on Left')269 t.throws(g(0), nonEitherErr, 'throws with falsey number on Left')270 t.throws(g(1), nonEitherErr, 'throws with truthy number on Left')271 t.throws(g(''), nonEitherErr, 'throws with falsey string on Left')272 t.throws(g('string'), nonEitherErr, 'throws with truthy string on Left')273 t.throws(g(false), nonEitherErr, 'throws with false on Left')274 t.throws(g(true), nonEitherErr, 'throws with true on Left')275 t.throws(g([]), nonEitherErr, 'throws with array on Left')276 t.throws(g({}), nonEitherErr, 'throws with object on Left')277 t.throws(g(m), nonEitherErr, 'throws with non-Either on Left')278 const innerErr = /Either.concat: Both containers must contain Semigroups of the same type/279 const notSemiLeft = bindFunc(x => Either.Right(x).concat(good))280 t.throws(notSemiLeft(undefined), innerErr, 'throws with undefined on left')281 t.throws(notSemiLeft(null), innerErr, 'throws with null on left')282 t.throws(notSemiLeft(0), innerErr, 'throws with falsey number on left')283 t.throws(notSemiLeft(1), innerErr, 'throws with truthy number on left')284 t.throws(notSemiLeft(''), innerErr, 'throws with falsey string on left')285 t.throws(notSemiLeft('string'), innerErr, 'throws with truthy string on left')286 t.throws(notSemiLeft(false), innerErr, 'throws with false on left')287 t.throws(notSemiLeft(true), innerErr, 'throws with true on left')288 t.throws(notSemiLeft({}), innerErr, 'throws with object on left')289 const notSemiRight = bindFunc(x => good.concat(Either.Right(x)))290 t.throws(notSemiRight(undefined), innerErr, 'throws with undefined on right')291 t.throws(notSemiRight(null), innerErr, 'throws with null on right')292 t.throws(notSemiRight(0), innerErr, 'throws with falsey number on right')293 t.throws(notSemiRight(1), innerErr, 'throws with truthy number on right')294 t.throws(notSemiRight(''), innerErr, 'throws with falsey string on right')295 t.throws(notSemiRight('string'), innerErr, 'throws with truthy string on right')296 t.throws(notSemiRight(false), innerErr, 'throws with false on right')297 t.throws(notSemiRight(true), innerErr, 'throws with true on right')298 t.throws(notSemiRight({}), innerErr, 'throws with object on right')299 const noMatch = bindFunc(() => good.concat(Either.Right('')))300 t.throws(noMatch({}), innerErr, 'throws with different semigroups')301 t.end()302})303test('Either concat fantasy-land errors', t => {304 const m = { type: () => 'Either...Not' }305 const good = Either.Right([])306 const f = bindFunc(Either.Right([])[fl.concat])307 const nonEitherErr = /Either.fantasy-land\/concat: Either of Semigroup required/308 t.throws(f(undefined), nonEitherErr, 'throws with undefined on Right')309 t.throws(f(null), nonEitherErr, 'throws with null on Right')310 t.throws(f(0), nonEitherErr, 'throws with falsey number on Right')311 t.throws(f(1), nonEitherErr, 'throws with truthy number on Right')312 t.throws(f(''), nonEitherErr, 'throws with falsey string on Right')313 t.throws(f('string'), nonEitherErr, 'throws with truthy string on Right')314 t.throws(f(false), nonEitherErr, 'throws with false on Right')315 t.throws(f(true), nonEitherErr, 'throws with true on Right')316 t.throws(f([]), nonEitherErr, 'throws with array on Right')317 t.throws(f({}), nonEitherErr, 'throws with object on Right')318 t.throws(f(m), nonEitherErr, 'throws with non-Either on Right')319 const g = bindFunc(Either.Left(0)[fl.concat])320 t.throws(g(undefined), nonEitherErr, 'throws with undefined on Left')321 t.throws(g(null), nonEitherErr, 'throws with null on Left')322 t.throws(g(0), nonEitherErr, 'throws with falsey number on Left')323 t.throws(g(1), nonEitherErr, 'throws with truthy number on Left')324 t.throws(g(''), nonEitherErr, 'throws with falsey string on Left')325 t.throws(g('string'), nonEitherErr, 'throws with truthy string on Left')326 t.throws(g(false), nonEitherErr, 'throws with false on Left')327 t.throws(g(true), nonEitherErr, 'throws with true on Left')328 t.throws(g([]), nonEitherErr, 'throws with array on Left')329 t.throws(g({}), nonEitherErr, 'throws with object on Left')330 t.throws(g(m), nonEitherErr, 'throws with non-Either on Left')331 const innerErr = /Either.fantasy-land\/concat: Both containers must contain Semigroups of the same type/332 const notSemiLeft = bindFunc(x => Either.Right(x)[fl.concat](good))333 t.throws(notSemiLeft(undefined), innerErr, 'throws with undefined on left')334 t.throws(notSemiLeft(null), innerErr, 'throws with null on left')335 t.throws(notSemiLeft(0), innerErr, 'throws with falsey number on left')336 t.throws(notSemiLeft(1), innerErr, 'throws with truthy number on left')337 t.throws(notSemiLeft(''), innerErr, 'throws with falsey string on left')338 t.throws(notSemiLeft('string'), innerErr, 'throws with truthy string on left')339 t.throws(notSemiLeft(false), innerErr, 'throws with false on left')340 t.throws(notSemiLeft(true), innerErr, 'throws with true on left')341 t.throws(notSemiLeft({}), innerErr, 'throws with object on left')342 const notSemiRight = bindFunc(x => good[fl.concat](Either.Right(x)))343 t.throws(notSemiRight(undefined), innerErr, 'throws with undefined on right')344 t.throws(notSemiRight(null), innerErr, 'throws with null on right')345 t.throws(notSemiRight(0), innerErr, 'throws with falsey number on right')346 t.throws(notSemiRight(1), innerErr, 'throws with truthy number on right')347 t.throws(notSemiRight(''), innerErr, 'throws with falsey string on right')348 t.throws(notSemiRight('string'), innerErr, 'throws with truthy string on right')349 t.throws(notSemiRight(false), innerErr, 'throws with false on right')350 t.throws(notSemiRight(true), innerErr, 'throws with true on right')351 t.throws(notSemiRight({}), innerErr, 'throws with object on right')352 const noMatch = bindFunc(() => good[fl.concat](Either.Right('')))353 t.throws(noMatch({}), innerErr, 'throws with different semigroups')354 t.end()355})356test('Either concat functionality', t => {357 const extract =358 either(identity, identity)359 const left = Either.Left('Left')360 const a = Either.Right([ 1, 2 ])361 const b = Either.Right([ 4, 3 ])362 const right = a.concat(b)363 const leftRight = a.concat(left)364 const leftLeft = left.concat(a)365 t.ok(isSameType(Either, right), 'returns another Either with Right')366 t.ok(isSameType(Either, leftRight), 'returns another Either with Left on right side')367 t.ok(isSameType(Either, leftLeft), 'returns another Either with Left on left side')368 t.same(extract(right), [ 1, 2, 4, 3 ], 'concats the inner semigroup with Rights')369 t.equals(extract(leftRight), 'Left', 'returns a Left with a Left on right side')370 t.equals(extract(leftLeft), 'Left', 'returns a Left with a Left on left side')371 t.end()372})373test('Either concat properties (Semigroup)', t => {374 const extract =375 either(identity, identity)376 const a = Either.Right([ 'a' ])377 const b = Either.Right([ 'b' ])378 const c = Either.Right([ 'c' ])379 const left = a.concat(b).concat(c)380 const right = a.concat(b.concat(c))381 t.ok(isFunction(a.concat), 'provides a concat function')382 t.same(extract(left), extract(right), 'associativity')383 t.ok(isArray(extract(a.concat(b))), 'returns an Array')384 t.end()385})386test('Either equals functionality', t => {387 const la = Either.Left(0)388 const lb = Either.Left(0)389 const lc = Either.Left(1)390 const ra = Either.Right(0)391 const rb = Either.Right(0)392 const rc = Either.Right(1)393 const value = 1394 const nonEither = { type: 'Either...Not' }395 t.equal(la.equals(lc), false, 'returns false when 2 Left Eithers are not equal')396 t.equal(la.equals(lb), true, 'returns true when 2 Left Eithers are equal')397 t.equal(lc.equals(value), false, 'returns when Left passed a simple value')398 t.equal(ra.equals(rc), false, 'returns false when 2 Right Eithers are not equal')399 t.equal(ra.equals(rb), true, 'returns true when 2 Right Eithers are equal')400 t.equal(rc.equals(value), false, 'returns when Right passed a simple value')401 t.equal(la.equals(nonEither), false, 'returns false when passed a non-Either')402 t.equal(ra.equals(lb), false, 'returns false when Left compared to Right')403 t.end()404})405test('Either equals properties (Setoid)', t => {406 const la = Either.Left({ a: 'nice' })407 const lb = Either.Left({ a: 'nice' })408 const lc = Either.Left({ a: 'nice', b: 45 })409 const ld = Either.Left({ a: 'nice' })410 const ra = Either.Right([ 1, 2 ])411 const rb = Either.Right([ 1, 2 ])412 const rc = Either.Right([ 3, 2, 1 ])413 const rd = Either.Right([ 1, 2 ])414 t.ok(isFunction(Either(null).equals), 'provides an equals function')415 t.equal(la.equals(la), true, 'Left reflexivity')416 t.equal(la.equals(lb), lb.equals(la), 'Left symmetry (equal)')417 t.equal(la.equals(lc), lc.equals(la), 'Left symmetry (!equal)')418 t.equal(la.equals(lb) && lb.equals(ld), la.equals(ld), 'Left transitivity')419 t.equal(ra.equals(ra), true, 'Right reflexivity')420 t.equal(ra.equals(rb), rb.equals(ra), 'Right symmetry (equal)')421 t.equal(ra.equals(rc), rc.equals(ra), 'Right symmetry (!equal)')422 t.equal(ra.equals(rb) && rb.equals(rd), ra.equals(rd), 'Right transitivity')423 t.end()424})425test('Either map errors', t => {426 const rmap = bindFunc(Either.Right(0).map)427 const lmap = bindFunc(Either.Left(0).map)428 const err = /Either.map: Function required/429 t.throws(rmap(undefined), err, 'right map throws with undefined')430 t.throws(rmap(null), err, 'right map throws with null')431 t.throws(rmap(0), err, 'right map throws with falsey number')432 t.throws(rmap(1), err, 'right map throws with truthy number')433 t.throws(rmap(''), err, 'right map throws with falsey string')434 t.throws(rmap('string'), err, 'right map throws with truthy string')435 t.throws(rmap(false), err, 'right map throws with false')436 t.throws(rmap(true), err, 'right map throws with true')437 t.throws(rmap([]), err, 'right map throws with an array')438 t.throws(rmap({}), err, 'right map throws iwth object')439 t.doesNotThrow(rmap(unit), 'right map does not throw when passed a function')440 t.throws(lmap(undefined), err, 'left map throws with undefined')441 t.throws(lmap(null), err, 'left map throws with null')442 t.throws(lmap(0), err, 'left map throws with falsey number')443 t.throws(lmap(1), err, 'left map throws with truthy number')444 t.throws(lmap(''), err, 'left map throws with falsey string')445 t.throws(lmap('string'), err, 'left map throws with truthy string')446 t.throws(lmap(false), err, 'left map throws with false')447 t.throws(lmap(true), err, 'left map throws with true')448 t.throws(lmap([]), err, 'left map throws with an array')449 t.throws(lmap({}), err, 'left map throws iwth object')450 t.doesNotThrow(lmap(unit), 'left map does not throw when passed a function')451 t.end()452})453test('Either map fantasy-land errors', t => {454 const rmap = bindFunc(Either.Right(0)[fl.map])455 const lmap = bindFunc(Either.Left(0)[fl.map])456 const err = /Either.fantasy-land\/map: Function required/457 t.throws(rmap(undefined), err, 'right map throws with undefined')458 t.throws(rmap(null), err, 'right map throws with null')459 t.throws(rmap(0), err, 'right map throws with falsey number')460 t.throws(rmap(1), err, 'right map throws with truthy number')461 t.throws(rmap(''), err, 'right map throws with falsey string')462 t.throws(rmap('string'), err, 'right map throws with truthy string')463 t.throws(rmap(false), err, 'right map throws with false')464 t.throws(rmap(true), err, 'right map throws with true')465 t.throws(rmap([]), err, 'right map throws with an array')466 t.throws(rmap({}), err, 'right map throws iwth object')467 t.doesNotThrow(rmap(unit), 'right map does not throw when passed a function')468 t.throws(lmap(undefined), err, 'left map throws with undefined')469 t.throws(lmap(null), err, 'left map throws with null')470 t.throws(lmap(0), err, 'left map throws with falsey number')471 t.throws(lmap(1), err, 'left map throws with truthy number')472 t.throws(lmap(''), err, 'left map throws with falsey string')473 t.throws(lmap('string'), err, 'left map throws with truthy string')474 t.throws(lmap(false), err, 'left map throws with false')475 t.throws(lmap(true), err, 'left map throws with true')476 t.throws(lmap([]), err, 'left map throws with an array')477 t.throws(lmap({}), err, 'left map throws iwth object')478 t.doesNotThrow(lmap(unit), 'left map does not throw when passed a function')479 t.end()480})481test('Either map functionality', t => {482 const lspy = sinon.spy(identity)483 const rspy = sinon.spy(identity)484 const l = Either.Left(0).map(lspy)485 const r = Either.Right(0).map(rspy)486 t.equal(l.type(), 'Either', 'returns an Either Type')487 t.equal(l.either(identity, constant(1)), 0, 'returns the original Left value')488 t.notOk(lspy.called, 'mapped function is never called when Left')489 t.equal(r.type(), 'Either', 'returns a Either type')490 t.equal(r.either(constant(1), identity), 0, 'returns a Right Either with the same value when mapped with identity')491 t.ok(rspy.called, 'mapped function is called when Right')492 t.end()493})494test('Either map properties (Functor)', t => {495 const f = x => x + 2496 const g = x => x * 2497 const Right = Either.Right498 const Left = Either.Left499 t.ok(isFunction(Left(0).map), 'left provides a map function')500 t.ok(isFunction(Right(0).map), 'right provides a map function')501 t.equal(Right(30).map(identity).either(constant(0), identity), 30, 'Right identity')502 t.equal(503 Right(10).map(compose(f, g)).either(constant(0), identity),504 Right(10).map(g).map(f).either(constant(0), identity),505 'Right composition'506 )507 t.equal(Left(45).map(identity).either(identity, constant(0)), 45, 'Left identity')508 t.equal(509 Left(10).map(compose(f, g)).either(identity, constant(0)),510 Left(10).map(g).map(f).either(identity, constant(0)),511 'Left composition'512 )513 t.end()514})515test('Either bimap errors', t => {516 const bimap = bindFunc(Either.Right('popcorn').bimap)517 const err = /Either.bimap: Requires both left and right functions/518 t.throws(bimap(undefined, unit), err, 'throws with undefined in first argument')519 t.throws(bimap(null, unit), err, 'throws with null in first argument')520 t.throws(bimap(0, unit), err, 'throws with falsey number in first argument')521 t.throws(bimap(1, unit), err, 'throws with truthy number in first argument')522 t.throws(bimap('', unit), err, 'throws with falsey string in first argument')523 t.throws(bimap('string', unit), err, 'throws with truthy string in first argument')524 t.throws(bimap(false, unit), err, 'throws with false in first argument')525 t.throws(bimap(true, unit), err, 'throws with true in first argument')526 t.throws(bimap([], unit), err, 'throws with an array in first argument')527 t.throws(bimap({}, unit), err, 'throws with object in first argument')528 t.throws(bimap(unit, undefined), err, 'throws with undefined in second argument')529 t.throws(bimap(unit, null), err, 'throws with null in second argument')530 t.throws(bimap(unit, 0), err, 'throws with falsey number in second argument')531 t.throws(bimap(unit, 1), err, 'throws with truthy number in second argument')532 t.throws(bimap(unit, ''), err, 'throws with falsey string in second argument')533 t.throws(bimap(unit, 'string'), err, 'throws with truthy string in second argument')534 t.throws(bimap(unit, false), err, 'throws with false in second argument')535 t.throws(bimap(unit, true), err, 'throws with true in second argument')536 t.throws(bimap(unit, []), err, 'throws with an array in second argument')537 t.throws(bimap(unit, {}), err, 'throws with object in second argument')538 t.doesNotThrow(bimap(unit, unit), 'allows functions')539 t.end()540})541test('Either bimap fantasy-land errors', t => {542 const bimap = bindFunc(Either.Right('popcorn')[fl.bimap])543 const err = /Either.fantasy-land\/bimap: Requires both left and right functions/544 t.throws(bimap(undefined, unit), err, 'throws with undefined in first argument')545 t.throws(bimap(null, unit), err, 'throws with null in first argument')546 t.throws(bimap(0, unit), err, 'throws with falsey number in first argument')547 t.throws(bimap(1, unit), err, 'throws with truthy number in first argument')548 t.throws(bimap('', unit), err, 'throws with falsey string in first argument')549 t.throws(bimap('string', unit), err, 'throws with truthy string in first argument')550 t.throws(bimap(false, unit), err, 'throws with false in first argument')551 t.throws(bimap(true, unit), err, 'throws with true in first argument')552 t.throws(bimap([], unit), err, 'throws with an array in first argument')553 t.throws(bimap({}, unit), err, 'throws with object in first argument')554 t.throws(bimap(unit, undefined), err, 'throws with undefined in second argument')555 t.throws(bimap(unit, null), err, 'throws with null in second argument')556 t.throws(bimap(unit, 0), err, 'throws with falsey number in second argument')557 t.throws(bimap(unit, 1), err, 'throws with truthy number in second argument')558 t.throws(bimap(unit, ''), err, 'throws with falsey string in second argument')559 t.throws(bimap(unit, 'string'), err, 'throws with truthy string in second argument')560 t.throws(bimap(unit, false), err, 'throws with false in second argument')561 t.throws(bimap(unit, true), err, 'throws with true in second argument')562 t.throws(bimap(unit, []), err, 'throws with an array in second argument')563 t.throws(bimap(unit, {}), err, 'throws with object in second argument')564 t.doesNotThrow(bimap(unit, unit), 'allows functions')565 t.end()566})567test('Either bimap properties (Bifunctor)', t => {568 const f = x => x + 2569 const g = x => x * 2570 const e = either(identity, identity)571 t.ok(isFunction(Either.Left(0).bimap), 'left provides a bimap function')572 t.ok(isFunction(Either.Right(0).bimap), 'right provides a bimap function')573 t.equal(e(Either.Right(30).bimap(constant(0), identity)), 30, 'Right identity')574 t.equal(575 e(Either.Right(10).bimap(constant(0), compose(f, g))),576 e(Either.Right(10).bimap(constant(0), g).bimap(constant(0), f)),577 'Right composition'578 )579 t.equal(e(Either.Left(45).bimap(identity, constant(0))), 45, 'Left identity')580 t.equal(581 e(Either.Left(10).bimap(compose(f, g), constant(0))),582 e(Either.Left(10).bimap(g, constant(0)).bimap(f, constant(0))),583 'Left composition'584 )585 t.end()586})587test('Either alt errors', t => {588 const m = { type: () => 'Either...Not' }589 const altRight = bindFunc(Either.of(0).alt)590 const err = /Either.alt: Either required/591 t.throws(altRight(undefined), err, 'throws when passed an undefined with Right')592 t.throws(altRight(null), err, 'throws when passed a null with Right')593 t.throws(altRight(0), err, 'throws when passed a falsey number with Right')594 t.throws(altRight(1), err, 'throws when passed a truthy number with Right')595 t.throws(altRight(''), err, 'throws when passed a falsey string with Right')596 t.throws(altRight('string'), err, 'throws when passed a truthy string with Right')597 t.throws(altRight(false), err, 'throws when passed false with Right')598 t.throws(altRight(true), err, 'throws when passed true with Right')599 t.throws(altRight([]), err, 'throws when passed an array with Right')600 t.throws(altRight({}), err, 'throws when passed an object with Right')601 t.throws(altRight(m), err, 'throws when container types differ on Right')602 const altLeft = bindFunc(Either.Left(0).alt)603 t.throws(altLeft(undefined), err, 'throws when passed an undefined with Left')604 t.throws(altLeft(null), err, 'throws when passed a null with Left')605 t.throws(altLeft(0), err, 'throws when passed a falsey number with Left')606 t.throws(altLeft(1), err, 'throws when passed a truthy number with Left')607 t.throws(altLeft(''), err, 'throws when passed a falsey string with Left')608 t.throws(altLeft('string'), err, 'throws when passed a truthy string with Left')609 t.throws(altLeft(false), err, 'throws when passed false with Left')610 t.throws(altLeft(true), err, 'throws when passed true with Left')611 t.throws(altLeft([]), err, 'throws when passed an array with Left')612 t.throws(altLeft({}), err, 'throws when passed an object with Left')613 t.throws(altLeft(m), err, 'throws when container types differ on Left')614 t.end()615})616test('Either alt fantasy-land errors', t => {617 const m = { type: () => 'Either...Not' }618 const altRight = bindFunc(Either.of(0)[fl.alt])619 const err = /Either.fantasy-land\/alt: Either required/620 t.throws(altRight(undefined), err, 'throws when passed an undefined with Right')621 t.throws(altRight(null), err, 'throws when passed a null with Right')622 t.throws(altRight(0), err, 'throws when passed a falsey number with Right')623 t.throws(altRight(1), err, 'throws when passed a truthy number with Right')624 t.throws(altRight(''), err, 'throws when passed a falsey string with Right')625 t.throws(altRight('string'), err, 'throws when passed a truthy string with Right')626 t.throws(altRight(false), err, 'throws when passed false with Right')627 t.throws(altRight(true), err, 'throws when passed true with Right')628 t.throws(altRight([]), err, 'throws when passed an array with Right')629 t.throws(altRight({}), err, 'throws when passed an object with Right')630 t.throws(altRight(m), err, 'throws when container types differ on Right')631 const altLeft = bindFunc(Either.Left(0)[fl.alt])632 t.throws(altLeft(undefined), err, 'throws when passed an undefined with Left')633 t.throws(altLeft(null), err, 'throws when passed a null with Left')634 t.throws(altLeft(0), err, 'throws when passed a falsey number with Left')635 t.throws(altLeft(1), err, 'throws when passed a truthy number with Left')636 t.throws(altLeft(''), err, 'throws when passed a falsey string with Left')637 t.throws(altLeft('string'), err, 'throws when passed a truthy string with Left')638 t.throws(altLeft(false), err, 'throws when passed false with Left')639 t.throws(altLeft(true), err, 'throws when passed true with Left')640 t.throws(altLeft([]), err, 'throws when passed an array with Left')641 t.throws(altLeft({}), err, 'throws when passed an object with Left')642 t.throws(altLeft(m), err, 'throws when container types differ on Left')643 t.end()644})645test('Either alt functionality', t => {646 const right = Either.of('Right')647 const anotherRight = Either.of('Another Right')648 const left = Either.Left('Left')649 const anotherLeft = Either.Left('Another Left')650 const f = either(identity, identity)651 t.equals(f(right.alt(left).alt(anotherRight)), 'Right', 'retains first Right success')652 t.equals(f(left.alt(anotherLeft)), 'Another Left', 'provdes last Left when all Lefts')653 t.end()654})655test('Either alt properties (Alt)', t => {656 const a = Either.of('a')657 const b = Either.Left('Left')658 const c = Either.of('c')659 const f = either(identity, identity)660 t.equals(f(a.alt(b).alt(c)), f(a.alt(b.alt(c))), 'assosiativity')661 t.equals(662 f(a.alt(b).map(identity)),663 f(a.map(identity).alt(b.map(identity))),664 'distributivity'665 )666 t.end()667})668test('Either ap errors', t => {669 const m = { type: () => 'Either...Not' }670 const noFunc = /Either.ap: Wrapped value must be a function/671 t.throws(Either.of(undefined).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is an undefined')672 t.throws(Either.of(null).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is a null')673 t.throws(Either.of(0).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is a falsey number')674 t.throws(Either.of(1).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is a truthy number')675 t.throws(Either.of('').ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is a falsey string')676 t.throws(Either.of('string').ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is a truthy string')677 t.throws(Either.of(false).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is false')678 t.throws(Either.of(true).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is true')679 t.throws(Either.of([]).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is an array')680 t.throws(Either.of({}).ap.bind(null, Either.of(0)), noFunc, 'throws when wrapped value is an object')681 t.doesNotThrow(Either.Left(0).ap.bind(null, Either.of(0)), 'does not throw when ap on Left')682 const noEither = /Either.ap: Either required/683 t.throws(Either.of(unit).ap.bind(null, undefined), noEither, 'throws when passed an undefined')684 t.throws(Either.of(unit).ap.bind(null, null), noEither, 'throws when passed a null')685 t.throws(Either.of(unit).ap.bind(null, 0), noEither, 'throws when passed a falsey number')686 t.throws(Either.of(unit).ap.bind(null, 1), noEither, 'throws when passed a truthy number')687 t.throws(Either.of(unit).ap.bind(null, ''), noEither, 'throws when passed a falsey string')688 t.throws(Either.of(unit).ap.bind(null, 'string'), noEither, 'throws when passed a truthy string')689 t.throws(Either.of(unit).ap.bind(null, false), noEither, 'throws when passed false')690 t.throws(Either.of(unit).ap.bind(null, true), noEither, 'throws when passed true')691 t.throws(Either.of(unit).ap.bind(null, []), noEither, 'throws when passed an array')692 t.throws(Either.of(unit).ap.bind(null, {}), noEither, 'throws when passed an object')693 t.doesNotThrow(Either.Left(unit).ap.bind(null, Either.of(0)), 'does not throw when ap on Left')694 t.throws(Either.of(unit).ap.bind(null, m), noEither, 'throws when container types differ on Right')695 t.doesNotThrow(Either.Left(unit).ap.bind(null, m), 'does not throws when container types differ on Left')696 t.end()697})698test('Either ap properties (Apply)', t => {699 const Right = Either.Right700 const m = Right(identity)701 const a = m.map(compose).ap(m).ap(m)702 const b = m.ap(m.ap(m))703 t.ok(isFunction(m.ap), 'provides an ap function')704 t.ok(isFunction(m.map), 'implements the Functor spec')705 t.equal(706 a.ap(Right(3)).either(constant(0), identity),707 b.ap(Right(3)).either(constant(0), identity),708 'composition Right'709 )710 t.end()711})712test('Either of', t => {713 t.equal(Either.of, Either(0).of, 'Either.of is the same as the instance version')714 t.equal(Either.of(0).type(), 'Either', 'returns an Either')715 t.equal(Either.of(0).either(constant('left'), identity), 0, 'wraps the value into an Either.Right')716 testCircularReference(t, Either.of)717 t.end()718})719test('Either of properties (Applicative)', t => {720 const Right = Either.Right721 const Left = Either.Left722 const r = Right(identity)723 const l = Left('left')724 t.ok(isFunction(r.of), 'Right provides an of function')725 t.ok(isFunction(l.of), 'Left provides an of function')726 t.ok(isFunction(r.ap), 'Right implements the Apply spec')727 t.ok(isFunction(l.ap), 'Left implements the Apply spec')728 t.equal(r.ap(Right(3)).either(constant(0), identity), 3, 'identity Right')729 t.equal(730 r.ap(Either.of(3)).either(constant(0), identity),731 Either.of(3).either(constant(0), identity),732 'homomorphism Right'733 )734 const a = x => r.ap(Either.of(x))735 const b = x => Either.of(applyTo(x)).ap(r)736 t.equal(737 a(3).either(constant(0),identity),738 b(3).either(constant(0),identity),739 'interchange Right'740 )741 t.end()742})743test('Either chain errors', t => {744 const rchain = bindFunc(Either.Right(0).chain)745 const lchain = bindFunc(Either.Left(0).chain)746 const noFunc = /Either.chain: Function required/747 t.throws(rchain(undefined), noFunc, 'Right throws with undefined')748 t.throws(rchain(null), noFunc, 'Right throws with null')749 t.throws(rchain(0), noFunc, 'Right throws falsey with number')750 t.throws(rchain(1), noFunc, 'Right throws truthy with number')751 t.throws(rchain(''), noFunc, 'Right throws falsey with string')752 t.throws(rchain('string'), noFunc, 'Right throws with truthy string')753 t.throws(rchain(false), noFunc, 'Right throws with false')754 t.throws(rchain(true), noFunc, 'Right throws with true')755 t.throws(rchain([]), noFunc, 'Right throws with an array')756 t.throws(rchain({}), noFunc, 'Right throws with an object')757 t.doesNotThrow(rchain(Either.of), 'Right allows a function')758 t.throws(lchain(undefined), noFunc, 'Left throws with undefined')759 t.throws(lchain(null), noFunc, 'Left throws with null')760 t.throws(lchain(0), noFunc, 'Left throws with falsey number')761 t.throws(lchain(1), noFunc, 'Left throws with truthy number')762 t.throws(lchain(''), noFunc, 'Left throws with falsey string')763 t.throws(lchain('string'), noFunc, 'Left throws with truthy string')764 t.throws(lchain(false), noFunc, 'Left throws with false')765 t.throws(lchain(true), noFunc, 'Left throws with true')766 t.throws(lchain([]), noFunc, 'Left throws with an array')767 t.throws(lchain({}), noFunc, 'Left throws with an object')768 t.doesNotThrow(lchain(unit), 'Left allows any function')769 const noEither = /Either.chain: Function must return an Either/770 t.throws(rchain(unit), noEither, 'Right throws with a non Either returning function')771 t.end()772})773test('Either chain fantasy-land errors', t => {774 const rchain = bindFunc(Either.Right(0)[fl.chain])775 const lchain = bindFunc(Either.Left(0)[fl.chain])776 const noFunc = /Either.fantasy-land\/chain: Function required/777 t.throws(rchain(undefined), noFunc, 'Right throws with undefined')778 t.throws(rchain(null), noFunc, 'Right throws with null')779 t.throws(rchain(0), noFunc, 'Right throws falsey with number')780 t.throws(rchain(1), noFunc, 'Right throws truthy with number')781 t.throws(rchain(''), noFunc, 'Right throws falsey with string')782 t.throws(rchain('string'), noFunc, 'Right throws with truthy string')783 t.throws(rchain(false), noFunc, 'Right throws with false')784 t.throws(rchain(true), noFunc, 'Right throws with true')785 t.throws(rchain([]), noFunc, 'Right throws with an array')786 t.throws(rchain({}), noFunc, 'Right throws with an object')787 t.doesNotThrow(rchain(Either.of), 'Right allows a function')788 t.throws(lchain(undefined), noFunc, 'Left throws with undefined')789 t.throws(lchain(null), noFunc, 'Left throws with null')790 t.throws(lchain(0), noFunc, 'Left throws with falsey number')791 t.throws(lchain(1), noFunc, 'Left throws with truthy number')792 t.throws(lchain(''), noFunc, 'Left throws with falsey string')793 t.throws(lchain('string'), noFunc, 'Left throws with truthy string')794 t.throws(lchain(false), noFunc, 'Left throws with false')795 t.throws(lchain(true), noFunc, 'Left throws with true')796 t.throws(lchain([]), noFunc, 'Left throws with an array')797 t.throws(lchain({}), noFunc, 'Left throws with an object')798 t.doesNotThrow(lchain(unit), 'Left allows any function')799 const noEither = /Either.fantasy-land\/chain: Function must return an Either/800 t.throws(rchain(unit), noEither, 'Right throws with a non Either returning function')801 t.end()802})803test('Either chain properties (Chain)', t => {804 const Right = Either.Right805 const Left = Either.Left806 t.ok(isFunction(Right(0).chain), 'Right provides a chain function')807 t.ok(isFunction(Right(0).ap), 'Right implements the Apply spec')808 t.ok(isFunction(Left(0).chain), 'Left provides a chain function')809 t.ok(isFunction(Left(0).ap), 'Left implements the Apply spec')810 const f = x => Right(x + 2)811 const g = x => Right(x + 10)812 const a = x => Right(x).chain(f).chain(g)813 const b = x => Right(x).chain(y => f(y).chain(g))814 t.equal(815 a(10).either(constant(0), identity),816 b(10).either(constant(0), identity),817 'assosiativity Right'818 )819 t.end()820})821test('Either chain properties (Monad)', t => {822 const Right = Either.Right823 t.ok(isFunction(Right(0).chain), 'Right implements the Chain spec')824 t.ok(isFunction(Right(0).of), 'Right implements the Applicative spec')825 const f = x => Right(x)826 t.equal(827 Either.of(3).chain(f).either(constant(0), identity),828 f(3).either(constant(0), identity),829 'left identity Right'830 )831 const m = x => Right(x)832 t.equal(833 m(3).chain(Either.of).either(constant(0), identity),834 m(3).either(constant(0), identity),835 'right identity Right'836 )837 t.end()838})839test('Either sequence errors', t => {840 const rseq = bindFunc(Either.Right(MockCrock(0)).sequence)841 const lseq = bindFunc(Either.Left('Left').sequence)842 const rseqBad = bindFunc(Either.Right(0).sequence)843 const err = /Either.sequence: Applicative TypeRep or Apply returning function required/844 t.throws(rseq(undefined), err, 'Right throws with undefined')845 t.throws(rseq(null), err, 'Right throws with null')846 t.throws(rseq(0), err, 'Right throws falsey with number')847 t.throws(rseq(1), err, 'Right throws truthy with number')848 t.throws(rseq(''), err, 'Right throws falsey with string')849 t.throws(rseq('string'), err, 'Right throws with truthy string')850 t.throws(rseq(false), err, 'Right throws with false')851 t.throws(rseq(true), err, 'Right throws with true')852 t.throws(rseq([]), err, 'Right throws with an array')853 t.throws(rseq({}), err, 'Right throws with an object')854 t.throws(lseq(undefined), err, 'Left throws with undefined')855 t.throws(lseq(null), err, 'Left throws with null')856 t.throws(lseq(0), err, 'Left throws with falsey number')857 t.throws(lseq(1), err, 'Left throws with truthy number')858 t.throws(lseq(''), err, 'Left throws with falsey string')859 t.throws(lseq('string'), err, 'Left throws with truthy string')860 t.throws(lseq(false), err, 'Left throws with false')861 t.throws(lseq(true), err, 'Left throws with true')862 t.throws(lseq([]), err, 'Left throws with an array')863 t.throws(lseq({}), err, 'Left throws with an object')864 const noAp = /Either.sequence: Must wrap an Apply/865 t.throws(rseqBad(unit), noAp, 'Right without wrapping Apply throws')866 t.end()867})868test('Either sequence with Apply function', t => {869 const Right = Either.Right870 const Left = Either.Left871 const x = 284872 const f = x => MockCrock(x)873 const r = Right(MockCrock(x)).sequence(f)874 const l = Left('Left').sequence(f)875 t.ok(isSameType(MockCrock, r), 'Provides an outer type of MockCrock')876 t.ok(isSameType(Either, r.valueOf()), 'Provides an inner type of Either')877 t.equal(r.valueOf().either(constant(0), identity), x, 'Either contains original inner value')878 t.ok(isSameType(MockCrock, l), 'MockCrock', 'Provides an outer type of MockCrock')879 t.ok(isSameType(Either, l.valueOf()), 'Provides an inner type of Either')880 t.equal(l.valueOf().either(identity, constant(0)), 'Left', 'Either contains original Left value')881 const ar = x => [ x ]882 const arR = Right([ x ]).sequence(ar)883 const arL = Left('Left').sequence(ar)884 t.ok(isSameType(Array, arR), 'Provides an outer type of Array')885 t.ok(isSameType(Either, arR[0]), 'Provides an inner type of Either')886 t.equal(arR[0].either(constant(0), identity), x, 'Either contains original inner value')887 t.ok(isSameType(Array, arL), 'Provides an outer type of Array')888 t.ok(isSameType(Either, arL[0]), 'Provides an inner type of Either')889 t.equal(arL[0].either(identity, constant(0)), 'Left', 'Either contains original Left value')890 t.end()891})892test('Either sequence with Applicative TypeRep', t => {893 const Right = Either.Right894 const Left = Either.Left895 const x = 284896 const m = MockCrock897 const r = Right(MockCrock(x)).sequence(m)898 const l = Left('Left').sequence(m)899 t.ok(isSameType(MockCrock, r), 'Provides an outer type of MockCrock')900 t.ok(isSameType(Either, r.valueOf()), 'Provides an inner type of Either')901 t.equal(r.valueOf().either(constant(0), identity), x, 'Either contains original inner value')902 t.ok(isSameType(MockCrock, l), 'Provides an outer type of MockCrock')903 t.ok(isSameType(Either, l.valueOf()), 'Provides an inner type of Either')904 t.equal(l.valueOf().either(identity, constant(0)), 'Left', 'Either contains original Left value')905 const arR = Right([ x ]).sequence(Array)906 const arL = Left('Left').sequence(Array)907 t.ok(isSameType(Array, arR), 'Provides an outer type of Array')908 t.ok(isSameType(Either, arR[0]), 'Provides an inner type of Either')909 t.equal(arR[0].either(constant(0), identity), x, 'Either contains original inner value')910 t.ok(isSameType(Array, arL), 'Provides an outer type of Array')911 t.ok(isSameType(Either, arL[0]), 'Provides an inner type of Either')912 t.equal(arL[0].either(identity, constant(0)), 'Left', 'Either contains original Left value')913 t.end()914})915test('Either traverse errors', t => {916 const rtrav = bindFunc(Either.Right(0).traverse)917 const ltrav = bindFunc(Either.Left('Left').traverse)918 const f = x => MockCrock(x)919 const noFirstAp = /Either.traverse: Applicative TypeRep or Apply returning function required for first argument/920 const noFunc = /Either.traverse: Apply returning function required for second argument/921 t.throws(rtrav(undefined, unit), noFirstAp, 'Right throws with undefined in first argument')922 t.throws(rtrav(null, unit), noFirstAp, 'Right throws with null in first argument')923 t.throws(rtrav(0, unit), noFirstAp, 'Right throws falsey with number in first argument')924 t.throws(rtrav(1, unit), noFirstAp, 'Right throws truthy with number in first argument')925 t.throws(rtrav('', unit), noFirstAp, 'Right throws falsey with string in first argument')926 t.throws(rtrav('string', unit), noFirstAp, 'Right throws with truthy string in first argument')927 t.throws(rtrav(false, unit), noFirstAp, 'Right throws with false in first argument')928 t.throws(rtrav(true, unit), noFirstAp, 'Right throws with true in first argument')929 t.throws(rtrav([], unit), noFirstAp, 'Right throws with an array in first argument')930 t.throws(rtrav({}, unit), noFirstAp, 'Right throws with an object in first argument')931 t.throws(rtrav(f, undefined), noFunc, 'Right throws with undefined in second argument')932 t.throws(rtrav(f, null), noFunc, 'Right throws with null in second argument')933 t.throws(rtrav(f, 0), noFunc, 'Right throws falsey with number in second argument')934 t.throws(rtrav(f, 1), noFunc, 'Right throws truthy with number in second argument')935 t.throws(rtrav(f, ''), noFunc, 'Right throws falsey with string in second argument')936 t.throws(rtrav(f, 'string'), noFunc, 'Right throws with truthy string in second argument')937 t.throws(rtrav(f, false), noFunc, 'Right throws with false in second argument')938 t.throws(rtrav(f, true), noFunc, 'Right throws with true in second argument')939 t.throws(rtrav(f, []), noFunc, 'Right throws with an array in second argument')940 t.throws(rtrav(f, {}), noFunc, 'Right throws with an object in second argument')941 t.throws(ltrav(undefined, MockCrock), noFirstAp, 'Left throws with undefined in first argument')942 t.throws(ltrav(null, MockCrock), noFirstAp, 'Left throws with null in first argument')943 t.throws(ltrav(0, MockCrock), noFirstAp, 'Left throws with falsey number in first argument')944 t.throws(ltrav(1, MockCrock), noFirstAp, 'Left throws with truthy number in first argument')945 t.throws(ltrav('', MockCrock), noFirstAp, 'Left throws with falsey string in first argument')946 t.throws(ltrav('string', MockCrock), noFirstAp, 'Left throws with truthy string in first argument')947 t.throws(ltrav(false, MockCrock), noFirstAp, 'Left throws with false in first argument')948 t.throws(ltrav(true, MockCrock), noFirstAp, 'Left throws with true in first argument')949 t.throws(ltrav([], MockCrock), noFirstAp, 'Left throws with an array in first argument')950 t.throws(ltrav({}, MockCrock), noFirstAp, 'Left throws with an object in first argument')951 t.throws(ltrav(unit, undefined), noFunc, 'Left throws with undefined in second argument')952 t.throws(ltrav(unit, null), noFunc, 'Left throws with null in second argument')953 t.throws(ltrav(unit, 0), noFunc, 'Left throws falsey with number in second argument')954 t.throws(ltrav(unit, 1), noFunc, 'Left throws truthy with number in second argument')955 t.throws(ltrav(unit, ''), noFunc, 'Left throws falsey with string in second argument')956 t.throws(ltrav(unit, 'string'), noFunc, 'Left throws with truthy string in second argument')957 t.throws(ltrav(unit, false), noFunc, 'Left throws with false in second argument')958 t.throws(ltrav(unit, true), noFunc, 'Left throws with true in second argument')959 t.throws(ltrav(unit, []), noFunc, 'Left throws with an array in second argument')960 t.throws(ltrav(unit, {}), noFunc, 'Left throws with an object in second argument')961 const noAp = /Either.traverse: Both functions must return an Apply of the same type/962 t.throws(rtrav(unit, unit), noAp, 'Right throws when first function does not return an Apply')963 t.throws(ltrav(unit, unit), noAp, 'Left throws when second function does not return an Apply')964 t.end()965})966test('Either traverse with Apply function', t => {967 const { Left, Right } = Either968 const x = 98969 const res = 'result'970 const f = x => MockCrock(x)971 const fn = m => constant(m(res))972 const r = Right(x).traverse(f, fn(MockCrock))973 const l = Left('Left').traverse(f, fn(MockCrock))974 t.ok(isSameType(MockCrock, r), 'Provides an outer type of MockCrock')975 t.ok(isSameType(Either, r.valueOf()), 'Provides an inner type of Either')976 t.equal(r.valueOf().either(constant(0), identity), res, 'Either contains transformed inner value')977 t.ok(isSameType(MockCrock, l), 'Provides an outer type of MockCrock')978 t.ok(isSameType(Either, l.valueOf()), 'Provides an inner type of Either')979 t.equal(l.valueOf().either(identity, constant(0)), 'Left', 'Either contains original Left value')980 const ar = x => [ x ]981 const arR = Right(x).traverse(ar, fn(ar))982 const arL = Left('Left').traverse(ar, fn(ar))983 t.ok(isSameType(Array, arR), 'Provides an outer type of Array')984 t.ok(isSameType(Either, arR[0]), 'Provides an inner type of Either')985 t.equal(arR[0].either(constant(0), identity), res, 'Either contains transformed value')986 t.ok(isSameType(Array, arL), 'Provides an outer type of Array')987 t.ok(isSameType(Either, arL[0]), 'Provides an inner type of Either')988 t.equal(arL[0].either(identity, constant(0)), 'Left', 'Either contains original Left value')989 t.end()990})991test('Either traverse with Applicative TypeRep', t => {992 const { Left, Right } = Either993 const x = 98994 const res = 'result'995 const fn = m => constant(m(res))996 const m = MockCrock997 const r = Right(x).traverse(m, fn(MockCrock))998 const l = Left('Left').traverse(m, fn(MockCrock))999 t.ok(isSameType(MockCrock, r), 'Provides an outer type of MockCrock')1000 t.ok(isSameType(Either, r.valueOf()), 'Provides an inner type of Either')1001 t.equal(r.valueOf().either(constant(0), identity), res, 'Either contains transformed value')1002 t.ok(isSameType(MockCrock, l), 'Provides an outer type of MockCrock')1003 t.ok(isSameType(Either, l.valueOf()), 'Provides an inner type of Either')1004 t.equal(l.valueOf().either(identity, constant(0)), 'Left', 'Either contains original Left value')1005 const ar = x => [ x ]1006 const arR = Right(x).traverse(Array, fn(ar))1007 const arL = Left('Left').traverse(Array, fn(ar))1008 t.ok(isSameType(Array, arR), 'Provides an outer type of Array')1009 t.ok(isSameType(Either, arR[0]), 'Provides an inner type of Either')1010 t.equal(arR[0].either(constant(0), identity), res, 'Either contains transformed value')1011 t.ok(isSameType(Array, arL), 'Provides an outer type of Array')1012 t.ok(isSameType(Either, arL[0]), 'Provides an inner type of Either')1013 t.equal(arL[0].either(identity, constant(0)), 'Left', 'Either contains original Left value')1014 t.end()...
rules.js
Source:rules.js
1'use strict';2const validationRules = {3 4 tMF645serviceQualificationCreate: 5 [{ $: [{$noneOf: ["id", "href", "serviceQualificationDate", "state", "qualificationResult", 6 "estimatedResponseDate", "effectiveQualificationDate", 7 "eligibilityUnavailabilityReason", "alternateServiceProposal",8 "expirationDate"]},9 {$present: ['serviceQualificationItem']}]},10 {"serviceQualificationItem": {$present: ["id"]}},11 {"serviceQualificationItem": {$noneOf: ["expirationDate", "qualificationItemResult"]}},12 {"serviceQualificationItem.qualificationItemRelationship": {$present: ["id", "type"]}},13 {"serviceQualificationItem.relatedParty": {$eitherOf: ["href", "id"]}},14 {"serviceQualificationItem.service.serviceCharacteristic": {$present: ["name", "value"]}}],15 //16 // TMF 641 Service Order, based on TMF641B Release 18.0.1 May 201817 // 18 // Notes: 19 // 1) Handling of 'state' in POST is unclear in the document, here treated as not allowed20 // 2) orderItem is incorrectly labelled as 'serviceOrderItem' in TMF641B21 // 3) removed rule { "orderItem.action": {$notEqual: "add", $eitherOf: ["service.id", "service.href"]}}22 // 23 tMF641serviceOrderCreate:24 [{ $: { $noneOf: ["id", "href", "state", "orderDate", "completionDate", 25 "expectedCompletionDate", "startDate"]}},26 { $: {$eitherOf: ["orderItem"]}},27 { "relatedParty": {$eitherOf: ["id", "href"]}},28 { "note": {$eitherOf: ["author", "text"]}},29 { "orderItem": {$notEmpty: true}},30 { "orderItem": {$present: ["action","id"]}},31 { "orderItem": {$noneOf: ["state"]}},32 { "orderItem.appointment": {$eitherOf: ["id", "href"]}},33 { "orderItem.orderItemRelationship": {$present: ["type", "id"]}},34 { "orderItem.service": {$eitherOf: ["id", "href"]}},35 { "orderItem.service": {$eitherOf: ["id", "href"]}},36 { "orderItem.service.serviceSpecification": {$eitherOf: ["id", "href"]}}, 37 { "orderItem.service.serviceSpecification.targetServiceSchema": {$present: ["@type", "@schemaLocation"]}}, 38 { "orderItem.service.serviceRelationship": {$eitherOf: ["type", "service"] }},39 { "orderItem.service.serviceCharacteristic": {$eitherOf: ["name", "valueType", "value"]}},40 { "orderItem.service.place": {$eitherOf: ["id", "href"]}},41 { "orderItem.service.place": {$present: ["role", "@referredType"]}},42 { "orderItem.relatedParty": {$present: ["type"]}},43 { "orderItem.relatedParty": {$eitherOf: ["id", "href"]}},44 { "orderItem.orderRelationship": {$present: ["type"]}},45 { "orderItem.orderRelationship": {$eitherOf: ["id", "href"]}}46 ]47};48const validationRulesType2 = {49 "Customer": {50 "operations": ["GET", "POST", "PATCH", "DELETE"],51 "POST": [52 {"engagedParty": {$eitherOf: ["id", "href"]}},53 {"characteristic": {$present: ["name", "value"]}},54 {"contactMedium": {$present: ["type", "characteristic"]}},55 {"account": {$present: ["name"]}},56 {"account": {$eitherOf: ["id", "href"]}},57 {"creditProfile": {$present: ["creditProfileDate", "validFor"]}},58 {"paymentMethod": {$eitherOf: ["id", "href"]}},59 {$: {$present: ["name"]}}60 ],61 "PATCH": [62 {$: {$noneOf: ["id", "href"]}},63 {"engagedParty": {$eitherOf: ["id", "href"]}},64 {"characteristic": {$present: ["name", "value"]}},65 {"contactMedium": {$present: ["type", "characteristic"]}},66 {"account": {$present: ["name"]}},67 {"account": {$eitherOf: ["id", "href"]}},68 {"creditProfile": {$present: ["creditProfileDate", "validFor"]}},69 {"paymentMethod": {$eitherOf: ["id", "href"]}}70 ],71 },72 "BalanceReserve": {73 "operations": ["POST"],74 "POST": [75 {$: {$present: ["id", "relatedParty", "reservedAmount"]}}76 ],77 },78 "RoleType": {79 },80 "Product": {81 "operations": ["GET", "PATCH", "POST", "DELETE"],82 "POST": [83 {"productOffering": {$eitherOf: ["id", "href"]}},84 {"productSpecification": {$eitherOf: ["id", "href"]}},85 {"billingAccount": {$eitherOf: ["id", "href"]}},86 {"relatedParty": {$eitherOf: ["id", "href"]}},87 {$: {$present: ["name", "relatedParty"]}}88 ],89 "PATCH": [90 {$: {$noneOf: ["id", "href", "orderDate"]}},91 {"productOffering": {$eitherOf: ["id", "href"]}},92 {"productSpecification": {$eitherOf: ["id", "href"]}},93 {"billingAccount": {$eitherOf: ["id", "href"]}},94 {"relatedParty": {$eitherOf: ["id", "href"]}}95 ],96 },97 "SLA": {98 "operations": ["GET", "PATCH", "POST", "DELETE"],99 "POST": [100 {$: {$present: ["name"]}}101 ],102 "PATCH": [103 {$: {$noneOf: ["id", "href"]}},104 105 ],106 },107 "Extract": {108 "operations": ["POST"],109 "POST": [110 111 ],112 "PATCH": [113 114 ],115 },116 "ResourcePool": {117 "operations": ["POST", "PATCH", "DELETE"],118 "POST": [119 120 ],121 "PATCH": [122 123 ],124 },125 "ChangeRequest": {126 "operations": ["GET", "PATCH", "POST", "DELETE"],127 "POST": [128 {"sla": {$eitherOf: ["id", "href"]}},129 {"characteristic": {$present: ["name", "value"]}},130 {"specification": {$eitherOf: ["id", "href"]}},131 {"impactEntity": {$eitherOf: ["id", "href"]}},132 {"relatedChangeRequest": {$eitherOf: ["id", "href"]}},133 {"relatedParty": {$eitherOf: ["id", "href"]}},134 {"resolution": {$present: ["name", "description"]}},135 {"targetEntity": {$eitherOf: ["id", "href"]}},136 {"workLog": {$present: ["createDateTime", "record"]}},137 {$: {$present: ["status"]}},138 {$: {$present: ["priority"]}},139 {$: {$present: ["targetEntity"]}},140 {$: {$present: ["specification"]}}141 ],142 "PATCH": [143 {$: {$noneOf: ["id", "href"]}},144 {"sla": {$eitherOf: ["id", "href"]}},145 {"characteristic": {$present: ["name", "value"]}},146 {"specification": {$eitherOf: ["id", "href"]}},147 {"impactEntity": {$eitherOf: ["id", "href"]}},148 {"relatedChangeRequest": {$eitherOf: ["id", "href"]}},149 {"relatedParty": {$eitherOf: ["id", "href"]}},150 {"resolution": {$present: ["name", "description"]}},151 {"targetEntity": {$eitherOf: ["id", "href"]}},152 {"workLog": {$present: ["createDateTime", "record"]}}153 ],154 },155 "Document": {156 "operations": ["GET", "PATCH", "POST", "DELETE"],157 "POST": [158 {"partyRoleRef": {$eitherOf: ["id", "href"]}},159 {"documentCharacteristic": {$present: ["name", "value"]}},160 {"attachment": {$present: ["size"]}},161 {$: {$present: ["attachment.sizeUnit"]}},162 {"attachment": {$present: ["mimeType"]}},163 {"categoryRef": {$eitherOf: ["id", "href"]}},164 {"relatedObject": {$present: ["involvement", "reference"]}},165 {$: {$present: ["description"]}},166 {$: {$present: ["type"]}},167 {$: {$present: ["attachment"]}}168 ],169 "PATCH": [170 {$: {$noneOf: ["id", "href", "created"]}},171 {"partyRoleRef": {$eitherOf: ["id", "href"]}},172 {"documentCharacteristic": {$present: ["name", "value"]}},173 {"attachment": {$present: ["size"]}},174 {$: {$present: ["attachment.sizeUnit"]}},175 {"attachment": {$present: ["mimeType"]}},176 {"categoryRef": {$eitherOf: ["id", "href"]}},177 {"relatedObject": {$present: ["involvement", "reference"]}}178 ],179 },180 "BalanceDeductRollback": {181 "operations": ["POST"],182 "POST": [183 {$: {$present: ["id", "relatedParty", "balanceDeduct"]}}184 ],185 },186 "Reservation": {187 "operations": ["GET", "POST", "PATCH"],188 "POST": [189 {$: {$present: ["relatedParty", "resourceCapacityDemand"]}}190 ],191 "PATCH": [192 193 ],194 },195 "CommunicationMessage": {196 "operations": ["GET", "PATCH", "POST", "DELETE"],197 "POST": [198 {"receiver": {$present: ["id"]}},199 {"sender": {$present: ["id"]}},200 {"characteristic": {$present: ["name", "value"]}},201 {"attachment": {$eitherOf: ["id", "href"]}},202 {$: {$present: ["type", "content", "sender", "receiver"]}}203 ],204 "PATCH": [205 {$: {$noneOf: ["id", "href", "name"]}},206 {"receiver": {$present: ["id"]}},207 {"sender": {$present: ["id"]}},208 {"characteristic": {$present: ["name", "value"]}},209 {"attachment": {$eitherOf: ["id", "href"]}}210 ],211 },212 "ServiceLevelSpecification": {213 "operations": ["GET", "PATCH", "POST", "DELETE"],214 "POST": [215 {"objective": {$eitherOf: ["id", "href"]}},216 {$: {$present: ["name"]}},217 {$: {$present: ["objective"]}}218 ],219 "PATCH": [220 {$: {$noneOf: ["id", "href", "validFor"]}},221 {"objective": {$eitherOf: ["id", "href"]}}222 ],223 },224 "ServiceProblem": {225 "operations": ["GET", "PATCH", "POST"],226 "POST": [227 {"relatedParty": {$eitherOf: ["id", "href"]}},228 {$: {$present: ["category", "priority", "description", "reason", "originatorParty"]}}229 ],230 "PATCH": [231 {$: {$noneOf: ["id", "correlationId", "originatingSystem", "href", "firstAlert", "timeRaised", "trackingRecord", ""]}},232 {"relatedParty": {$eitherOf: ["id", "href"]}}233 ],234 },235 "SettlementAccount": {236 "operations": ["GET", "PATCH", "POST", "DELETE"],237 "POST": [238 {$: {$present: ["name", "relatedParty"]}}239 ],240 "PATCH": [241 {$: {$noneOf: ["id", "href", "accountBalance"]}},242 ],243 },244 "Street": {245 "operations": ["GET"],246 },247 "BillFormat": {248 "operations": ["GET", "PATCH", "POST", "DELETE"],249 "POST": [250 {$: {$present: ["name"]}}251 ],252 "PATCH": [253 {$: {$noneOf: ["id", "href"]}},254 ],255 },256 "LogicalResource": {257 "operations": ["GET", "PATCH", "POST", "DELETE"],258 "POST": [259 {"resourceSpecification": {$eitherOf: ["id", "href"]}},260 {"partyRole": {$eitherOf: ["id", "href"]}},261 {"resourceRelationship": {$present: ["type"]}},262 {"note": {$present: ["text"]}},263 {"place": {$present: ["role"]}},264 {"place": {$eitherOf: ["id", "href"]}},265 {$: {$present: ["value"]}}266 ],267 "PATCH": [268 {$: {$noneOf: ["id", "href"]}},269 {"resourceSpecification": {$eitherOf: ["id", "href"]}},270 {"partyRole": {$eitherOf: ["id", "href"]}},271 {"resourceRelationship": {$present: ["type"]}},272 {"note": {$present: ["text"]}},273 {"place": {$present: ["role"]}},274 {"place": {$eitherOf: ["id", "href"]}}275 ],276 },277 "Push": {278 "operations": ["POST"],279 "POST": [280 281 ],282 "PATCH": [283 284 ],285 },286 "BalanceDeduct": {287 "operations": ["POST"],288 "POST": [289 {$: {$present: ["id", "relatedParty", "balanceReserve"]}}290 ],291 },292 "StreetSegment": {293 "operations": ["GET"],294 },295 "PartyRole": {296 "operations": ["GET", "POST", "PATCH", "DELETE"],297 "POST": [298 {"engagedParty": {$eitherOf: ["id", "href"]}},299 {"characteristic": {$present: ["name", "value"]}},300 {"contactMedium": {$present: ["type", "characteristic"]}},301 {"account": {$present: ["name"]}},302 {"account": {$eitherOf: ["id", "href"]}},303 {"creditProfile": {$present: ["creditProfileDate", "validFor"]}},304 {"paymentMethod": {$eitherOf: ["id", "href"]}},305 {"type": {$present: ["name"]}},306 {$: {$present: ["name", "type"]}}307 ],308 "PATCH": [309 {$: {$noneOf: ["id", "href"]}},310 {"engagedParty": {$eitherOf: ["id", "href"]}},311 {"characteristic": {$present: ["name", "value"]}},312 {"contactMedium": {$present: ["type", "characteristic"]}},313 {"account": {$present: ["name"]}},314 {"account": {$eitherOf: ["id", "href"]}},315 {"creditProfile": {$present: ["creditProfileDate", "validFor"]}},316 {"paymentMethod": {$eitherOf: ["id", "href"]}},317 {"type": {$present: ["name"]}}318 ],319 },320 "GeographicLocation": {321 "operations": ["GET", "POST", "PATCH", "DELETE"],322 },323 "Resource": {324 "operations": ["GET", "PATCH", "POST", "DELETE"],325 "POST": [326 {"resourceSpecification": {$eitherOf: ["id", "href"]}},327 {"partyRole": {$eitherOf: ["id", "href"]}},328 {"resourceRelationship": {$present: ["type"]}},329 {"note": {$present: ["text"]}},330 {"place": {$present: ["role"]}},331 {"place": {$eitherOf: ["id", "href"]}},332 {$: {$present: ["name", "@type"]}}333 ],334 "PATCH": [335 {$: {$noneOf: ["id", "href"]}},336 {"resourceSpecification": {$eitherOf: ["id", "href"]}},337 {"partyRole": {$eitherOf: ["id", "href"]}},338 {"resourceRelationship": {$present: ["type"]}},339 {"note": {$present: ["text"]}},340 {"place": {$present: ["role"]}},341 {"place": {$eitherOf: ["id", "href"]}}342 ],343 },344 "ServiceTestSpecification": {345 "operations": ["GET", "PATCH", "POST", "DELETE"],346 "POST": [347 {"relatedServiceSpecification": {$eitherOf: ["id", "href"]}},348 {"validFor": {$present: ["endDateTime", "startDateTime"]}},349 {"testMeasureDefinition": {$present: ["metricName", "metricHref", "name"]}},350 {"testMeasureDefinition.capturePeriod": {$present: ["endDateTime", "startDateTime"]}},351 {"testMeasureDefinition.thresholdRule": {$present: ["conformanceTargetLower", "conformanceTargetUpper", "conformanceComparatorLower", "conformanceComparatorUpper", "name"]}},352 {$: {$present: ["name"]}},353 {$: {$present: ["relatedServiceSpecification"]}}354 ],355 "PATCH": [356 {$: {$noneOf: ["id", "href", "validFor"]}},357 {"relatedServiceSpecification": {$eitherOf: ["id", "href"]}},358 {"validFor": {$present: ["endDateTime", "startDateTime"]}},359 {"testMeasureDefinition": {$present: ["metricName", "metricHref", "name"]}},360 {"testMeasureDefinition.capturePeriod": {$present: ["endDateTime", "startDateTime"]}},361 {"testMeasureDefinition.thresholdRule": {$present: ["conformanceTargetLower", "conformanceTargetUpper", "conformanceComparatorLower", "conformanceComparatorUpper", "name"]}}362 ],363 },364 "Catalog": {365 "operations": ["GET", "POST", "PATCH", "DELETE"],366 "POST": [367 {$: {$present: ["name"]}}368 ],369 "PATCH": [370 {$: {$noneOf: ["id", "href"]}},371 ],372 },373 "Recommendation": {374 "operations": ["GET"],375 },376 "Area": {377 "operations": ["GET"],378 },379 "AssociationSpecification": {380 "operations": ["GET", "POST", "PATCH", "DELETE"],381 "POST": [382 {$: {$present: ["name", "associationRoleSpec"]}}383 ],384 "PATCH": [385 {$: {$noneOf: ["id", "href"]}},386 ],387 },388 "BalanceUnreserve": {389 "operations": ["POST"],390 "POST": [391 {$: {$present: ["id", "relatedParty", "balanceReserve"]}}392 ],393 },394 "FinancialAccount": {395 "operations": ["GET", "POST", "PATCH", "DELETE"],396 "POST": [397 {"taxExemption": {$present: ["issuingJurisdiction", "validFor"]}},398 {"accountRelationship": {$present: ["relationshipType", "validFor"]}},399 {"contact": {$present: ["contactType", "validFor"]}},400 {"relatedParty": {$present: ["id", "name"]}},401 {"accountBalance": {$present: ["type", "amount", "validFor"]}},402 {$: {$present: ["name"]}}403 ],404 "PATCH": [405 {"taxExemption": {$present: ["issuingJurisdiction", "validFor"]}},406 {"accountRelationship": {$present: ["relationshipType", "validFor"]}},407 {"contact": {$present: ["contactType", "validFor"]}},408 {"relatedParty": {$present: ["id", "name"]}},409 {"accountBalance": {$present: ["type", "amount", "validFor"]}}410 ],411 },412 "Individual": {413 "operations": ["GET", "PATCH", "POST", "DELETE"],414 "POST": [415 {"relatedParty": {$eitherOf: ["id", "href"]}},416 {"disability": {$present: ["disability"]}},417 {"characteristic": {$present: ["name", "value"]}},418 {"identification": {$present: ["type", "identificationId"]}},419 {"externalReference": {$present: ["type", "href"]}},420 {"relatedParty": {$present: ["role"]}},421 {$: {$present: ["givenName", "familyName"]}}422 ],423 "PATCH": [424 {$: {$noneOf: ["id", "href"]}},425 {"relatedParty": {$eitherOf: ["id", "href"]}},426 {"disability": {$present: ["disability"]}},427 {"characteristic": {$present: ["name", "value"]}},428 {"identification": {$present: ["type", "identificationId"]}},429 {"externalReference": {$present: ["type", "href"]}},430 {"relatedParty": {$present: ["role"]}}431 ],432 },433 "EntityCatalog": {434 "operations": ["GET", "POST", "PATCH", "DELETE"],435 "POST": [436 {$: {$present: ["name"]}}437 ],438 "PATCH": [439 {$: {$noneOf: ["id", "href"]}},440 ],441 },442 "GeographicAddressValidation": {443 "operations": ["GET", "PATCH", "POST", "DELETE"],444 "PATCH": [445 {$: {$noneOf: ["id", "href"]}},446 ],447 },448 "ImportJob": {449 "operations": ["GET", "POST"],450 "POST": [451 452 ],453 "PATCH": [454 {$: {$noneOf: ["id", "href"]}},455 456 ],457 },458 "AgreementSpecification": {459 "operations": ["GET", "PATCH", "POST", "DELETE"],460 "POST": [461 {$: {$present: ["name", "attachment"]}}462 ],463 "PATCH": [464 {$: {$noneOf: ["id", "href"]}},465 ],466 },467 "ServiceTest": {468 "operations": ["GET", "PATCH", "POST", "DELETE"],469 "POST": [470 {"relatedService": {$eitherOf: ["id", "href"]}},471 {"testSpecification": {$eitherOf: ["id", "href"]}},472 {"characteristic": {$present: ["name", "value"]}},473 {"testMeasure.ruleViolation": {$present: ["name", "conformanceTargetLower", "conformanceTargetUpper", "conformanceComparatorLower", "conformanceComparatorUpper"]}},474 {"testMeasure": {$present: ["metricHref", "metricName"]}},475 {$: {$present: ["name"]}},476 {$: {$present: ["relatedService"]}},477 {$: {$present: ["testSpecification"]}}478 ],479 "PATCH": [480 {$: {$noneOf: ["id", "href"]}},481 {"relatedService": {$eitherOf: ["id", "href"]}},482 {"testSpecification": {$eitherOf: ["id", "href"]}},483 {"characteristic": {$present: ["name", "value"]}},484 {"testMeasure.ruleViolation": {$present: ["name", "conformanceTargetLower", "conformanceTargetUpper", "conformanceComparatorLower", "conformanceComparatorUpper"]}},485 {"testMeasure": {$present: ["metricHref", "metricName"]}}486 ],487 },488 "Organization": {489 "operations": ["GET", "PATCH", "POST", "DELETE"],490 "POST": [491 {"relatedParty": {$eitherOf: ["id", "href"]}},492 {"characteristic": {$present: ["name", "value"]}},493 {"identification": {$present: ["type", "identificationId"]}},494 {"externalReference": {$present: ["type", "href"]}},495 {"relatedParty": {$present: ["role"]}},496 {$: {$present: ["tradingName"]}}497 ],498 "PATCH": [499 {$: {$noneOf: ["id", "href"]}},500 {"relatedParty": {$eitherOf: ["id", "href"]}},501 {"characteristic": {$present: ["name", "value"]}},502 {"identification": {$present: ["type", "identificationId"]}},503 {"externalReference": {$present: ["type", "href"]}},504 {"relatedParty": {$present: ["role"]}}505 ],506 },507 "BillPresentationMedia": {508 "operations": ["GET", "PATCH", "POST", "DELETE"],509 "POST": [510 {$: {$present: ["name"]}}511 ],512 "PATCH": [513 {$: {$noneOf: ["id", "href"]}},514 ],515 },516 "EntityCatalogItem": {517 "operations": ["GET", "POST", "PATCH", "DELETE"],518 "POST": [519 {$: {$present: ["name"]}}520 ],521 "PATCH": [522 {$: {$noneOf: ["id", "href"]}},523 ],524 },525 "BillingCycleSpecification": {526 "operations": ["GET", "PATCH", "POST", "DELETE"],527 "POST": [528 {$: {$present: ["name"]}}529 ],530 "PATCH": [531 {$: {$noneOf: ["id", "href"]}},532 ],533 },534 "CustomerBill": {535 "operations": ["GET", "PATCH"],536 "PATCH": [537 ],538 },539 "GeographicSite": {540 "operations": ["GET", "PATCH", "POST", "DELETE"],541 "POST": [542 {"relatedParty": {$present: ["name"]}},543 {"relatedParty": {$eitherOf: ["id", "href"]}},544 {$: {$present: ["name", "id", "type"]}}545 ],546 "PATCH": [547 {$: {$noneOf: ["id", "href"]}},548 {"relatedParty": {$present: ["name"]}},549 {"relatedParty": {$eitherOf: ["id", "href"]}}550 ],551 },552 "PhysicalResource": {553 "operations": ["GET", "PATCH", "POST", "DELETE"],554 "POST": [555 {"resourceSpecification": {$eitherOf: ["id", "href"]}},556 {"partyRole": {$eitherOf: ["id", "href"]}},557 {"resourceRelationship": {$present: ["type"]}},558 {"note": {$present: ["text"]}},559 {"place": {$present: ["role"]}},560 {"place": {$eitherOf: ["id", "href"]}},561 {$: {$present: ["name", "serialNumber"]}}562 ],563 "PATCH": [564 {$: {$noneOf: ["id", "href"]}},565 {"resourceSpecification": {$eitherOf: ["id", "href"]}},566 {"partyRole": {$eitherOf: ["id", "href"]}},567 {"resourceRelationship": {$present: ["type"]}},568 {"note": {$present: ["text"]}},569 {"place": {$present: ["role"]}},570 {"place": {$eitherOf: ["id", "href"]}}571 ],572 },573 "Promotion": {574 "operations": ["GET", "PATCH", "POST", "DELETE"],575 "POST": [576 {"pattern": {$present: ["id", "name"]}},577 {"pattern.action": {$present: ["id", "actionType", "actionValue", "actionObjectId"]}},578 {"pattern.criteriaGroup.criteria": {$present: ["id", "criteriaPara", "criteriaOperator", "criteriaValue"]}},579 {"pattern.criteriaGroup": {$present: ["id", "groupName", "relationTypeInGroup"]}},580 {$: {$present: ["name"]}}581 ],582 "PATCH": [583 {$: {$noneOf: ["id", "href"]}},584 {"pattern": {$present: ["id", "name"]}},585 {"pattern.action": {$present: ["id", "actionType", "actionValue", "actionObjectId"]}},586 {"pattern.criteriaGroup.criteria": {$present: ["id", "criteriaPara", "criteriaOperator", "criteriaValue"]}},587 {"pattern.criteriaGroup": {$present: ["id", "groupName", "relationTypeInGroup"]}}588 ],589 },590 "Party": {591 },592 "Association": {593 "operations": ["GET", "POST", "PATCH", "DELETE"],594 "POST": [595 {$: {$present: ["name", "associationRole"]}}596 ],597 "PATCH": [598 {$: {$noneOf: ["id", "href"]}},599 ],600 },601 "SLAViolation": {602 "operations": ["GET", "PATCH", "POST", "DELETE"],603 "POST": [604 605 ],606 "PATCH": [607 {$: {$noneOf: ["id", "href"]}},608 609 ],610 },611 "GeographicAddress": {612 "operations": ["GET"],613 },614 "ExportJob": {615 "operations": ["GET", "POST"],616 "POST": [617 618 ],619 "PATCH": [620 {$: {$noneOf: ["id", "href"]}},621 622 ],623 },624 "BillingAccount": {625 "operations": ["GET", "PATCH", "POST", "DELETE"],626 "POST": [627 {$: {$present: ["name", "relatedParty"]}}628 ],629 "PATCH": [630 {$: {$noneOf: ["id", "href", "accountBalance"]}},631 ],632 },633 "UsageSpecification": {634 "operations": ["GET", "PATCH", "POST", "DELETE"],635 "POST": [636 {$: {$present: ["nONE"]}},637 {$: {$present: ["nONE"]}}638 ],639 "PATCH": [640 {$: {$noneOf: ["id", "href"]}},641 {$: {$present: ["nONE"]}}642 ],643 },644 "PartyAccount": {645 "operations": ["GET", "PATCH", "POST", "DELETE"],646 "POST": [647 {$: {$present: ["name", "relatedParty"]}}648 ],649 "PATCH": [650 {$: {$noneOf: ["id", "href", "accountBalance"]}},651 ],652 },653 "ProductOrder": {654 "operations": ["GET", "PATCH", "POST", "DELETE"],655 "POST": [656 {"orderItem": {$present: ["id", "action", "billingAccount", "product"]}},657 {"billingAccount": {$eitherOf: ["id", "href"]}},658 {"payment": {$eitherOf: ["id", "href"]}},659 {"note": {$present: ["text"]}},660 {"relatedParty": {$present: ["name"]}},661 {"relatedParty": {$eitherOf: ["id", "href"]}},662 {"relatedParty": {$present: ["role"]}},663 {"orderItem.qualification": {$eitherOf: ["id", "href"]}},664 {"orderItem.payment": {$eitherOf: ["id", "href"]}},665 {"orderItem.appointment": {$eitherOf: ["id", "href"]}},666 {"orderItem.product.place": {$present: ["role"]}},667 {"orderItem.productOffering": {$eitherOf: ["id", "href"]}},668 {"orderItem.itemTerm": {$present: ["name", "duration"]}},669 {"orderItem.orderItemRelationship": {$present: ["type", "id"]}},670 {"orderItem.action": {$equal: "modify", "orderItem.product": {$eitherOf: ["id", "href"]}}},671 {"orderItem.action": {$equal: "delete", "orderItem.product": {$eitherOf: ["id", "href"]}}},672 {$: {$present: ["relatedParty", "orderItem"]}}673 ],674 "PATCH": [675 {$: {$noneOf: ["id", "href", "externalId", "orderDate", "completionDate", "expectedCompletionDate", "state"]}},676 {"orderItem": {$present: ["id", "action", "billingAccount", "product"]}},677 {"billingAccount": {$eitherOf: ["id", "href"]}},678 {"payment": {$eitherOf: ["id", "href"]}},679 {"note": {$present: ["text"]}},680 {"relatedParty": {$present: ["name"]}},681 {"relatedParty": {$eitherOf: ["id", "href"]}},682 {"relatedParty": {$present: ["role"]}},683 {"orderItem.qualification": {$eitherOf: ["id", "href"]}},684 {"orderItem.payment": {$eitherOf: ["id", "href"]}},685 {"orderItem.appointment": {$eitherOf: ["id", "href"]}},686 {"orderItem.product.place": {$present: ["role"]}},687 {"orderItem.productOffering": {$eitherOf: ["id", "href"]}},688 {"orderItem.itemTerm": {$present: ["name", "duration"]}},689 {"orderItem.orderItemRelationship": {$present: ["type", "id"]}},690 {"orderItem.action": {$equal: "modify", "orderItem.product": {$eitherOf: ["id", "href"]}}},691 {"orderItem.action": {$equal: "delete", "orderItem.product": {$eitherOf: ["id", "href"]}}}692 ],693 },694 "ResourceOrder": {695 "operations": ["GET", "PATCH", "POST", "DELETE"],696 "POST": [697 {"note": {$present: ["text"]}},698 {"appointment": {$eitherOf: ["id", "href"]}},699 {"orderItem": {$present: ["id", "action", "resource"]}},700 {"relatedParty": {$present: ["name"]}},701 {"relatedParty": {$eitherOf: ["id", "href"]}},702 {"orderItem.resource.place": {$present: ["role"]}},703 {"orderItem.resourceCandidate": {$eitherOf: ["id", "href"]}},704 {"orderItem.action": {$equal: "add", $present: ["characteristic"]}},705 {"orderItem.action": {$equal: "modify", "orderItem.resource": {$eitherOf: ["id", "href"]}}},706 {"orderItem.action": {$equal: "delete", "orderItem.resource": {$eitherOf: ["id", "href"]}}},707 {$: {$present: ["orderItem"]}}708 ],709 "PATCH": [710 {$: {$noneOf: ["id", "href", "corelationId", "orderDate", "completionDate", "orderItem.id", "orderItem.action"]}},711 {"note": {$present: ["text"]}},712 {"appointment": {$eitherOf: ["id", "href"]}},713 {"orderItem": {$present: ["id", "action", "resource"]}},714 {"relatedParty": {$present: ["name"]}},715 {"relatedParty": {$eitherOf: ["id", "href"]}},716 {"orderItem.resource.place": {$present: ["role"]}},717 {"orderItem.resourceCandidate": {$eitherOf: ["id", "href"]}},718 {"orderItem.action": {$equal: "add", $present: ["characteristic"]}},719 {"orderItem.action": {$equal: "modify", "orderItem.resource": {$eitherOf: ["id", "href"]}}},720 {"orderItem.action": {$equal: "delete", "orderItem.resource": {$eitherOf: ["id", "href"]}}}721 ],722 },723 "Usage": {724 "operations": ["GET", "PATCH", "POST", "DELETE"],725 "POST": [726 {$: {$present: ["date", "type"]}}727 ],728 "PATCH": [729 {$: {$noneOf: ["id", "href"]}},730 731 ],732 },733 "PartnershipType": {734 "operations": ["GET", "POST", "PATCH", "DELETE"],735 "POST": [736 {"roleType": {$present: ["name"]}},737 {$: {$present: ["name"]}}738 ],739 "PATCH": [740 {"roleType": {$present: ["name"]}}741 ],742 },743 "ProductOfferingQualification": {744 "operations": ["GET", "PATCH", "POST", "DELETE"],745 "POST": [746 {"productOfferingQualificationItem": {$present: ["category", "productOffering", "product"]}},747 {"productOffering": {$eitherOf: ["id", "href"]}},748 {"category": {$eitherOf: ["id", "href"]}},749 {"relatedParty": {$present: ["productOffering"]}},750 {"relatedParty": {$present: ["role"]}},751 {"qualificationItemRelationship": {$present: ["type", "id"]}},752 {"productRelationship": {$present: ["type", "id"]}},753 {"productCharacteristic": {$present: ["name", "value"]}},754 {"productSpecification": {$eitherOf: ["id", "href"]}},755 {"channel": {$eitherOf: ["id", "href"]}},756 {$: {$present: ["productOfferingQualificationItem"]}}757 ],758 "PATCH": [759 {$: {$noneOf: ["id", "href", "productOfferingQualificationDateTime", "effectiveQualificationDate"]}},760 {"productOfferingQualificationItem": {$present: ["category", "productOffering", "product"]}},761 {"productOffering": {$eitherOf: ["id", "href"]}},762 {"category": {$eitherOf: ["id", "href"]}},763 {"relatedParty": {$present: ["productOffering"]}},764 {"relatedParty": {$present: ["role"]}},765 {"qualificationItemRelationship": {$present: ["type", "id"]}},766 {"productRelationship": {$present: ["type", "id"]}},767 {"productCharacteristic": {$present: ["name", "value"]}},768 {"productSpecification": {$eitherOf: ["id", "href"]}},769 {"channel": {$eitherOf: ["id", "href"]}}770 ],771 },772 "AppliedCustomerBillingRate": {773 "operations": ["GET"],774 },775 "Service": {776 "operations": ["GET", "PATCH", "POST", "DELETE"],777 "POST": [778 {"serviceOrder": {$eitherOf: ["id", "href"]}},779 {"serviceSpecification": {$eitherOf: ["id", "href"]}},780 {"relatedParty": {$present: ["role"]}},781 {"serviceRelationship": {$present: ["type"]}},782 {"serviceRelationship.serviceRef": {$eitherOf: ["id", "href"]}},783 {"supportingService": {$eitherOf: ["id", "href"]}},784 {"supportingResource": {$eitherOf: ["id", "href"]}},785 {"note": {$present: ["text"]}},786 {"place": {$present: ["role"]}},787 {$: {$present: ["name", "relatedParty"]}}788 ],789 "PATCH": [790 {$: {$noneOf: ["id", "href", "orderDate"]}},791 {"serviceOrder": {$eitherOf: ["id", "href"]}},792 {"serviceSpecification": {$eitherOf: ["id", "href"]}},793 {"relatedParty": {$present: ["role"]}},794 {"serviceRelationship": {$present: ["type"]}},795 {"serviceRelationship.serviceRef": {$eitherOf: ["id", "href"]}},796 {"supportingService": {$eitherOf: ["id", "href"]}},797 {"supportingResource": {$eitherOf: ["id", "href"]}},798 {"note": {$present: ["text"]}},799 {"place": {$present: ["role"]}}800 ],801 },802 "TroubleTicket": {803 "operations": ["GET", "PATCH", "POST", "DELETE"],804 "POST": [805 {$: {$present: ["description", "severity", "ticketType"]}}806 ],807 "PATCH": [808 {$: {$noneOf: ["id", "href", "creationDate", "lastUpdated", "statusChange", "@baseType", "@type", "@schemaLocation"]}},809 810 ],811 },812 "AvailabilityCheck": {813 "operations": ["POST"],814 "POST": [815 816 ],817 "PATCH": [818 819 ],820 },821 "ProductSpecification": {822 "operations": ["GET", "POST", "PATCH", "DELETE"],823 "POST": [824 {$: {$present: ["name"]}}825 ],826 "PATCH": [827 {$: {$noneOf: ["id", "href"]}},828 ],829 },830 "Quote": {831 "operations": ["GET", "PATCH", "POST", "DELETE"],832 "POST": [833 {"quoteItem": {$present: ["id"]}},834 {"quoteItem": {$present: ["action"]}},835 {"quoteItem.quoteItem": {$present: ["id", "action"]}},836 {"note": {$present: ["text"]}},837 {"agreement": {$eitherOf: ["id", "href"]}},838 {"billingAccount": {$eitherOf: ["id", "href"]}},839 {"relatedParty": {$present: ["name"]}},840 {"relatedParty": {$eitherOf: ["id", "href"]}},841 {"relatedParty": {$present: ["role"]}},842 {"quoteItem.productOffering": {$eitherOf: ["id", "href"]}},843 {"quoteItem.appointment": {$eitherOf: ["id", "href"]}},844 {"quoteItem.product": {$eitherOf: ["id", "href"]}},845 {$: {$present: ["quoteItem"]}}846 ],847 "PATCH": [848 {$: {$noneOf: ["id", "href", "externalId", "version", "quoteDate", "effectiveQuoteCompletionDate", "quoteTotalPrice"]}},849 {"quoteItem": {$present: ["id"]}},850 {"quoteItem": {$present: ["action"]}},851 {"quoteItem.quoteItem": {$present: ["id", "action"]}},852 {"note": {$present: ["text"]}},853 {"agreement": {$eitherOf: ["id", "href"]}},854 {"billingAccount": {$eitherOf: ["id", "href"]}},855 {"relatedParty": {$present: ["name"]}},856 {"relatedParty": {$eitherOf: ["id", "href"]}},857 {"relatedParty": {$present: ["role"]}},858 {"quoteItem.productOffering": {$eitherOf: ["id", "href"]}},859 {"quoteItem.appointment": {$eitherOf: ["id", "href"]}},860 {"quoteItem.product": {$eitherOf: ["id", "href"]}}861 ],862 },863 "Agreement": {864 "operations": ["GET", "POST", "PATCH", "DELETE"],865 "POST": [866 {"engagedPartyRole": {$present: ["id", "name"]}},867 {"associatedAgreement": {$eitherOf: ["id", "href"]}},868 {$: {$present: ["name", "type", "engagedPartyRole", "agreementItem"]}}869 ],870 "PATCH": [871 {$: {$noneOf: ["id", "href", "completionDate"]}},872 {"engagedPartyRole": {$present: ["id", "name"]}},873 {"associatedAgreement": {$eitherOf: ["id", "href"]}}874 ],875 },876 "EntitySpecification": {877 "operations": ["GET", "POST", "PATCH", "DELETE"],878 "POST": [879 {$: {$present: ["name"]}}880 ],881 "PATCH": [882 {$: {$noneOf: ["id", "href", "lastUpdate", "@type"]}},883 ],884 },885 "ShoppingCart": {886 "operations": ["GET", "PATCH", "POST", "DELETE"],887 "POST": [888 {"cartItem": {$present: ["id", "action"]}},889 {"cartItem.cartItem": {$present: ["id", "action"]}},890 {"cartItem.note": {$present: ["text"]}},891 {"relatedParty": {$present: ["name"]}},892 {"relatedParty": {$eitherOf: ["id", "href"]}},893 {"cartItem.product.place": {$present: ["role", "href"]}},894 {"cartItem.productOffering": {$eitherOf: ["id", "href"]}},895 {"cartItem.product": {$eitherOf: ["id", "href"]}},896 {$: {$present: ["cartItem"]}}897 ],898 "PATCH": [899 {$: {$noneOf: ["id", "href", "validFor", "cartTotalPrice"]}},900 {"cartItem": {$present: ["id", "action"]}},901 {"cartItem.cartItem": {$present: ["id", "action"]}},902 {"cartItem.note": {$present: ["text"]}},903 {"relatedParty": {$present: ["name"]}},904 {"relatedParty": {$eitherOf: ["id", "href"]}},905 {"cartItem.product.place": {$present: ["role"]}},906 {"cartItem.productOffering": {$eitherOf: ["id", "href"]}},907 {"cartItem.product": {$eitherOf: ["id", "href"]}}908 ],909 },910 "ServiceLevelObjective": {911 "operations": ["GET", "PATCH", "POST", "DELETE"],912 "POST": [913 {"specParameter": {$present: ["name", "relatedEntity"]}},914 {"specParameter.relatedEntity": {$eitherOf: ["id", "href"]}},915 {$: {$present: ["conformanceTarget"]}},916 {$: {$present: ["conformanceComparator"]}},917 {$: {$present: ["specParameter"]}}918 ],919 "PATCH": [920 {$: {$noneOf: ["id", "href", "validFor"]}},921 {"specParameter": {$present: ["name", "relatedEntity"]}},922 {"specParameter.relatedEntity": {$eitherOf: ["id", "href"]}}923 ],924 },925 "ProductOffering": {926 "operations": ["GET", "POST", "PATCH", "DELETE"],927 "POST": [928 {$: {$present: ["name"]}},929 {"isBundle": {$equal: "true", $present: "bundledProductOffering"}}930 ],931 "PATCH": [932 {$: {$noneOf: ["id", "href", "lastUpdate"]}},933 ],934 },935 "EntityCategory": {936 "operations": ["GET", "POST", "PATCH", "DELETE"],937 "POST": [938 {$: {$present: ["name"]}}939 ],940 "PATCH": [941 {$: {$noneOf: ["id", "href"]}},942 ],943 }944};...
index.js
Source:index.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.Either = exports.Right = exports.Left = void 0;4/**5 * Creates a Left Either instance using the provided argument as the6 * underlying value.7 *8 * @remarks Left is considered the failed track.9 */10var Left = function (value11// @ts-ignore12) { return new Either(value, 'left'); };13exports.Left = Left;14/**15 * Creates a Right Either instance using the provided argument as the16 * underlying value.17 *18 * @remarks Right is considered the success track.19 */20var Right = function (value21// @ts-ignore22) { return new Either(value, 'right'); };23exports.Right = Right;24/**25 * The Either class26 *27 * Construct instances of an Either through the provided `Left` and28 * `Right` functions or the class's static `of` method.29 */30var Either = /** @class */ (function () {31 /**32 * Construct an instance of an Either.33 */34 function Either(value, type) {35 this.value = value;36 this.type = type;37 }38 /**39 * Returns true if the instance is a Left. Returns false otherwise.40 */41 Either.prototype.isLeft = function () {42 return this.type === 'left';43 };44 /**45 * Returns true if the instance is a Right. Returns true otherwise.46 */47 Either.prototype.isRight = function () {48 return this.type === 'right';49 };50 /**51 * Returns false if the instance is a Left or if the instance is a52 * Right but fails the predicateFn.53 * Returns true if and only if the instance is a Right and passes54 * the predicateFn.55 */56 Either.prototype.exists = function (predicateFn) {57 return this.isLeft() || predicateFn(this.get());58 };59 /**60 * Returns the underlying value regardless of whether the instance61 * is a Left or a Right.62 */63 Either.prototype.get = function () {64 return this.value;65 };66 /**67 * Returns the underlying value if it's a Right. Returns the68 * provided argument otherwise.69 */70 Either.prototype.getOrElse = function (fallback) {71 return this.isLeft() ?72 fallback :73 this.get();74 };75 /**76 * Returns the current instance if it's a Right. Returns the77 * provided Either argument otherwise.78 *79 * @remarks Useful for chaining successive calls to return the first80 * Right in the chain of orElses.81 *82 * @example83 * ```84 * const firstRightSidedEither = fnReturnsEither85 * .orElse(fn2ReturnsEither())86 * .orElse(fn3ReturnsEither())87 * .orElse(fn4ReturnsEither())88 * ```89 */90 Either.prototype.orElse = function (otherEither) {91 return this.isLeft() ?92 otherEither :93 this;94 };95 /**96 * Transforms the underlying value if the instance is a Right by97 * applying the provided function to the underlying value, returning98 * the transformed value in a Right Either.99 * Returns the instance otherwise.100 *101 * @remarks Prefer this to `flatMap` when the provided function does102 * not return an Either.103 */104 Either.prototype.map = function (fn) {105 return this.isLeft() ?106 this :107 exports.Right(fn(this.get()));108 };109 /**110 * A static version of map. Useful for lifting functions of type111 * (val: A) => B to be a function of type112 * (val: Either<A>) => Either<B>.113 *114 * A curried version of map. First accepts the transformation115 * function, and returns a function that accepts the Either.116 *117 * @example118 * ```119 * const appendToString = (val: string) => val + "@gmail.com";120 *121 * // Eithers (possibly returned by other functions)122 * const either = Right("johnsmith");123 * const otherEither = Left("Error: name not entered");124 *125 * // Create a version of appendToString that works on values that126 * // are Eithers.127 * const appendToEitherString = Either.map(appendToString);128 *129 * const eitherEmailOrError = appendToEitherString(either);130 * // eitherEmailOrError => Right("johnsmith@gmail.com")131 *132 * const eitherEmailOrError2 = appendToEitherString(otherEither);133 * // eitherEmailOrError2 => Left("Error: name not entered");134 * ```135 */136 Either.map = function (fn) {137 return function (either) {138 return either.map(fn);139 };140 };141 /**142 * An alias for Option.map. Perhaps a more accurate or descriptive143 * name.144 *145 * Lifts a function of type (val: A) => B146 * to be a function of type (val: Either<A>) => Either<B>.147 *148 * @example149 * // Working with number150 * const addFive = (val: number) => val + 5;151 * const eight = addFive(3);152 *153 * // Working with Either<number>154 * const addFiveToEither = Either.lift(addFive);155 * const eightOrError = addFiveToEither(Right(3));156 */157 Either.lift = function (fn) {158 return function (either) {159 return either.map(fn);160 };161 };162 /**163 * Like Either.lift but for functions with an arbitrary number of164 * arguments instead of just one.165 *166 * Lifts a function, with an arbitrary number of arguments, where167 * each argument is not an Either, to be a function that works on168 * Either versions of those arguments.169 *170 * @remarks This function has very weak type support and strict171 * requirements to work correctly. Use with caution.172 * @remarks The provided function **must** be completely curried.173 * @remarks If any of the provided Either arguments are a Left, the174 * Left will be returned.175 * @remarks Each argument in the provided curried function must have176 * the same type as its corresponding Either type. See the 2nd177 * example below.178 * @remarks All of the Either arguments for the provided function179 * must be passed when liftN is invoked.180 *181 * @example182 * ```183 * Either.liftN<number>(184 * (a: number) => (b: number) => (c: number) => a + b + c,185 * Right(18),186 * Right(4),187 * Right(6)188 * ); // => Right(28)189 *190 * // Since the 2nd argument (b) is defined as an object with a191 * // property age whose type is a number, the 2nd Either must be192 * // an Either whose underlying value is an Object with a property193 * // called age whose value is a number. This required relationship194 * // is **not** enforced by the type system.195 * Either.liftN<number>(196 * (a: number) => (b: { age: number }) => a + b.age,197 * Right(78),198 * Right({ age: 22 })199 * ); // => Right(100)200 * ```201 */202 Either.liftN = function (203 // @ts-ignore204 fn) {205 var args = [];206 for (var _i = 1; _i < arguments.length; _i++) {207 args[_i - 1] = arguments[_i];208 }209 var recurse = function (either, shadowArgs) {210 if (shadowArgs.length === 0) {211 return either;212 }213 var updatedValue = either.ap(shadowArgs.at(0));214 return recurse(updatedValue, shadowArgs.slice(1));215 };216 var initialValue = args[0].map(function () { return fn; });217 return recurse(initialValue, args);218 };219 /**220 * Applies the function wrapped in the current instance (as a Right)221 * to the provided Either argument.222 *223 * If the instance is a Left, the instance is returned.224 *225 * If the instance is a Right, and the argument a Left, the argument226 * is returned.227 *228 * If the instance is a Right, and the argument is a Right, the229 * result of applying the function to the argument's underlying230 * value is returned (wrapped in an Either as a Right).231 *232 * @remarks An Either is always returned.233 * @remarks The Either's Right underlying value must be a function234 * of the type (val: A) => B.235 * @remarks Useful when the function to apply to another Either is236 * itself wrapped in an Either.237 *238 * @example239 * ```240 * const getFunctionOrError = () => {241 * return Math.random() > .5 ?242 * Right(val => val * 2) :243 * Left("bad luck today");244 * }245 * // These next two constants could be retrieved by calling246 * // getFunctionOrError. Imagine it's been called twice and247 * // returned the following two Eithers.248 * const myRightEither = Right(val => val * 2);249 * const myLeftEither = Left("bad luck today");250 *251 * // Everything works nicely if all the Eithers are Rights252 * const resOne = myRightEither.ap(Right(42)); // => Right(84)253 *254 * // If the Either (containing the function or error) is a Left,255 * // that instance (containing the error) is returned.256 * const resTwo = myLeftEither.ap(Right(42));257 * // => Left("bad luck today")258 *259 * // If the argument to ap is a Left, and the instance is a Right,260 * // the argument is returned with no modification.261 * const resThree = myRightEither.ap(Left(42)); // => Left(42)262 * ```263 */264 Either.prototype.ap = function (either) {265 if (this.isLeft()) {266 return this;267 }268 if (typeof this.get() !== 'function') {269 return this;270 }271 // The instance's generic, A, must be a function272 // whose type is B => C.273 var underlyingFunc = this.get();274 return either.map(underlyingFunc);275 };276 /**277 * Applies one of the provided functions to the instance's278 * underlying value, returning the result of applying the function.279 *280 * If the instance is a Left, fnA is applied.281 * If the instance is a Right, fnB is applied.282 *283 * @remarks Regardless of whether the instance is a Left or Right,284 * the result of applying the function to the underlying value is285 * returned.286 *287 * @example288 * const double = val => val * 2;289 * const triple = val => val * 3;290 *291 * ```292 * Left(7).fold(double, triple); // => 14293 * Right(7).fold(double, triple); // => 21294 * ```295 */296 Either.prototype.fold = function (fnA, fnB) {297 return this.isLeft() ?298 fnA(this.get()) :299 fnB(this.get());300 };301 /**302 * Transforms and returns the underlying value if the instance is a303 * Right by applying the provided function to the underlying value.304 * Returns a Left otherwise.305 *306 * @remarks Prefer this to `map` when the provided function returns307 * an Either.308 *309 * @remarks If unsure of which method to use between `map`,310 * `flatMap`, and `then`, `then` should always work.311 */312 Either.prototype.flatMap = function (fn) {313 return this.isLeft() ?314 this :315 fn(this.get());316 };317 /**318 * A static version of flatMap. Useful for lifting functions of type319 * (val: A) => Either<B> to be a function of type320 * (val: Either<A>) => Either<B>321 *322 * A curried version of flatMap. First accepts the transformation323 * function, then the Either.324 *325 * @example326 * ```327 * const appendIfValid = (val: string): Either<string> => {328 * if (val.length > 2) {329 * const newVal = val + "@gmail.com";330 * return Right(newVal);331 * } else {332 * return Left(333 * new Error("value is too short to be an email")334 * );335 * }336 * }337 *338 * // Eithers - possibly returned by other parts of your code base.339 * const either = Right("johnsmith");340 * const otherEither = Left(new Error("invalid username"));341 *342 * // Create a version of appendIfValid that works on343 * // Either<string>344 * const appendToEitherStrIfValid = Either.flatMap(appendIfValid);345 *346 * const emailAddressOrError = appendToEitherStrIfValid(opt);347 * // emailAddressOrError => Right("johnsmith@gmail.com")348 *349 * const emailAddressOrError2 = appendToEitherStrIfValid(otherOpt);350 * // emailAddressOrError2 => Left(new Error("invalid username"))351 *352 * // This next line is equivalent to the above and just avoids353 * // storing the intermeidate constants.354 * const emailAddressOrError3 = Either.flatMap(appendIfValid)(opt);355 * ```356 */357 Either.flatMap = function (fn) {358 return function (either) {359 return either.flatMap(fn);360 };361 };362 /**363 * Usable in place of both map and flatMap.364 * Accepts a function that returns either an Either or non Either365 * value.366 *367 * Always returns an Either.368 *369 * Makes the Either class into a thenable.370 *371 * If the instance is a Left, the Either is returned as is.372 * If the provided function returns an Either, the result of373 * applying the function to the underlying value is returned.374 * If the provided function returns a non Either, the result of375 * applying the function to the underlying value is lifted into an376 * Either and returned.377 *378 * @example379 * ```380 * const myEither = Right(10);381 *382 * const doubleOrError = (val: number): Either<number> => {383 * Math.random() > .5 ?384 * Right(val * 2) :385 * Left("Just not your day :(. Try again next time");386 * }387 *388 * const alwaysDouble = (val: number): number => val * 2;389 *390 * // function calls can be chained with .then regarless if the391 * // functions passed to then return an Either or non Either value.392 * const eitherErrorOrValue = myEither.then(doubleOrError)393 * .then(alwaysDouble);394 * ```395 */396 Either.prototype.then = function (fn) {397 if (this.isLeft()) {398 return this;399 }400 var result = fn(this.get());401 if (result instanceof Either) {402 return result;403 }404 return exports.Right(result);405 };406 /**407 * Flattens a wrapped Either.408 *409 * If the instance is a Left, the instance is returned.410 * If the instance is a Right and the underlying value is an Either,411 * the underlying value is returned.412 * If the instance is a Right but the undnerlying value is not an413 * Either, the instance is returned.414 *415 * @remarks In all cases, an Either is returned.416 */417 Either.prototype.flatten = function () {418 if (this.isLeft()) {419 return this;420 }421 // The instance must be a Right422 var underlyingValue = this.get();423 if (underlyingValue instanceof Either) {424 return underlyingValue;425 }426 return this;427 };428 /**429 * Returns the instance if the instance is a Left.430 * Returns the instance if the instance is a Right and passes the431 * provided filter function.432 * Returns the otherEither if the instance is a Right and fails the433 * provided filter function.434 *435 * @example436 * ```437 * Right(42).filterOrElse(438 * val => val > 20,439 * Left("not bigger than 20")440 * ); // => Right(42)441 *442 * Left("uh oh, something broke").filterOrElse(443 * val => val > 20,444 * Left("not bigger than 20")445 * ); // => Left("uh oh, something broke")446 *447 * Right(19).filterOrElse(448 * val => val > 20,449 * Left("not bigger than 20")450 * ); // => Left("not bigger than 20")451 * ```452 */453 Either.prototype.filterOrElse = function (filterFn, otherEither) {454 if (this.isLeft()) {455 return this;456 }457 if (filterFn(this.get())) {458 return this;459 }460 else {461 return otherEither;462 }463 };464 /**465 * Returns true if the instance's underlying value equals the466 * provided argument. Returns false otherwise.467 *468 * @remarks Accepts an optional equality function for comparing two469 * values for when the underlying value is not a primitive. By470 * default this equality function is JavaScript's ===.471 */472 Either.prototype.contains = function (value, equalityFn) {473 if (equalityFn === void 0) { equalityFn = function (valOne, valTwo) { return valOne === valTwo; }; }474 return equalityFn(this.get(), value);475 };476 /**477 * Swaps the type of the instance and returns the now478 * swapped instance.479 * If the instance is a Left, it becomes a Right.480 * If the instance is a Right, it becomes a Left.481 *482 * @remarks The underlying value is not modified.483 */484 Either.prototype.swap = function () {485 var newType = this.isLeft() ?486 'right' :487 'left';488 this.type = newType;489 return this;490 };491 /**492 * Returns an Array with the underlying value when the instance is a493 * Right. Returns an empty Array otherwise.494 */495 Either.prototype.toArray = function () {496 return this.isLeft() ?497 [] :498 [this.get()];499 };500 /**501 * Returns a Set containing the underlying value when the instance502 * is a Right. Returns an empty Set otherwise.503 */504 Either.prototype.toSet = function () {505 return this.isLeft() ?506 new Set() :507 new Set().add(this.get());508 };509 /*510 * Returns a string representation of the Either.511 * Useful for console logging an instance.512 *513 * @example514 * ```515 * console.log(Left(-1)); // => "Left(-1)"516 * console.log(Right(42)); // => "Right(42)"517 * ```518 */519 Either.prototype.toString = function () {520 return this.isLeft() ?521 "Left(" + this.get() + ")" :522 "Right(" + this.get() + ")";523 };524 /**525 * An alias for toString();526 */527 Either.prototype.toStr = function () {528 return this.toString();529 };530 /**531 * Logs the Either to the console invoking both console.log and532 * toString for you.533 *534 * Accepts an optional function (customToString) as an argument.535 * customToString is a function you implement that returns a string.536 * The string returned by customToString will be used in place of537 * the string returned by toString method.538 * customToString will have access to the Either instance as well539 * but should **not** mutate the instance in any way (by calling540 * map, flatMap, then, filter, etc).541 *542 * @example543 * ```544 * Right(3).log(); // => "Right(3)"545 * Left('uh oh').log(); // => "Left('Uh oh')"546 *547 * const customLogger = (either: Either<number>): string => {548 * return ~~~~~~~~~~~ " + either.toStr() + " ~~~~~~~~~~";549 * }550 *551 * Left(-1).log(customLogger) // => "~~~~~~~~~~ Left(-1) ~~~~~~~~~~"552 * // Or defined inline and not even using the instance553 * Right(3).log(() => "-- I AM HERE --"); // => "-- I AM HERE --"554 * ```555 */556 Either.prototype.log = function () {557 console.log(this.toStr());558 };559 /**560 * Returns the instance after logging it to the console.561 *562 * Convenient to see the value of the Either in a sequence of method563 * calls for debugging without having to split up the method calls.564 *565 * Accepts an optional function (customToString) as an argument.566 * customToString is a function you implement that returns a string.567 * The string returned by customToString will be used in place of568 * the string returned by toString method.569 * customToString will have access to the either instance as well570 * but should **not** mutate the instance in any way (by calling571 * map, flatMap, then, filter, etc).572 *573 * @example574 * const customLogger = <T>(either: Either<T>): string => {575 * return "!!!!!!! " + either.toStr() + " !!!!!!!";576 * }577 * Right(3)578 * .map(val => val + 5)579 * .logAndContinue() // => "Right(8)"580 * .map(val => val + 2)581 * .filter(val => val > 10)582 * .logAndContinue(customLogger) // => "!!!!!!! Left() !!!!!!!"583 * .getOrElse(-1);584 * ```585 */586 Either.prototype.logAndContinue = function () {587 console.log(this.toStr());588 return this;589 };590 /**591 * Returns an instance of an Either using the value passed to it.592 * When invoking this function, the caller must specify whether the593 * instance is a Left or Right using the 2nd argument.594 *595 * Equivalent to using the Left() or Right() functions.596 *597 * @example598 * ```599 * const myRightEither = Either.of(42, 'right');600 * // The above is equivalent to => Right(42)601 *602 * const myLeftEither = Either.of(42, 'left');603 * // The above is equivalent to => Left(42);604 * ```605 */606 Either.of = function (val, type) {607 if (type === 'left') {608 return new Either(val, type);609 }610 else {611 return new Either(val, type);612 }613 };614 return Either;615}());...
util_name_particles.js
Source:util_name_particles.js
1CSL.ParticleList = (function() {2 var always_dropping_1 = [[[0,1], null]];3 var always_dropping_3 = [[[0,3], null]];4 var always_non_dropping_1 = [[null, [0,1]]];5 var always_non_dropping_2 = [[null, [0,2]]];6 var always_non_dropping_3 = [[null, [0,3]]];7 var either_1 = [[null, [0,1]],[[0,1],null]];8 var either_2 = [[null, [0,2]],[[0,2],null]];9 var either_1_dropping_best = [[[0,1],null],[null, [0,1]]];10 var either_2_dropping_best = [[[0,2],null],[null, [0,2]]];11 var either_3_dropping_best = [[[0,3],null],[null, [0,3]]];12 var non_dropping_2_alt_dropping_1_non_dropping_1 = [[null, [0,2]], [[0,1], [1,2]]];13 var PARTICLES = [14 ["'s", always_non_dropping_1],15 ["'s-", always_non_dropping_1],16 ["'t", always_non_dropping_1],17 ["a", always_non_dropping_1],18 ["aan 't", always_non_dropping_2],19 ["aan de", always_non_dropping_2],20 ["aan den", always_non_dropping_2],21 ["aan der", always_non_dropping_2],22 ["aan het", always_non_dropping_2],23 ["aan t", always_non_dropping_2],24 ["aan", always_non_dropping_1],25 ["ad-", either_1],26 ["adh-", either_1],27 ["af", either_1],28 ["al", either_1],29 ["al-", either_1],30 ["am de", always_non_dropping_2],31 ["am", always_non_dropping_1],32 ["an-", either_1],33 ["ar-", either_1],34 ["as-", either_1],35 ["ash-", either_1],36 ["at-", either_1],37 ["ath-", either_1],38 ["auf dem", either_2_dropping_best],39 ["auf den", either_2_dropping_best],40 ["auf der", either_2_dropping_best],41 ["auf ter", always_non_dropping_2],42 ["auf", either_1_dropping_best],43 ["aus 'm", either_2_dropping_best],44 ["aus dem", either_2_dropping_best],45 ["aus den", either_2_dropping_best],46 ["aus der", either_2_dropping_best],47 ["aus m", either_2_dropping_best],48 ["aus", either_1_dropping_best],49 ["aus'm", either_2_dropping_best],50 ["az-", either_1],51 ["aÅ¡-", either_1],52 ["aá¸-", either_1],53 ["aá¸-", either_1],54 ["aá¹£-", either_1],55 ["aá¹-", either_1],56 ["aṯ-", either_1],57 ["aáº-", either_1],58 ["ben", always_non_dropping_1],59 ["bij 't", always_non_dropping_2],60 ["bij de", always_non_dropping_2],61 ["bij den", always_non_dropping_2],62 ["bij het", always_non_dropping_2],63 ["bij t", always_non_dropping_2],64 ["bij", always_non_dropping_1],65 ["bin", always_non_dropping_1],66 ["boven d", always_non_dropping_2],67 ["boven d'", always_non_dropping_2],68 ["d", always_non_dropping_1],69 ["d'", either_1],70 ["da", either_1],71 ["dal", always_non_dropping_1],72 ["dal'", always_non_dropping_1],73 ["dall'", always_non_dropping_1],74 ["dalla", always_non_dropping_1],75 ["das", either_1],76 ["de die le", always_non_dropping_3],77 ["de die", always_non_dropping_2],78 ["de l", always_non_dropping_2],79 ["de l'", always_non_dropping_2],80 ["de la", non_dropping_2_alt_dropping_1_non_dropping_1],81 ["de las", non_dropping_2_alt_dropping_1_non_dropping_1],82 ["de le", always_non_dropping_2],83 ["de li", either_2],84 ["de van der", always_non_dropping_3],85 ["de", either_1],86 ["de'", either_1],87 ["deca", always_non_dropping_1],88 ["degli", either_1],89 ["dei", either_1],90 ["del", either_1],91 ["dela", always_dropping_1],92 ["dell'", either_1],93 ["della", either_1],94 ["delle", either_1],95 ["dello", either_1],96 ["den", either_1],97 ["der", either_1],98 ["des", either_1],99 ["di", either_1],100 ["die le", always_non_dropping_2],101 ["do", always_non_dropping_1],102 ["don", always_non_dropping_1],103 ["dos", either_1],104 ["du", either_1],105 ["ed-", either_1],106 ["edh-", either_1],107 ["el", either_1],108 ["el-", either_1],109 ["en-", either_1],110 ["er-", either_1],111 ["es-", either_1],112 ["esh-", either_1],113 ["et-", either_1],114 ["eth-", either_1],115 ["ez-", either_1],116 ["eÅ¡-", either_1],117 ["eá¸-", either_1],118 ["eá¸-", either_1],119 ["eá¹£-", either_1],120 ["eá¹-", either_1],121 ["eṯ-", either_1],122 ["eáº-", either_1],123 ["het", always_non_dropping_1],124 ["i", always_non_dropping_1],125 ["il", always_dropping_1],126 ["im", always_non_dropping_1],127 ["in 't", always_non_dropping_2],128 ["in de", always_non_dropping_2],129 ["in den", always_non_dropping_2],130 ["in der", either_2],131 ["in het", always_non_dropping_2],132 ["in t", always_non_dropping_2],133 ["in", always_non_dropping_1],134 ["l", always_non_dropping_1],135 ["l'", always_non_dropping_1],136 ["la", always_non_dropping_1],137 ["las", always_non_dropping_1],138 ["le", always_non_dropping_1],139 ["les", either_1],140 ["lo", either_1],141 ["los", always_non_dropping_1],142 ["lou", always_non_dropping_1],143 ["of", always_non_dropping_1],144 ["onder 't", always_non_dropping_2],145 ["onder de", always_non_dropping_2],146 ["onder den", always_non_dropping_2],147 ["onder het", always_non_dropping_2],148 ["onder t", always_non_dropping_2],149 ["onder", always_non_dropping_1],150 ["op 't", always_non_dropping_2],151 ["op de", either_2],152 ["op den", always_non_dropping_2],153 ["op der", always_non_dropping_2],154 ["op gen", always_non_dropping_2],155 ["op het", always_non_dropping_2],156 ["op t", always_non_dropping_2],157 ["op ten", always_non_dropping_2],158 ["op", always_non_dropping_1],159 ["over 't", always_non_dropping_2],160 ["over de", always_non_dropping_2],161 ["over den", always_non_dropping_2],162 ["over het", always_non_dropping_2],163 ["over t", always_non_dropping_2],164 ["over", always_non_dropping_1],165 ["s", always_non_dropping_1],166 ["s'", always_non_dropping_1],167 ["sen", always_dropping_1],168 ["t", always_non_dropping_1],169 ["te", always_non_dropping_1],170 ["ten", always_non_dropping_1],171 ["ter", always_non_dropping_1],172 ["tho", always_non_dropping_1],173 ["thoe", always_non_dropping_1],174 ["thor", always_non_dropping_1],175 ["to", always_non_dropping_1],176 ["toe", always_non_dropping_1],177 ["tot", always_non_dropping_1],178 ["uijt 't", always_non_dropping_2],179 ["uijt de", always_non_dropping_2],180 ["uijt den", always_non_dropping_2],181 ["uijt te de", always_non_dropping_3],182 ["uijt ten", always_non_dropping_2],183 ["uijt", always_non_dropping_1],184 ["uit 't", always_non_dropping_2],185 ["uit de", always_non_dropping_2],186 ["uit den", always_non_dropping_2],187 ["uit het", always_non_dropping_2],188 ["uit t", always_non_dropping_2],189 ["uit te de", always_non_dropping_3],190 ["uit ten", always_non_dropping_2],191 ["uit", always_non_dropping_1],192 ["unter", always_non_dropping_1],193 ["v", always_non_dropping_1],194 ["v.", always_non_dropping_1],195 ["v.d.", always_non_dropping_1],196 ["van 't", always_non_dropping_2],197 ["van de l", always_non_dropping_3],198 ["van de l'", always_non_dropping_3],199 ["van de", always_non_dropping_2],200 ["van de", always_non_dropping_2],201 ["van den", always_non_dropping_2],202 ["van der", always_non_dropping_2],203 ["van gen", always_non_dropping_2],204 ["van het", always_non_dropping_2],205 ["van la", always_non_dropping_2],206 ["van t", always_non_dropping_2],207 ["van ter", always_non_dropping_2],208 ["van van de", always_non_dropping_3],209 ["van", either_1],210 ["vander", always_non_dropping_1],211 ["vd", always_non_dropping_1],212 ["ver", always_non_dropping_1],213 ["vom und zum", always_dropping_3],214 ["vom", either_1],215 ["von 't", always_non_dropping_2],216 ["von dem", either_2_dropping_best],217 ["von den", either_2_dropping_best],218 ["von der", either_2_dropping_best],219 ["von t", always_non_dropping_2],220 ["von und zu", either_3_dropping_best],221 ["von zu", either_2_dropping_best],222 ["von", either_1_dropping_best],223 ["voor 't", always_non_dropping_2],224 ["voor de", always_non_dropping_2],225 ["voor den", always_non_dropping_2],226 ["voor in 't", always_non_dropping_3],227 ["voor in t", always_non_dropping_3],228 ["voor", always_non_dropping_1],229 ["vor der", either_2_dropping_best],230 ["vor", either_1_dropping_best],231 ["z", always_dropping_1],232 ["ze", always_dropping_1],233 ["zu", either_1_dropping_best],234 ["zum", either_1],235 ["zur", either_1]236 ];237 return PARTICLES;238}());239CSL.parseParticles = (function(){240 function splitParticles(nameValue, firstNameFlag, caseOverride) {241 // Parse particles out from name fields.242 // * nameValue (string) is the field content to be parsed.243 // * firstNameFlag (boolean) parse trailing particles244 // (default is to parse leading particles)245 // * caseOverride (boolean) include all but one word in particle set246 // (default is to include only words with lowercase first char)247 // [caseOverride is not used in this application]248 // Returns an array with:249 // * (boolean) flag indicating whether a particle was found250 // * (string) the name after removal of particles251 // * (array) the list of particles found252 var origNameValue = nameValue;253 nameValue = caseOverride ? nameValue.toLowerCase() : nameValue;254 var particleList = [];255 var rex;256 var hasParticle;257 if (firstNameFlag) {258 nameValue = nameValue.split("").reverse().join("");259 rex = CSL.PARTICLE_GIVEN_REGEXP;260 } else {261 rex = CSL.PARTICLE_FAMILY_REGEXP;262 }263 var m = nameValue.match(rex);264 while (m) {265 var m1 = firstNameFlag ? m[1].split("").reverse().join("") : m[1];266 var firstChar = m ? m1 : false;267 var firstChar = firstChar ? m1.replace(/^[-\'\u02bb\u2019\s]*(.).*$/, "$1") : false;268 hasParticle = firstChar ? firstChar.toUpperCase() !== firstChar : false;269 if (!hasParticle) {270 break;271 }272 if (firstNameFlag) {273 particleList.push(origNameValue.slice(m1.length * -1));274 origNameValue = origNameValue.slice(0,m1.length * -1);275 } else {276 particleList.push(origNameValue.slice(0,m1.length));277 origNameValue = origNameValue.slice(m1.length);278 }279 //particleList.push(m1);280 nameValue = m[2];281 m = nameValue.match(rex);282 }283 if (firstNameFlag) {284 nameValue = nameValue.split("").reverse().join("");285 particleList.reverse();286 for (var i=1,ilen=particleList.length;i<ilen;i++) {287 if (particleList[i].slice(0, 1) == " ") {288 particleList[i-1] += " ";289 }290 }291 for (var i=0,ilen=particleList.length;i<ilen;i++) {292 if (particleList[i].slice(0, 1) == " ") {293 particleList[i] = particleList[i].slice(1);294 }295 }296 nameValue = origNameValue.slice(0, nameValue.length);297 } else {298 nameValue = origNameValue.slice(nameValue.length * -1);299 }300 return [hasParticle, nameValue, particleList];301 }302 function trimLast(str) {303 var lastChar = str.slice(-1);304 str = str.trim();305 if (lastChar === " " && ["\'", "\u2019"].indexOf(str.slice(-1)) > -1) {306 str += " ";307 }308 return str;309 }310 function parseSuffix(nameObj) {311 if (!nameObj.suffix && nameObj.given) {312 var m = nameObj.given.match(/(\s*,!*\s*)/);313 if (m) {314 var idx = nameObj.given.indexOf(m[1]);315 var possible_suffix = nameObj.given.slice(idx + m[1].length);316 var possible_comma = nameObj.given.slice(idx, idx + m[1].length).replace(/\s*/g, "");317 if (possible_suffix.replace(/\./g, "") === 'et al' && !nameObj["dropping-particle"]) {318 // This hack covers the case where "et al." is explicitly used in the319 // authorship information of the work.320 nameObj["dropping-particle"] = possible_suffix;321 nameObj["comma-dropping-particle"] = ",";322 } else {323 if (possible_comma.length === 2) {324 nameObj["comma-suffix"] = true;325 }326 nameObj.suffix = possible_suffix;327 }328 nameObj.given = nameObj.given.slice(0, idx);329 }330 }331 }332 return function(nameObj) {333 // Extract and set non-dropping particle(s) from family name field334 var res = splitParticles(nameObj.family);335 var lastNameValue = res[1];336 var lastParticleList = res[2];337 nameObj.family = lastNameValue;338 var nonDroppingParticle = trimLast(lastParticleList.join(""));339 if (nonDroppingParticle) {340 nameObj['non-dropping-particle'] = nonDroppingParticle;341 }342 // Split off suffix first of all343 parseSuffix(nameObj);344 // Extract and set dropping particle(s) from given name field345 var res = splitParticles(nameObj.given, true);346 var firstNameValue = res[1];347 var firstParticleList = res[2];348 nameObj.given = firstNameValue;349 var droppingParticle = firstParticleList.join("").trim();350 if (droppingParticle) {351 nameObj['dropping-particle'] = droppingParticle;352 }353 };...
avaran.js
Source:avaran.js
1// Add Fantasy Land and Static Land support.2const { sum, tagged } = require("styp");3// Identity4const Identity = tagged("Identity",["val"]);5Identity.prototype.map = function(transformer) {6 return Identity(transformer(this.val));7}8Identity.prototype.flatMap = function(transformer) {9 if(Identity.is(this.val)) return this.val.flatMap(transformer);10 return Identity(transformer(this.val));11}12Identity.prototype.unbox = function() {13 return this.val;14}15// State Monad16const State = tagged("State", ["comp"]);17State.get = function(func) {18 return State(s => {19 const out = func(s);20 return [s,out];21 });22};23State.put = function(val) {24 return State(() => [val,val]);25};26State.prototype.map = function(transformer) {27};28State.prototype.flatMap = function(transformer) {29};30State.prototype.runWith = function(state) {31 return this.comp(state);32};33State.prototype.evalWith = function(state) {34 const pair = this.comp(state);35 return pair[1];36};37State.prototype.execWith = function(state) {38 const pair = this.comp(state);39 return pair[0];40};41// Free Monad42const Free = sum("Free", {43 Return:["v"],44 Suspend:["f"]45});46Free.lift = function(monad) {47 return Free.Suspend(monad)48};49Free.prototype.map = function(transformer) {50 this.cata({51 Return: ({ v }) => Free.Return(transformer(v)),52 Suspend: ({ f }) => Free.Suspend(f.map(fr => fr.map(transformer)))53 });54};55Free.prototype.flatMap = function(transformer) {56 this.cata({57 Return: ({ v }) => Free.Return(transformer(v)),58 Suspend: ({ f }) => Free.Suspend(f.map(fr => fr.flatMap(transformer)))59 });60};61Free.prototype.resume = function() {62 this.cata({63 Return: ({ v }) => v,64 Suspend: ({ f }) => f65 });66};67Free.prototype.go = function(extract) {68 this.cata({69 Return: ({ v }) => v,70 Suspend: ({ f }) => extract(f).go(extract)71 });72};73// Immutable Lists74const List = sum("List", {75 Nil:[],76 Cell:["car","cdr"]77});78List.prototype.map = function(transformer) {79 this.cata({80 });81};82List.prototype.flatMap = function(transformer) {83 this.cata({84 });85};86List.prototype.foldLeft = function(func) {87 this.cata({88 });89};90List.prototype.foldRight = function(func) {91 this.cata({92 });93};94// Either Monad95// Right biased96const Either = sum("Either", {97 Left:["v"],98 Right:["v"]99});100Either.prototype.map = function(transformer) {101 return this.cata({102 Right: ({ v }) => Either.Right(transformer(v)),103 Left: () => this104 });105};106Either.prototype.leftMap = function(transformer) {107 return this.cata({108 Right: () => this,109 Left: ({ v }) => Either.Left(transformer(v))110 });111};112Either.prototype.flatMap = function(transformer) {113 return this.cata({114 Right: ({ v }) => Either.is(v)?v.flatMap(transformer):Either.Right(transformer(v)),115 Left: () => this116 });117};118Either.prototype.catchMap = function(transformer) {119 return this.cata({120 Right: () => this,121 Left: ({ v }) => Either.is(v)?v.flatMap(transformer):Either.Left(transformer(v))122 });123};124Either.prototype.cataM = function(ifRight, ifLeft) {125 return this.cata({126 Right: ({ v }) => ifRight(v),127 Left: ({ v }) => ifLeft(v)128 });129};130Either.prototype.bimap = function(rTransformer,lTransformer) {131 return this.cata({132 Right: ({ v }) => Either.Right(rTransformer(v)),133 Left: ({ v }) => Either.Left(lTransformer(v))134 });135};136Either.prototype.swap = function() {137 return this.cata({138 Right: ({ v }) => Either.Left(v),139 Left: ({ v }) => Either.Right(v)140 });141};142Either.prototype.isRight = function() {143 return Either.Right.is(this);144};145Either.prototype.isLeft = function() {146 return Either.Left.is(this);147};148Either.prototype.foldLeft = function(inital,transformer) {149 return this.cata({150 Right: ({ v }) => transformer(inital,v),151 Left: () => inital152 });153};154Either.prototype.foldRight = function(inital,transformer) {155 return this.cata({156 Right: ({ v }) => transformer(v,inital),157 Left: () => inital158 });159};160Either.prototype.right = function() {161 return this.cata({162 Right: ({ v }) => v,163 Left: () => { throw new Error("Either.Right was expected") }164 });165};166Either.prototype.left = function() {167 return this.cata({168 Right: () => { throw new Error("Either.Left was expected") },169 Left: ({ v }) => v170 });171};172Either.prototype.contains = function(val) {173 return this.cata({174 Right: ({ v }) => v == val,175 Left: ({ v }) => v == val176 });177};178// Reader Monad179const Reader = tagged("Reader", ["action"]);180Reader.prototype.map = function(transformer) {181 return Reader((dep) => transformer(this.run(dep)));182};183Reader.prototype.flatMap = function(transformer) {184 return Reader((dep) => {185 const out = this.run(dep);186 if(Reader.is(out)) return out.flatMap(transformer);187 const tval = transformer(out);188 return Reader.is(tval)?transformer(out).run(dep):tval;189 });190};191Reader.prototype.run = function(dep) {192 return this.action(dep);193};194// IO Monad195const IO = tagged("IO", ["effect"]);196IO.prototype.map = function(transformer) {197 return IO(() => transformer(this.run()));198};199IO.prototype.flatMap = function(transformer) {200 return IO(() => {201 const out = this.run();202 if(IO.is(out)) return out.flatMap(transformer);203 const tval = transformer(out);204 return IO.is(tval)?transformer(out).run():tval;205 });206};207IO.prototype.run = function() {208 return this.effect();209};210// Maybe Monad211const Maybe = sum("Maybe", {212 Some:["v"],213 None:[]214});215Maybe.prototype.map = function(transformer) {216 return this.cata({217 Some: ({ v }) => Maybe.Some(transformer(v)),218 None: () => this219 });220};221Maybe.prototype.flatMap = function(transformer) {222 return this.cata({223 Some: ({ v }) => Maybe.is(v)?v.flatMap(transformer):Maybe.Some(transformer(v)),224 None: () => this225 });226};227Maybe.prototype.catchMap = function(other) {228 return this.cata({229 Some: () => this,230 None: () => other()231 });232};233Maybe.prototype.fold = function(def, transformer) {234 return this.cata({235 Some: ({ v }) => transformer(v),236 None: () => def237 });238};239Maybe.prototype.foldLeft = function(def, transformer) {240 return this.cata({241 Some: ({ v }) => transformer(def,v),242 None: () => def243 });244};245Maybe.prototype.isSome = function() {246 return Maybe.Some.is(this);247};248Maybe.prototype.isNone = function() {249 return Maybe.None.is(this);250};251Maybe.prototype.some = function() {252 return this.cata({253 Some: ({ v }) => v,254 None: () => { throw new Error("Maybe.some: No value present"); }255 });256};257Maybe.prototype.orSome = function(def) {258 return this.cata({259 Some: ({ v }) => v,260 None: () => def261 });262};263Maybe.prototype.orLazy = function(def) {264 return this.cata({265 Some: ({ v }) => v,266 None: () => def()267 });268};269Maybe.prototype.orNull = function() {270 return this.cata({271 Some: ({ v }) => v,272 None: () => null273 });274};275Maybe.prototype.orUndefined = function() {276 return this.cata({277 Some: ({ v }) => v,278 None: () => undefined279 });280};281Maybe.prototype.orElse = function(other) {282 return this.cata({283 Some: () => this,284 None: () => other285 });286};287Maybe.prototype.orNoneif = function(bool) {288 return bool? Maybe.None: this;289};290Maybe.prototype.do = function(fn) {291 this.cata({292 Some: ({ v }) => fn(v),293 None: () => {}294 });295};296Maybe.prototype.orElseRun = function(fn) {297 this.cata({298 Some: () => {},299 None: () => fn()300 });301};302Maybe.prototype.filter = function(cond) {303 return this.cata({304 Some: ({ v }) => cond(v)? this: Maybe.None,305 None: () => this306 });307};308Maybe.prototype.toArray = function() {309 return this.cata({310 Some: ({ v }) => [v],311 None: () => []312 });313};314Maybe.prototype.toBool = function() {315 return this.cata({316 Some: () => true,317 None: () => false318 });319};320Maybe.prototype.cataM = function(ifSome, ifNone) {321 return this.cata({322 Some: ({ v }) => ifSome(v),323 None: ifNone324 });325};326const avaran = Object.freeze({327 Maybe: Maybe,328 Either: Either,329 IO:IO,330 Reader:Reader,331 Free:Free332});...
coinmarketcap.js
Source:coinmarketcap.js
1let request = require('request-promise-native');2const handle = async (data) => {3 let url = "https://pro-api.coinmarketcap.com/v1/";4 url = url + data.endpoint;5 if (data.resource != "") {6 url = url + "/" + data.resource;7 }8 url = url + "/" + data.path;9 let idOrSymbol = ["id", "symbol"];10 let idOrSlug = ["id", "slug"];11 let endpoints = {12 "cryptocurrency": {13 "info": {14 eitherOr: [idOrSymbol],15 resources: {}16 },17 "map": {18 optional: ["listing_status", "start", "limit", "symbol"],19 resources: {}20 },21 "latest": {22 resources: {23 "listings": {24 optional: ["start", "limit", "convert", "sort", "sort_dir", "cryptocurrency_type"],25 },26 "market-pairs": {27 optional: ["start", "limit", "convert"],28 eitherOr: [idOrSymbol]29 },30 "quotes": {31 optional: ["convert"],32 eitherOr: [idOrSymbol]33 }34 }35 },36 "historical": {37 optional: ["time_end", "count", "interval", "convert"],38 resources: {39 "ohlcv": {40 required: ["time_start"],41 optional: ["time_period"],42 eitherOr: [idOrSymbol]43 },44 "quotes": {45 optional: ["time_start"],46 eitherOr: [idOrSymbol]47 }48 }49 }50 },51 "exchange": {52 "info": {53 eitherOr: [idOrSlug],54 resources: {}55 },56 "map": {57 optional: ["listing_status", "slug", "start", "limit"],58 resources: {}59 },60 "latest": {61 optional: ["convert"],62 resources: {63 "listings": {64 required: ["sort_dir"],65 optional: ["start", "limit", "sort", "market_type"],66 },67 "market-pairs": {68 optional: ["start", "limit"],69 eitherOr: [idOrSlug]70 },71 "quotes": {72 eitherOr: [idOrSlug]73 }74 }75 },76 "historical": {77 resources: {78 "quotes": {79 optional: ["time_start", "time_end", "count", "interval", "convert"],80 eitherOr: [idOrSlug]81 }82 }83 }84 },85 "global-metrics": {86 "latest": {87 resources: {88 "quotes": {89 optional: ["convert"],90 }91 }92 },93 "historical": {94 resources: {95 "quotes": {96 optional: ["time_start", "time_end", "count", "interval", "convert"],97 }98 }99 }100 },101 "tools": {102 "price-conversion": {103 required: ["amount"],104 optional: ["time", "convert"],105 eitherOr: [idOrSymbol]106 }107 }108 };109 if (!endpoints.hasOwnProperty(data.endpoint)) {110 return {111 statusCode: 400, 112 body: {113 jobRunID: data.jobId,114 status: "errored",115 error: "Not a valid endpoint"116 }117 };118 }119 if (!endpoints[data.endpoint].hasOwnProperty(data.path)) {120 return {121 statusCode: 400, 122 body: {123 jobRunID: data.jobId,124 status: "errored",125 error: "Path is not valid for this endpoint"126 }127 };128 }129 if (data.resource != "" && !endpoints[data.endpoint][data.path].resources.hasOwnProperty(data.resource)) {130 return {131 statusCode: 400, 132 body: {133 jobRunID: data.jobId,134 status: "errored",135 error: "Resource is not valid for this endpoint/path"136 }137 };138 }139 let required = endpoints[data.endpoint][data.path].required || [];140 let optional = endpoints[data.endpoint][data.path].optional || [];141 let eitherOr = endpoints[data.endpoint][data.path].eitherOr || [];142 if (data.resource != "") {143 required = required.concat(endpoints[data.endpoint][data.path].resources[data.resource].required || []);144 optional = optional.concat(endpoints[data.endpoint][data.path].resources[data.resource].optional || []);145 eitherOr = eitherOr.concat(endpoints[data.endpoint][data.path].resources[data.resource].eitherOr || []);146 }147 var requestObj = {};148 for (var i = 0; i < required.length; i++) {149 if (data[required[i]] == "") {150 return {151 statusCode: 400, 152 body: {153 jobRunID: data.jobId,154 status: "errored",155 error: "Missing required parameter"156 }157 };158 }159 requestObj[required[i]] = data[required[i]];160 }161 for (var i = 0; i < optional.length; i++) {162 if (data[optional[i]] != "") {163 requestObj[optional[i]] = data[optional[i]];164 }165 }166 for (var i = 0; i < eitherOr.length; i++) {167 let options = eitherOr[i];168 let selected = false;169 for (var j = 0; j < options.length; j++) {170 if (data[options[j]] != "") {171 requestObj[options[j]] = data[options[j]];172 selected = true;173 break;174 }175 }176 if (!selected) {177 return {178 statusCode: 400, 179 body: {180 jobRunID: data.jobId,181 status: "errored",182 error: "Missing required either-or parameter"183 }184 };185 }186 }187 let options = {188 method: 'GET',189 uri: url,190 qs: requestObj,191 headers: {192 'X-CMC_PRO_API_KEY': data.apiKey193 },194 json: true195 };196 let response = await request(options);197 if (data.endpoint === "cryptocurrency" && data.resource === "quotes" && data.path === "latest")198 response.result = response.data[data.symbol].quote[data.convert].price;199 return { 200 statusCode: 200, 201 body: {202 jobRunID: data.jobId,203 data: response204 }205 }206};207module.exports.default = async (event) => {208 let data = {209 jobId: event.id,210 apiKey: process.env.CMC_API_KEY || "",211 endpoint: event.data.endpoint || "cryptocurrency",212 resource: event.data.resource || "quotes",213 path: event.data.path || "latest",214 id: event.data.id || "",215 symbol: event.data.coin || event.data.symbol || "",216 listing_status: event.data.listing_status || "",217 start: event.data.start || "",218 limit: event.data.limit || "",219 convert: event.data.market || event.data.convert || "",220 sort: event.data.sort || "",221 sort_dir: event.data.sort_dir || "",222 cryptocurrency_type: event.data.cryptocurrency_type || "",223 time_start: event.data.time_start || "",224 time_end: event.data.time_end || "",225 time_period: event.data.time_period || "",226 count: event.data.count || "",227 interval: event.data.interval || "",228 slug: event.data.slug || "",229 market_type: event.data.market_type || "",230 amount: event.data.amount || "",231 };232 return await handle(data);...
verificationEitherWithMonadLaws.js
Source:verificationEitherWithMonadLaws.js
1import Either from './Either';2const log = console.log;3/* Verification monad Either by using Monad Laws, according to mathematical Theory of Category. */4/*5 ASSOCIATIVE LAW6Monad are monoids, therefore it doesn't matter in what order the actions performed or7they are composed, because always give the same result.8*/9log( (Either(() => 2) + Either(() => 3)) + 1 === 1 + Either(() => 5) ); // true10log( Either(() => 2) + (Either(() => 3) + 1) === 1 + Either(() => 5) ); // true11log( (Either(() => 2) + Either(() => 3)) + 1 ); // 612log( (Either(() => 2) + 1) + Either(() => 3) ); // 6 13const add2 = (n) => Either(() => n + 2);14const multiply2 = (n) => Either(() => n * 2);15log( Either(() => 10).chain(add2).chain(multiply2).valueOf() ); // 2416log( Either(() => 10).chain(x => add2(x).chain(multiply2)).valueOf() ); // 2417/*18 THE IDENTITY LAW19For every type (i.e. string, boolean, number) exist a function that maps this type to20itself (in the same category).21*/22/*23Left identity24Monad with a value that chain function, return the same result as this function that 25takes the same type of value and returns the same type of monad.26*/27log(Either(() => 100).chain(multiply2).valueOf() === multiply2(100).valueOf()); // true28/*29 Right identity30If monad with value chain with the same type of monad, that after flatten this value31will be unchanged.32*/...
Either.js
Source:Either.js
...4Either.return = Either.right;5Either.fail = Either.left;6Either.prototype.map = function (f)7{8 return this.either(9 e => Either.left(e), // this10 x => Either.right(f(x))11 );12};13Either.fromObsolete = obsoleteEitherAB => either(Either.left, Either.right, obsoleteEitherAB);14/** Left: */15function Left(a)16{17 Either.call(this); // here only for selfdoc of typing18 this.a = a;19}20Left.prototype = Object.create(Either.prototype);21Left.prototype.constructor = Left;22Left.prototype.either = function (left, right) {return left(this.a);};23/** Right: */24function Right(b)25{26 Either.call(this); // here only for selfdoc of typing27 this.b = b;...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright['chromium'].launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();
Using AI Code Generation
1const { chromium } = require('playwright-internal');2const browser = await chromium.launch({ headless: false });3const context = await browser.newContext();4const page = await context.newPage();5const { chromium } = require('playwright');6const browser = await chromium.launch({ headless: false });7const context = await browser.newContext();8const page = await context.newPage();9const { chromium } = require('playwright-internal');10const browser = await chromium.launch({ headless: false });11const context = await browser.newContext();12const page = await context.newPage();13const { chromium } = require('playwright');14const browser = await chromium.launch({ headless: false });15const context = await browser.newContext();16const page = await context.newPage();
Using AI Code Generation
1const playwright = require('playwright');2const { chromium } = playwright;3const browser = await chromium.launch({ headless: false });4const context = await browser.newContext();5const page = await context.newPage();6await page.screenshot({ path: `example.png` });7const playwright = require('playwright');8(async () => {9const browser = await playwright.chromium.launch({ headless: false });10const context = await browser.newContext();11const page = await context.newPage();12await page.screenshot({ path: `example.png` });13await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17const browser = await chromium.launch({ headless: false });18const context = await browser.newContext();19const page = await context.newPage();20await page.screenshot({ path: `example.png` });21await browser.close();22})();23const playwright = require('playwright');24const { chromium, webkit, firefox } = playwright;25(async () => {26const browser = await chromium.launch({ headless: false });27const context = await browser.newContext();28const page = await context.newPage();29await page.screenshot({ path: `example.png` });30await browser.close();31})();32const playwright = require('playwright');33(async () => {34const browser = await playwright.launch({ headless: false });35const context = await browser.newContext();36const page = await context.newPage();37await page.screenshot({ path: `example.png` });38await browser.close();39})();40const playwright = require('playwright');41(async () => {42const browser = await playwright.launch({ headless: false });43const context = await browser.newContext();44const page = await context.newPage();45await page.screenshot({ path: `example.png` });46await browser.close();47})();
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('should open Google', async ({ page }) => {3 await page.screenshot({ path: `example.png` });4 const title = page.locator('text=Playwright');5 await expect(title).toBeVisible();6});7test('should open Google', async ({ page }) => {8 await page.screenshot({ path: `example.png` });9 const title = page.locator('text=Playwright');10 await expect(title).toBeVisible();11});12module.exports = {13 use: {14 },15};16const { test } = require('@playwright/test');17test('should open Google', async ({ page }) => {18 await page.screenshot({ path: `example.png` });19 const title = page.locator('text=Playwright');20 await expect(title).toBeVisible();21});22const { test } = require('@playwright/test');23test('should open Google', async ({ page }) => {24 await page.screenshot({ path: `example.png` });25 const title = page.locator('text=Playwright');26 await expect(title).toBeVisible();27});28const { test, expect } = require('@playwright/test');29test('should open Google', async ({ page }) => {
Using AI Code Generation
1const playwright = require('playwright');2const assert = require('assert');3const path = require('path');4const fs = require('fs');5const {chromium, firefox, webkit} = require('playwright');6(async () => {7 for (const browserType of [chromium, firefox, webkit]) {8 const browser = await browserType.launch();9 const context = await browser.newContext();10 const page = await context.newPage();11 await page.screenshot({ path: `example-${browserType.name()}.png` });12 await browser.close();13 }14})();
Using AI Code Generation
1const { test } = require('@playwright/test');2const { startServer } = require('playwright-test-server');3const { expect } = require('@playwright/test');4test.describe('Test Suite', () => {5 let server;6 test.beforeAll(async () => {7 server = await startServer({ command: 'node server.js', port: 3000 });8 });9 test.afterAll(async () => {10 await server.kill();11 });12 test('Test', async ({ page }) => {13 await page.goto(server.PREFIX);14 expect(await page.textContent('body')).toBe('Hello world!');15 });16});17const http = require('http');18const port = 3000;19const requestHandler = (request, response) => {20 response.end('Hello world!');21};22const server = http.createServer(requestHandler);23server.listen(port, (err) => {24 if (err) {25 return console.log('Something bad happened', err);26 }27 console.log(`server is listening on ${port}`);28});29`startServer(options)`30`startWebSocketServer(options)`
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!