Skip to content

Commit

Permalink
Preview/immutability (#149)
Browse files Browse the repository at this point in the history
* upodate typescript to ^4.1.3

* make array, nonempty, interface, partial, both readonly

* update changelog

* Publish

 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
 - @morphic-ts/[email protected]
  • Loading branch information
sledorze authored Dec 17, 2020
1 parent 0b6564c commit cfcf2f6
Show file tree
Hide file tree
Showing 39 changed files with 326 additions and 189 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
> - [Experimental]
> - [Deprecation]
## 3.0.0-RC0

- **New Feature**
- add `mutable`
- **Breaking Change**
- make `array`, `nonempty`, `interface`, `partial`, `both` readonly

## 2.0.0

Promotion from 2.0.0-alpha.19
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ts-node": "^8.6.2",
"tslint": "6.1.2",
"tslint-config-standard": "^9.0.0",
"typescript": "4.0.1-rc",
"typescript": "^4.1.3",
"yarn-deduplicate": "2.0.0"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion packages/morphic-adt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/adt",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic ADT provides Algebraic Data Type manipulation in Typescript",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand Down
3 changes: 2 additions & 1 deletion packages/morphic-adt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as M from './monocle'
import * as Ma from './matcher'
import * as PU from './predicates'
import * as CU from './ctors'
import { intersection, difference, reduceRight, array } from 'fp-ts/Array'
import { intersection, difference, reduceRight } from 'fp-ts/ReadonlyArray'
import { array } from 'fp-ts/Array'
import { eqString } from 'fp-ts/Eq'
import { fromFoldable } from 'fp-ts/Record'
import { tuple, identity } from 'fp-ts/function'
Expand Down
4 changes: 2 additions & 2 deletions packages/morphic-algebras/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/algebras",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic core Algebra package",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand All @@ -21,7 +21,7 @@
"es6"
],
"dependencies": {
"@morphic-ts/common": "^2.0.0"
"@morphic-ts/common": "^3.0.0-alpha.0"
},
"scripts": {
"lint": "tslint -p tsconfig.tslint.json src/**/*.ts test/**/*.ts",
Expand Down
8 changes: 4 additions & 4 deletions packages/morphic-batteries/dtslint/ts3.8/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ summon(F => {
return res
})

// $ExpectType M<{ FastCheckURI: FastCheck; }, string[], string[]>
// $ExpectType M<{ FastCheckURI: FastCheck; }, Array<string>, Array<string>>
summon(F =>
F.array(
F.string({
Expand Down Expand Up @@ -91,7 +91,7 @@ const model = defineFor(ProgramUnionURI)<{ FastCheckURI: FastCheck }>()(F => F.s
// $ExpectError
defineFor(ProgramUnionURI)<{}>()(F => F.interface({ a: model(F), b: F.number() }, 'A'))

// $ExpectType P<{ FastCheckURI: FastCheck; }, { a: string; b: number; }, { a: string; b: number; }>
// $ExpectType P<{ FastCheckURI: FastCheck; }, Readonly<{ a: string; b: number; }>, Readonly<{ a: string; b: number; }>>
defineFor(ProgramUnionURI)<{ FastCheckURI: FastCheck }>()(F => F.interface({ a: model(F), b: F.number() }, 'A'))

defineFor(ProgramUnionURI)()(F =>
Expand All @@ -114,7 +114,7 @@ defineFor(ProgramUnionURI)<{}>()(F =>
F.interface({ b: F.number({ FastCheckURI: (_, env: FastCheck2) => _ }) }, 'A')
)

// $ExpectType P<{ FastCheckURI: FastCheck & FastCheck2; }, { a: string; b: number; }, { a: string; b: number; }>
// $ExpectType P<{ FastCheckURI: FastCheck & FastCheck2; }, Readonly<{ a: string; b: number; }>, Readonly<{ a: string; b: number; }>>
const prg = defineFor(ProgramUnionURI)<{ FastCheckURI: FastCheck & FastCheck2 }>()(F =>
F.interface({ a: model(F), b: F.number({ FastCheckURI: (_, env: FastCheck2) => _ }) }, 'A')
)
Expand All @@ -124,5 +124,5 @@ summon(prg)

const { summon: summonAppEnv } = summonFor<AppEnv>({ FastCheckURI: { fc: 'a', fc2: 'a' } })

// $ExpectType M<AppEnv, { a: string; b: number; }, { a: string; b: number; }>
// $ExpectType M<AppEnv, Readonly<{ a: string; b: number; }>, Readonly<{ a: string; b: number; }>>
summonAppEnv(prg)
9 changes: 8 additions & 1 deletion packages/morphic-batteries/dtslint/ts3.8/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { array } from 'fast-check'
import { summonFor } from '../../src/summoner-BASTJ'
import type { EOfMorphADT, IfStringLiteral, AOfMorphADT } from '@morphic-ts/summoners/lib/tagged-union'
import { modelFastCheckInterpreter } from '@morphic-ts/fastcheck-interpreters/lib/interpreters'
Expand Down Expand Up @@ -104,5 +105,11 @@ type EM = EOfMorphADT<typeof ABC>
// $ExpectType (env: {}) => FastCheckType<A | B | C>
interpretable(ABC)(modelFastCheckInterpreter())

// $ExpectType M<{}, { a: string; b: string; }, { a: string; b: string; }>
// $ExpectType M<{}, Readonly<{ a: string; b: string; }>, Readonly<{ a: string; b: string; }>>
summon(F => F.interface({ a: F.string(), b: F.string() }, 'A'))

// $ExpectType M<{}, Mutable<Readonly<{ a: string; b: string; }>>, Mutable<Readonly<{ a: string; b: string; }>>>
summon(F => F.mutable(F.interface({ a: F.string(), b: F.string() }, 'A')))

// $ExpectType M<{}, string[], string[]>
summon(F => F.mutable(F.array(F.string())))
24 changes: 12 additions & 12 deletions packages/morphic-batteries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/batteries",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic batteries package to bootstrap projects",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand Down Expand Up @@ -37,17 +37,17 @@
"newtype-ts": "^0.3.3"
},
"dependencies": {
"@morphic-ts/adt": "^2.0.0",
"@morphic-ts/algebras": "^2.0.0",
"@morphic-ts/common": "^2.0.0",
"@morphic-ts/eq-interpreters": "^2.0.0",
"@morphic-ts/fastcheck-interpreters": "^2.0.0",
"@morphic-ts/io-ts-interpreters": "^2.0.0",
"@morphic-ts/json-schema-interpreters": "^2.0.0",
"@morphic-ts/model-algebras": "^2.0.0",
"@morphic-ts/ord-interpreters": "^2.0.0",
"@morphic-ts/show-interpreters": "^2.0.0",
"@morphic-ts/summoners": "^2.0.0"
"@morphic-ts/adt": "^3.0.0-alpha.0",
"@morphic-ts/algebras": "^3.0.0-alpha.0",
"@morphic-ts/common": "^3.0.0-alpha.0",
"@morphic-ts/eq-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/fastcheck-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/io-ts-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/json-schema-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/model-algebras": "^3.0.0-alpha.0",
"@morphic-ts/ord-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/show-interpreters": "^3.0.0-alpha.0",
"@morphic-ts/summoners": "^3.0.0-alpha.0"
},
"scripts": {
"lint": "tslint -p tsconfig.tslint.json src/**/*.ts test/**/*.ts",
Expand Down
11 changes: 9 additions & 2 deletions packages/morphic-common/dtslint/ts3.8/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface Foo<F extends URIS | URIS2, Env extends AnyEnv> {

// Program

const doIt = <Env extends AnyEnv = {}>() => <F extends URIS | URIS2>(f: (x: Foo<F, Env>) => void) => f
const doIt = <Env extends AnyEnv = {}>() => <F extends URIS | URIS2>(f: (x: Foo<F, Env>) => undefined) => f

doIt<{ Ord: { x: string } }>()(F => {
// $ExpectType HKT<"Eq" | "Ord" | "IOTs", { Ord: { x: string; }; }, string>
Expand All @@ -72,6 +72,7 @@ doIt<{ Ord: { x: string } }>()(F => {
// $ExpectType Ord<string>
x
})
return undefined
})

doIt<{ Ord: { b: number } }>()(F => {
Expand All @@ -83,6 +84,7 @@ doIt<{ Ord: { b: number } }>()(F => {
// $ExpectType Ord<string>
x
})
return undefined
})

doIt<{ Ord: { b: number } }>()(F => {
Expand All @@ -92,6 +94,7 @@ doIt<{ Ord: { b: number } }>()(F => {
// $ExpectType Ord<string>
x
})
return undefined
})

doIt<{ Eq: { a: string } } & { Ord: { b: number } }>()(F => {
Expand All @@ -116,6 +119,7 @@ doIt<{ Eq: { a: string } } & { Ord: { b: number } }>()(F => {
return x
}
})
return undefined
})

doIt<{ Eq: { a: string } }>()(F => {
Expand All @@ -132,6 +136,7 @@ doIt<{ Eq: { a: string } }>()(F => {
// $ExpectType Eq<string>
x
})
return undefined
})

doIt<{ IOTs: { c: string } } & { Eq: { a: string } } & { Ord: { b: number } }>()(F => {
Expand Down Expand Up @@ -165,17 +170,19 @@ doIt<{ IOTs: { c: string } } & { Eq: { a: string } } & { Ord: { b: number } }>()
return x
}
})
return undefined
})

interface Foo2<F extends URIS | URIS2, Env extends AnyEnv> {
myFunc: <R, A>(t: HKT<F, R, A>) => (a: ConfigsForType<Env, unknown, A>) => HKT<F, Env, A>
term: <R, A>() => HKT<F, R, A>
}

const doIt2 = <Env extends AnyEnv>() => <F extends URIS | URIS2>(f: (x: Foo2<F, Env>) => void) => f
const doIt2 = <Env extends AnyEnv>() => <F extends URIS | URIS2>(f: (x: Foo2<F, Env>) => undefined) => f

doIt2<{ Eq: { a: string } }>()(F => {
F.myFunc(F.term<{}, string>())({
Ord: (x, e) => x
})
return undefined
})
2 changes: 1 addition & 1 deletion packages/morphic-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/common",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic core common package",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand Down
10 changes: 5 additions & 5 deletions packages/morphic-eq-interpreters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/eq-interpreters",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic Eq (fp-ts) package for equality",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand All @@ -21,13 +21,13 @@
"es6"
],
"dependencies": {
"@morphic-ts/algebras": "^2.0.0",
"@morphic-ts/common": "^2.0.0",
"@morphic-ts/model-algebras": "^2.0.0",
"@morphic-ts/algebras": "^3.0.0-alpha.0",
"@morphic-ts/common": "^3.0.0-alpha.0",
"@morphic-ts/model-algebras": "^3.0.0-alpha.0",
"fast-equals": "^2.0.0"
},
"devDependencies": {
"@morphic-ts/summoners": "^2.0.0",
"@morphic-ts/summoners": "^3.0.0-alpha.0",
"fp-ts": "^2.5.3",
"io-ts": "^2.1.3",
"io-ts-types": "^0.5.6",
Expand Down
5 changes: 3 additions & 2 deletions packages/morphic-eq-interpreters/src/model/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getEq as OgetEq } from 'fp-ts/Option'
import { getEq as AgetEq } from 'fp-ts/Array'
import { getEq as NEAgetEq } from 'fp-ts/NonEmptyArray'
import { getEq as AgetEq } from 'fp-ts/ReadonlyArray'
import { getEq as NEAgetEq } from 'fp-ts/ReadonlyNonEmptyArray'
import { getEq as EgetEq } from 'fp-ts/Either'
import { eq, eqNumber, eqString, eqBoolean, eqStrict } from 'fp-ts/Eq'
import type { ModelAlgebraPrimitive1 } from '@morphic-ts/model-algebras/lib/primitives'
Expand Down Expand Up @@ -31,6 +31,7 @@ export const eqPrimitiveInterpreter = memo(
tag: (k, config) => env => new EqType<typeof k>(eqApplyConfig(config)(eqString, env)),
keysOf: (keys, config) => env => new EqType<keyof typeof keys>(eqApplyConfig(config)(eqStrict, env)),
nullable: (getType, config) => env => new EqType(eqApplyConfig(config)(OgetEq(getType(env).eq), env)),
mutable: (getType, config) => env => new EqType(eqApplyConfig(config)(getType(env).eq, env)),
array: (getType, config) => env => new EqType(eqApplyConfig(config)(AgetEq(getType(env).eq), env)),
nonEmptyArray: (getType, config) => env => new EqType(eqApplyConfig(config)(NEAgetEq(getType(env).eq), env)),
uuid: config => env => new EqType<UUID>(eqApplyConfig(config)(eqString, env)),
Expand Down
10 changes: 5 additions & 5 deletions packages/morphic-fastcheck-interpreters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/fastcheck-interpreters",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic fastcheck package for property based testing",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand All @@ -21,12 +21,12 @@
"es6"
],
"dependencies": {
"@morphic-ts/algebras": "^2.0.0",
"@morphic-ts/common": "^2.0.0",
"@morphic-ts/model-algebras": "^2.0.0"
"@morphic-ts/algebras": "^3.0.0-alpha.0",
"@morphic-ts/common": "^3.0.0-alpha.0",
"@morphic-ts/model-algebras": "^3.0.0-alpha.0"
},
"devDependencies": {
"@morphic-ts/summoners": "^2.0.0",
"@morphic-ts/summoners": "^3.0.0-alpha.0",
"fast-check": "^2.6.0",
"fp-ts": "^2.5.3",
"io-ts": "^2.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const fastCheckPrimitiveInterpreter = memo(
),
nullable: (T, config) => env =>
new FastCheckType(fastCheckApplyConfig(config)(option(T(env).arb).map(fromNullable), env)),
mutable: (T, config) => env => new FastCheckType(fastCheckApplyConfig(config)(T(env).arb, env)),
array: (T, config) => env => new FastCheckType(fastCheckApplyConfig(config)(array(T(env).arb), env)),
nonEmptyArray: (T, config) => env => {
const gen = T(env).arb
Expand Down
10 changes: 5 additions & 5 deletions packages/morphic-io-ts-interpreters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/io-ts-interpreters",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic io-ts package for encoding / decoding",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand All @@ -21,12 +21,12 @@
"es6"
],
"dependencies": {
"@morphic-ts/algebras": "^2.0.0",
"@morphic-ts/common": "^2.0.0",
"@morphic-ts/model-algebras": "^2.0.0"
"@morphic-ts/algebras": "^3.0.0-alpha.0",
"@morphic-ts/common": "^3.0.0-alpha.0",
"@morphic-ts/model-algebras": "^3.0.0-alpha.0"
},
"devDependencies": {
"@morphic-ts/summoners": "^2.0.0",
"@morphic-ts/summoners": "^3.0.0-alpha.0",
"fp-ts": "^2.5.3",
"io-ts": "^2.1.3",
"io-ts-types": "^0.5.6",
Expand Down
7 changes: 4 additions & 3 deletions packages/morphic-io-ts-interpreters/src/model/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { memo } from '@morphic-ts/common/lib/utils'
import { UUID } from 'io-ts-types/lib/UUID'
import { either as Teither } from 'io-ts-types/lib/either'
import { option as Toption } from 'io-ts-types/lib/option'
import { nonEmptyArray } from 'io-ts-types/lib/nonEmptyArray'
import { readonlyNonEmptyArray } from 'io-ts-types/lib/readonlyNonEmptyArray'

/**
* @since 0.0.1
Expand Down Expand Up @@ -62,8 +62,9 @@ export const ioTsPrimitiveInterpreter = memo(
keysOf: (k, config) => env =>
new IOTSType(iotsApplyConfig(config)(t.keyof(k) as t.Type<keyof typeof k, string, unknown>, env)),
nullable: (T, config) => env => new IOTSType(iotsApplyConfig(config)(optionFromNullable(T(env).type), env)),
array: (T, config) => env => new IOTSType(iotsApplyConfig(config)(t.array(T(env).type), env)),
nonEmptyArray: (T, config) => env => new IOTSType(iotsApplyConfig(config)(nonEmptyArray(T(env).type), env)),
mutable: (T, config) => env => new IOTSType(iotsApplyConfig(config)(T(env).type, env)),
array: (T, config) => env => new IOTSType(iotsApplyConfig(config)(t.readonlyArray(T(env).type), env)),
nonEmptyArray: (T, config) => env => new IOTSType(iotsApplyConfig(config)(readonlyNonEmptyArray(T(env).type), env)),
uuid: config => env => new IOTSType(iotsApplyConfig(config)(UUID, env)),
either: (e, a, config) => env => new IOTSType(iotsApplyConfig(config)(Teither(e(env).type, a(env).type), env)),
option: (a, config) => env => new IOTSType(iotsApplyConfig(config)(Toption(a(env).type), env))
Expand Down
10 changes: 5 additions & 5 deletions packages/morphic-json-schema-interpreters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@morphic-ts/json-schema-interpreters",
"version": "2.0.0",
"version": "3.0.0-alpha.0",
"description": "Morphic json schema-ish derivation",
"author": "Stéphane Le Dorze <[email protected]>",
"homepage": "",
Expand All @@ -21,12 +21,12 @@
"es6"
],
"dependencies": {
"@morphic-ts/algebras": "^2.0.0",
"@morphic-ts/common": "^2.0.0",
"@morphic-ts/model-algebras": "^2.0.0"
"@morphic-ts/algebras": "^3.0.0-alpha.0",
"@morphic-ts/common": "^3.0.0-alpha.0",
"@morphic-ts/model-algebras": "^3.0.0-alpha.0"
},
"devDependencies": {
"@morphic-ts/summoners": "^2.0.0",
"@morphic-ts/summoners": "^3.0.0-alpha.0",
"fp-ts": "^2.5.3",
"fp-ts-contrib": "^0.1.12",
"io-ts": "^2.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const jsonSchemaPrimitiveInterpreter = memo(
env
)
),
mutable: (getSchema, config) => env => new JsonSchema(jsonSchemaApplyConfig(config)(getSchema(env).schema, env)),
array: (getSchema, config) => env =>
new JsonSchema(
jsonSchemaApplyConfig(config)(
Expand Down
Loading

0 comments on commit cfcf2f6

Please sign in to comment.